Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BGDIINF_SB-3061 : keep where the camera is looking at when going back 2D #441

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/modules/map/components/cesium/CesiumMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ import log from '@/utils/logging'
import '@geoblocks/cesium-compass'
import * as cesium from 'cesium'
import {
Cartesian2,
Cartesian3,
Cartographic,
CesiumTerrainProvider,
Color,
defined,
Ellipsoid,
Math as CesiumMath,
RequestScheduler,
ScreenSpaceEventType,
Expand Down Expand Up @@ -270,6 +273,26 @@ export default {
globe.maximumScreenSpaceError = 30
}
},
beforeUnmount() {
// the camera position that is for now dispatched to the store doesn't correspond where the 2D
// view is looking at, as if the camera is tilted, its position will be over swaths of lands that
// have nothing to do with the top-down 2D view.
// here we ray trace the coordinate of where the camera is looking at, and send this "target"
// to the store as the new center
const ray = this.viewer.camera.getPickRay(
new Cartesian2(
Math.round(this.viewer.scene.canvas.clientWidth / 2),
Math.round(this.viewer.scene.canvas.clientHeight / 2)
)
)
const cameraTarget = this.viewer.scene.globe.pick(ray, this.viewer.scene)
if (defined(cameraTarget)) {
const cameraTargetCartographic = Ellipsoid.WGS84.cartesianToCartographic(cameraTarget)
const lat = CesiumMath.toDegrees(cameraTargetCartographic.latitude)
const lon = CesiumMath.toDegrees(cameraTargetCartographic.longitude)
this.setCenter(proj4(WGS84.epsg, WEBMERCATOR.epsg, [lon, lat]))
}
},
unmounted() {
this.setCameraPosition(null)
this.viewer.destroy()
Expand All @@ -281,6 +304,7 @@ export default {
'clearAllSelectedFeatures',
'click',
'toggleFloatingTooltip',
'setCenter',
]),
highlightSelectedFeatures() {
const [firstFeature] = this.selectedFeatures
Expand Down
Loading