diff --git a/ui/src/constants.ts b/ui/src/constants.ts
index 4f9197ad5..88ef73e83 100644
--- a/ui/src/constants.ts
+++ b/ui/src/constants.ts
@@ -8,6 +8,8 @@ export const SWITZERLAND_RECTANGLE = Rectangle.fromDegrees(...SWITZERLAND_BOUNDS
export const MINIMAP_EXTENT = [5.910642046, 45.191912227, 10.554524194, 48.04750923];
+export const MAP_RECTANGLE = Rectangle.fromDegrees(...[5.91, 45.8179, 10.9, 47.9]);
+
export const WEB_MERCATOR_TILING_SCHEME = new GeographicTilingScheme({
ellipsoid: Ellipsoid.WGS84,
rectangle: SWITZERLAND_RECTANGLE,
diff --git a/ui/src/earthquakeVisualization/earthquakeVisualizer.js b/ui/src/earthquakeVisualization/earthquakeVisualizer.js
index 4a9edcdbd..b11258725 100644
--- a/ui/src/earthquakeVisualization/earthquakeVisualizer.js
+++ b/ui/src/earthquakeVisualization/earthquakeVisualizer.js
@@ -35,44 +35,42 @@ export default class EarthquakeVisualizer {
}
async showEarthquakes() {
- fetch(this.config.downloadUrl).then(response => {
- response.text().then(text => {
- parseEarthquakeData(text).map(data => {
- const size = Number(data.Magnitude.split(' ')[0]) * EARTHQUAKE_SPHERE_SIZE_COEF;
- const depthMeters = Number(data.Depthkm.split(' ')[0]) * 1000; // convert km to m
- const longitude = Number(data.Longitude);
- const latitude = Number(data.Latitude);
- delete data.Longitude;
- delete data.Latitude;
- const position = Cartesian3.fromDegrees(longitude, latitude, -depthMeters);
- const posCart = Cartographic.fromCartesian(position);
- const altitude = this.viewer.scene.globe.getHeight(posCart) || 0;
- posCart.height = posCart.height + altitude;
- Cartographic.toCartesian(posCart, undefined, position);
- const cameraDistance = size * 4;
- const zoomHeadingPitchRange = new HeadingPitchRange(0, CMath.toRadians(25), cameraDistance);
- data['Details'] = this.config.detailsUrl;
- this.boundingRectangle.west = Math.min(CMath.toRadians(longitude), this.boundingRectangle.west);
- this.boundingRectangle.south = Math.min(CMath.toRadians(latitude), this.boundingRectangle.south);
- this.boundingRectangle.east = Math.max(CMath.toRadians(longitude), this.boundingRectangle.east);
- this.boundingRectangle.north = Math.max(CMath.toRadians(latitude), this.boundingRectangle.north);
- this.maximumHeight = Math.max(this.maximumHeight, depthMeters * 2);
- return this.earthquakeDataSource.entities.add({
- position: position,
- ellipsoid: {
- radii: new Cartesian3(size, size, size),
- material: getColorFromTime(data.Time),
- },
- properties: {
- ...data,
- propsOrder: this.config.propsOrder,
- zoomHeadingPitchRange: zoomHeadingPitchRange
- }
- });
- });
- this.boundingSphere = BoundingSphere.fromRectangle3D(this.boundingRectangle);
+ const response = await fetch(this.config.downloadUrl);
+ const text = await response.text();
+ parseEarthquakeData(text).map(data => {
+ const size = Number(data.Magnitude.split(' ')[0]) * EARTHQUAKE_SPHERE_SIZE_COEF;
+ const depthMeters = Number(data.Depthkm.split(' ')[0]) * 1000; // convert km to m
+ const longitude = Number(data.Longitude);
+ const latitude = Number(data.Latitude);
+ delete data.Longitude;
+ delete data.Latitude;
+ const position = Cartesian3.fromDegrees(longitude, latitude, -depthMeters);
+ const posCart = Cartographic.fromCartesian(position);
+ const altitude = this.viewer.scene.globe.getHeight(posCart) || 0;
+ posCart.height = posCart.height + altitude;
+ Cartographic.toCartesian(posCart, undefined, position);
+ const cameraDistance = size * 4;
+ const zoomHeadingPitchRange = new HeadingPitchRange(0, CMath.toRadians(25), cameraDistance);
+ data['Details'] = this.config.detailsUrl;
+ this.boundingRectangle.west = Math.min(CMath.toRadians(longitude), this.boundingRectangle.west);
+ this.boundingRectangle.south = Math.min(CMath.toRadians(latitude), this.boundingRectangle.south);
+ this.boundingRectangle.east = Math.max(CMath.toRadians(longitude), this.boundingRectangle.east);
+ this.boundingRectangle.north = Math.max(CMath.toRadians(latitude), this.boundingRectangle.north);
+ this.maximumHeight = Math.max(this.maximumHeight, depthMeters * 2);
+ return this.earthquakeDataSource.entities.add({
+ position: position,
+ ellipsoid: {
+ radii: new Cartesian3(size, size, size),
+ material: getColorFromTime(data.Time),
+ },
+ properties: {
+ ...data,
+ propsOrder: this.config.propsOrder,
+ zoomHeadingPitchRange: zoomHeadingPitchRange
+ }
});
});
+ this.boundingSphere = BoundingSphere.fromRectangle3D(this.boundingRectangle);
}
/**
diff --git a/ui/src/elements/dashboard/ngm-dashboard.ts b/ui/src/elements/dashboard/ngm-dashboard.ts
index c396d6543..0409d6e1e 100644
--- a/ui/src/elements/dashboard/ngm-dashboard.ts
+++ b/ui/src/elements/dashboard/ngm-dashboard.ts
@@ -248,7 +248,6 @@ export class NgmDashboard extends LitElementI18n {
const name = await parseKml(this.viewer, href, uploadedLayer, !!asset.clampToGround);
this.assetConfigs[href] = {
label: name,
- zoomToBbox: true,
opacity: DEFAULT_LAYER_OPACITY,
notSaveToPermalink: true,
topicKml: true
diff --git a/ui/src/elements/ngm-side-bar.ts b/ui/src/elements/ngm-side-bar.ts
index 244458bbe..17a804ff9 100644
--- a/ui/src/elements/ngm-side-bar.ts
+++ b/ui/src/elements/ngm-side-bar.ts
@@ -40,11 +40,9 @@ import './ngm-share-link';
import '../layers/ngm-layers-upload';
import MainStore from '../store/main';
import {classMap} from 'lit/directives/class-map.js';
-import {zoomTo} from '../utils';
import $ from '../jquery';
import {customElement, property, query, state} from 'lit/decorators.js';
import type QueryManager from '../query/QueryManager';
-import NavToolsStore from '../store/navTools';
import DashboardStore from '../store/dashboard';
import {getAssets} from '../api-ion';
@@ -295,20 +293,13 @@ export class SideBar extends LitElementI18n {
html`
this.onLayersOrderChange(evt.detail)}
- @zoomTo=${evt => {
- NavToolsStore.hideTargetPoint();
- zoomTo(this.viewer!, evt.detail);
- }}>
+ .actions=${this.layerActions}
+ @orderChanged=${(evt) => this.onLayersOrderChange(evt.detail)}>
` :
html`
{
- NavToolsStore.hideTargetPoint();
- zoomTo(this.viewer!, evt.detail);
- }}
@removeDisplayedLayer=${evt => this.onRemoveDisplayedLayer(evt)}
@layerChanged=${evt => this.onLayerChanged(evt)}>
`
@@ -726,7 +717,6 @@ export class SideBar extends LitElementI18n {
label: name,
layer,
promise: promise,
- zoomToBbox: true,
opacity: DEFAULT_LAYER_OPACITY,
notSaveToPermalink: true,
ownKml: true,
diff --git a/ui/src/layers/LayersActions.ts b/ui/src/layers/LayersActions.ts
index 17fa87f6d..020f23bb4 100644
--- a/ui/src/layers/LayersActions.ts
+++ b/ui/src/layers/LayersActions.ts
@@ -1,6 +1,6 @@
import {syncLayersParam} from '../permalink';
import {calculateBox, calculateRectangle, getBoxFromRectangle} from './helpers';
-import {LayerType} from '../constants';
+import {LayerType, MAP_RECTANGLE} from '../constants';
import {
Cartesian3,
Rectangle,
@@ -9,7 +9,7 @@ import {
Cesium3DTileset,
ImageryLayer,
CustomDataSource,
- GeoJsonDataSource
+ GeoJsonDataSource, VoxelPrimitive
} from 'cesium';
import type {Viewer} from 'cesium';
@@ -61,29 +61,46 @@ export default class LayersAction {
const p = await config.promise;
// wrong type in cesium;
const rootBoundingVolume = ( p)?.root?.boundingVolume;
- if (p instanceof EarthquakeVisualizer && p.boundingRectangle) { // earthquakes
- this.boundingBoxEntity.position = Cartographic.toCartesian(Rectangle.center(p.boundingRectangle));
- this.boundingBoxEntity.box.dimensions = getBoxFromRectangle(p.boundingRectangle, p.maximumHeight);
- this.boundingBoxEntity.rectangle.coordinates = p.boundingRectangle;
- this.boundingBoxEntity.show = true;
- this.viewer.scene.requestRender();
+ if (p instanceof EarthquakeVisualizer) { // earthquakes
+ // fetch earthquakes to get bbox info
+ if (!isFinite(p.boundingRectangle.west)) {
+ await p.showEarthquakes();
+ p.earthquakeDataSource.show = false;
+ }
+ this.showBbox(p.boundingRectangle, p.maximumHeight, true);
} else if ((p instanceof Cesium3DTileset) && rootBoundingVolume) {
const boundingVolume = rootBoundingVolume.boundingVolume;
const boundingRectangle = rootBoundingVolume.rectangle;
- this.boundingBoxEntity.position = boundingVolume.center;
if (boundingRectangle) {
+ this.boundingBoxEntity.position = boundingVolume.center;
this.boundingBoxEntity.box.dimensions = getBoxFromRectangle(boundingRectangle, rootBoundingVolume.maximumHeight);
this.boundingBoxEntity.rectangle.coordinates = boundingRectangle;
+ this.boundingBoxEntity.show = true;
+ this.viewer.scene.requestRender();
} else {
const boxSize = calculateBox(boundingVolume.halfAxes, p.root.boundingSphere.radius);
- this.boundingBoxEntity.box.dimensions = boxSize;
- this.boundingBoxEntity.rectangle.coordinates = calculateRectangle(boxSize.x, boxSize.y, boundingVolume.center);
+ const boundingRectangle = calculateRectangle(boxSize.x, boxSize.y, boundingVolume.center);
+ this.showBbox(boundingRectangle, boxSize.z);
}
- this.boundingBoxEntity.show = true;
- this.viewer.scene.requestRender();
+ } else if (p instanceof ImageryLayer) {
+ this.showBbox(p.imageryProvider.rectangle, 20000);
+ } else if (p instanceof VoxelPrimitive) {
+ const boxSize = calculateBox(p.orientedBoundingBox.halfAxes, p.boundingSphere.radius);
+ const boundingRectangle = calculateRectangle(boxSize.x, boxSize.y, p.orientedBoundingBox.center);
+ this.showBbox(boundingRectangle, boxSize.z);
}
}
+ private showBbox(boundingRectangle: Rectangle, height: number = 0, skipIntersectionCheck: boolean = false) {
+ if (!boundingRectangle) return;
+ if (!skipIntersectionCheck) Rectangle.intersection(MAP_RECTANGLE, boundingRectangle, boundingRectangle);
+ this.boundingBoxEntity.position = Cartographic.toCartesian(Rectangle.center(boundingRectangle));
+ this.boundingBoxEntity.box.dimensions = getBoxFromRectangle(boundingRectangle, height);
+ this.boundingBoxEntity.rectangle.coordinates = boundingRectangle;
+ this.boundingBoxEntity.show = true;
+ this.viewer.scene.requestRender();
+ }
+
hideBoundingBox() {
if (this.boundingBoxEntity.show) {
this.boundingBoxEntity.show = false;
@@ -114,4 +131,12 @@ export default class LayersAction {
stuff[eventName].addEventListener(callback);
}
}
+
+ zoomToBbox() {
+ this.viewer.zoomTo(this.boundingBoxEntity, {
+ heading: 0,
+ pitch: -1.57079633,
+ range: 0
+ });
+ }
}
diff --git a/ui/src/layers/ngm-layers-item.ts b/ui/src/layers/ngm-layers-item.ts
index 27edb2059..5888477fd 100644
--- a/ui/src/layers/ngm-layers-item.ts
+++ b/ui/src/layers/ngm-layers-item.ts
@@ -250,14 +250,16 @@ export class NgmLayersItem extends LitElementI18n {