Skip to content

Commit 07e6ad1

Browse files
authored
Merge branch 'master' into elevation-multi-dataset
2 parents cc457e5 + a53aa2b commit 07e6ad1

4 files changed

Lines changed: 33 additions & 16 deletions

File tree

components/map3d/Compare3D.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class Compare3D extends React.Component {
144144

145145
const renderer = this.props.sceneContext.scene.renderer;
146146
renderer.domElement.addEventListener("pointerdown", this.dragArrows);
147+
this.centerArrowsInView();
147148
};
148149
disableArrows = () => {
149150
this.props.sceneContext.scene.view.controls?.removeEventListener?.('change', this.centerArrowsInView);

components/map3d/Map3D.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ class Map3D extends React.Component {
221221
}
222222
};
223223
setBaseLayer = (layer, visibility) => {
224+
const currentBaseLayer = this.state.sceneContext.baseLayers.find(l => l.visibility === true)?.name || "";
225+
if (visibility && layer?.name === currentBaseLayer) {
226+
// Nothing changed
227+
return;
228+
}
224229
this.setState(state => ({
225230
sceneContext: {
226231
...state.sceneContext,
@@ -978,6 +983,7 @@ class Map3D extends React.Component {
978983
resolve({
979984
objects: objects,
980985
colorLayers: layers,
986+
baseLayer: this.state.sceneContext.baseLayers.find(layer => layer.visibility === true)?.name || "",
981987
personHeight: this.state.sceneContext.scene.view.controls.personHeight ?? 0,
982988
camera: [camera.x, camera.y, camera.z],
983989
target: [target.x, target.y, target.z]
@@ -1014,14 +1020,14 @@ class Map3D extends React.Component {
10141020
}
10151021
});
10161022
this.state.sceneContext.restoreView(data);
1017-
if (data.baselayer !== undefined) {
1023+
if (data.baseLayer !== undefined) {
10181024
this.setState(state => ({
10191025
sceneContext: {
10201026
...state.sceneContext,
1021-
baseLayers: state.sceneContext.baseLayers.map(l => ({...l, visibility: l.name === data.baselayer}))
1027+
baseLayers: state.sceneContext.baseLayers.map(l => ({...l, visibility: l.name === data.baseLayer}))
10221028
}
10231029
}));
1024-
UrlParams.updateParams({bl3d: data.baselayer});
1030+
UrlParams.updateParams({bl3d: data.baseLayer});
10251031
}
10261032
this.state.sceneContext.scene.notifyChange();
10271033
};

components/map3d/MapControls3D.jsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,28 @@ class MapControls3D extends React.Component {
175175
setViewToExtent = (bounds, angle = 0) => {
176176
this.leaveFirstPerson();
177177

178-
const center = {
179-
x: 0.5 * (bounds[0] + bounds[2]),
180-
y: 0.5 * (bounds[1] + bounds[3])
181-
};
182-
center.z = this.props.sceneContext.getTerrainHeightFromMap([center.x, center.y]) ?? 0;
183-
184-
// Camera height to width bbox width
185178
const fov = CAMERA_FOV / 180 * Math.PI;
186179
const cameraHeight = (bounds[2] - bounds[0]) / (2 * Math.tan(fov / 2));
187180

188-
const camerapos = new Vector3(center.x, center.y, center.z + cameraHeight);
189-
const target = new Vector3(center.x, center.y, center.z);
190-
this.controls.animateTo(camerapos, target, angle);
181+
const center = {
182+
x: 0.5 * (bounds[0] + bounds[2]),
183+
y: 0.5 * (bounds[1] + bounds[3]),
184+
};
185+
const camerapos = new Vector3(center.x, center.y, cameraHeight);
186+
const target = new Vector3(center.x, center.y, 0);
187+
const h = this.props.sceneContext.getTerrainHeightFromMap([center.x, center.y]);
188+
// Fall back to getTerrainHeightFromDTM if map is not yet loaded
189+
if (h === undefined) {
190+
this.props.sceneContext.getTerrainHeightFromDTM([center.x, center.y]).then(h2 => {
191+
camerapos.z += h2;
192+
target.z += h2;
193+
this.controls.animateTo(camerapos, target, angle);
194+
})
195+
} else {
196+
camerapos.z += h;
197+
target.z += h;
198+
this.controls.animateTo(camerapos, target, angle);
199+
}
191200
};
192201
pan = (ev, dx, dy) => {
193202
const panInterval = setInterval(() => {

plugins/View3D.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import React from 'react';
1010
import {connect, Provider} from 'react-redux';
1111

12+
import isEmpty from 'lodash.isempty';
1213
import PropTypes from 'prop-types';
1314
import {createSelector} from 'reselect';
1415

@@ -256,6 +257,7 @@ class View3D extends React.Component {
256257
} else if (this.props.view3dMode === View3DMode.DISABLING && prevProps.view3dMode !== View3DMode.DISABLING) {
257258
this.map3dComponentRef.store3dState().then(storedState => {
258259
this.setState({storedState});
260+
UrlParams.updateParams({v3d: undefined, bl3d: undefined});
259261
this.props.setView3dMode(View3DMode.DISABLED);
260262
});
261263
} else if (this.props.view3dMode === View3DMode.DISABLED && prevProps.view3dMode !== View3DMode.DISABLED) {
@@ -389,8 +391,7 @@ class View3D extends React.Component {
389391
return [button, this.render3DWindow()];
390392
}
391393
onClose = () => {
392-
this.props.setView3dMode(View3DMode.DISABLED);
393-
UrlParams.updateParams({v3d: undefined});
394+
this.props.setView3dMode(View3DMode.DISABLING);
394395
};
395396
onGeometryChanged = (geometry) => {
396397
if (geometry.maximized && this.props.view3dMode !== View3DMode.FULLSCREEN) {
@@ -462,7 +463,7 @@ class View3D extends React.Component {
462463
};
463464
setupMap = () => {
464465
if (this.map3dComponentRef) {
465-
if (this.state.storedState) {
466+
if (!isEmpty(this.state.storedState)) {
466467
this.map3dComponentRef.restore3dState(this.state.storedState);
467468
} else {
468469
this.sync2DExtent();

0 commit comments

Comments
 (0)