Skip to content

Commit

Permalink
BGDIINF_SB-3007: Set camera to null if undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
fredj committed Jul 13, 2023
1 parent da23e27 commit 9b91860
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 33 deletions.
31 changes: 19 additions & 12 deletions src/modules/map/components/cesium/CesiumMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ export default {
computed: {
...mapState({
zoom: (state) => state.position.zoom,
rotation: (state) => state.position.rotation,
center: (state) => state.position.center,
is3DActive: (state) => state.ui.showIn3d,
camera: (state) => state.position.camera,
uiMode: (state) => state.ui.mode,
previewYear: (state) => state.layers.previewYear,
}),
...mapGetters(['centerEpsg4326', 'resolution', 'hasDevSiteWarning', 'visibleLayers']),
...mapGetters(['centerEpsg4326', 'hasDevSiteWarning', 'visibleLayers']),
isDesktopMode() {
return this.uiMode === UIModes.DESKTOP
},
Expand Down Expand Up @@ -156,18 +154,27 @@ export default {
this.flyToPosition()
},
unmounted() {
this.setCameraPosition(null)
this.viewer.destroy()
delete this.viewer
},
methods: {
...mapActions(['setCameraPosition']),
flyToPosition() {
const cameraHeight =
(this.resolution * this.viewer.canvas.clientWidth) /
(2 * Math.tan(this.viewer.camera.frustum.fov / 2))
const x = this.camera ? this.camera.x : this.centerEpsg4326[0]
const y = this.camera ? this.camera.y : this.centerEpsg4326[1]
const z = this.camera ? this.camera.z : 20000 // FIXME: convert this.zoom to z
const heading = CesiumMath.toRadians(this.camera ? this.camera.heading : 0)
const pitch = CesiumMath.toRadians(this.camera ? this.camera.pitch :-90)
const roll = CesiumMath.toRadians(this.camera ? this.camera.roll : 0)
this.viewer.camera.flyTo({
destination: Cartesian3.fromDegrees(
this.centerEpsg4326[0],
this.centerEpsg4326[1],
cameraHeight
),
destination: Cartesian3.fromDegrees(x, y, z),
orientation: {
heading,
pitch,
roll,
},
duration: 0,
})
},
Expand Down
2 changes: 1 addition & 1 deletion src/router/storeSync/CameraParamConfig.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function dispatchCameraFromUrlIntoStore(store, urlParamValue) {
}

function generateCameraUrlParamFromStoreValues(store) {
if (store.state.ui.showIn3d) {
if (store.state.ui.showIn3d && store.state.position.camera !== null) {
const { x, y, z, pitch, heading, roll } = store.state.position.camera
const valuesAsString = [x, y, z, pitch, heading, roll].map((value) =>
value === 0 ? '' : `${value}`
Expand Down
20 changes: 2 additions & 18 deletions src/store/modules/position.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,7 @@ const state = {
*
* @type CameraPosition
*/
camera: {
x: 0,
y: 0,
z: 0,
heading: 0,
pitch: 0,
roll: 0,
},
camera: null,
}

/**
Expand Down Expand Up @@ -289,16 +282,7 @@ const actions = {
* @param {CameraPosition} cameraPosition
*/
setCameraPosition({ commit }, cameraPosition) {
// defaulting to 0 if the camera position is lacking some properties
const curatedCameraPosition = Object.assign({
x: 0,
y: 0,
z: 0,
heading: 0,
pitch: 0,
roll: 0,
}, cameraPosition)
commit('setCameraPosition', curatedCameraPosition)
commit('setCameraPosition', cameraPosition)
},
}

Expand Down
2 changes: 1 addition & 1 deletion src/store/plugins/sync-camera-lonlatzoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
export default function syncCameraLonLatZoom(store) {
store.subscribe((mutation, state) => {
if (mutation.type === 'setCameraPosition') {
if (mutation.type === 'setCameraPosition' && state.position.camera !== null) {
store.dispatch('setLongitude', parseFloat(state.position.camera.x))
store.dispatch('setLatitude', parseFloat(state.position.camera.y))
// FIXME: store.dispatch('setZoom', something(state.position.camera.z))
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e-cypress/integration/3d/transitionTo3d.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Testing transitioning between 2D and 3D', () => {
cy.get('[data-cy="3d-button"]').click()
cy.readWindowValue('cesiumViewer').then((viewer) => {
const cameraPosition = viewer.camera.positionCartographic
expect(cameraPosition.longitude).to.eq(0.13147292983909972)
expect(cameraPosition.longitude).to.eq(0.13147292983909975)
expect(cameraPosition.latitude).to.eq(0.819968266410843)
expect(cameraPosition.height).to.eq(36434.03514736528)
})
Expand Down

0 comments on commit 9b91860

Please sign in to comment.