Skip to content

Commit

Permalink
BGDIINF_SB-3185 : better background switch 2D/3D
Browse files Browse the repository at this point in the history
as we have "common" products, but they are defined differently in the 3D world. So I've created a matching matrix, so that we may swap between 2D and 3D equivalent when changing the 3D state
  • Loading branch information
pakb committed Nov 8, 2023
1 parent 2412725 commit 7a291ef
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/store/plugins/2d-to-3d-management.plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { DEFAULT_PROJECTION } from '@/config'
import { WEBMERCATOR } from '@/utils/coordinates/coordinateSystems'

const backgroundMatriceBetween2dAnd3d = {
'ch.swisstopo.pixelkarte-farbe': 'ch.swisstopo.swisstlm3d-karte-farbe_3d',
'ch.swisstopo.pixelkarte-grau': 'ch.swisstopo.swisstlm3d-karte-grau_3d',
'ch.swisstopo.swissimage': 'ch.swisstopo.swissimage_3d',
}

/**
* Plugin to switch to WebMercator coordinate system when we go 3D, and swap back to the default
* projection when 2D is re-activated
Expand All @@ -9,12 +15,40 @@ import { WEBMERCATOR } from '@/utils/coordinates/coordinateSystems'
*/
export default function from2Dto3Dplugin(store) {
store.subscribeAction({
after: (action, state) => {
if (DEFAULT_PROJECTION.epsg !== WEBMERCATOR.epsg && action.type === 'set3dActive') {
before: (action, state) => {
if (action.type === 'set3dActive') {
if (state.cesium.active) {
store.dispatch('setProjection', WEBMERCATOR)
// when going 2D, as we are before the action
const matching2dBackgroundId = Object.entries(
backgroundMatriceBetween2dAnd3d
).find(([_, layerId3d]) => {
return layerId3d === state.layers.currentBackgroundLayer?.getID()
})
if (matching2dBackgroundId.length > 0) {
store.dispatch('setBackground', matching2dBackgroundId[0])
}
} else {
store.dispatch('setProjection', DEFAULT_PROJECTION)
// when going 3D, as we are before the action
if (state.layers.currentBackgroundLayer) {
const matching3dBackgroundId =
backgroundMatriceBetween2dAnd3d[
state.layers.currentBackgroundLayer.getID()
]
if (matching3dBackgroundId) {
store.dispatch('setBackground', matching3dBackgroundId)
}
}
}
}
},
after: (action, state) => {
if (action.type === 'set3dActive') {
if (DEFAULT_PROJECTION.epsg !== WEBMERCATOR.epsg) {
if (state.cesium.active) {
store.dispatch('setProjection', WEBMERCATOR)
} else {
store.dispatch('setProjection', DEFAULT_PROJECTION)
}
}
}
},
Expand Down

0 comments on commit 7a291ef

Please sign in to comment.