/** * Erdbeben-Layer: Farbige Kreise auf der Erdoberfläche. */ const QuakesLayer = { _viewer: null, _dataSource: null, _interval: null, _count: 0, start(viewer) { if (this._dataSource) return; this._viewer = viewer; this._dataSource = new Cesium.CustomDataSource('quakes'); viewer.dataSources.add(this._dataSource); this._fetch(); var self = this; this._interval = setInterval(function() { self._fetch(); }, 300000); }, stop() { if (this._interval) { clearInterval(this._interval); this._interval = null; } if (this._dataSource && this._viewer) { this._viewer.dataSources.remove(this._dataSource); this._dataSource = null; } this._count = 0; }, _fetch() { var self = this; fetch('/api/quakes') .then(function(r) { return r.json(); }) .then(function(data) { if (!self._dataSource) return; self._dataSource.entities.removeAll(); var features = data.features || []; self._count = features.length; var now = Date.now(); features.forEach(function(f) { var c = f.geometry.coordinates; var p = f.properties; var mag = p.mag || 1; var ageH = (now - p.time) / 3600000; var color = ageH < 1 ? Cesium.Color.RED.withAlpha(0.8) : ageH < 6 ? Cesium.Color.ORANGE.withAlpha(0.7) : ageH < 12 ? Cesium.Color.YELLOW.withAlpha(0.6) : Cesium.Color.YELLOW.withAlpha(0.4); var radius = Math.max(mag * 15000, 20000); // Meter self._dataSource.entities.add({ position: Cesium.Cartesian3.fromDegrees(c[0], c[1]), ellipse: { semiMinorAxis: radius, semiMajorAxis: radius, material: color, outline: true, outlineColor: color.withAlpha(1.0), outlineWidth: 1, heightReference: Cesium.HeightReference.NONE, }, description: '