Skip to content

Commit 63dbe43

Browse files
authored
Merge pull request #607 from geoadmin/feat-PB-100-manage-3d-parameters
PB-100: Manage camera and 3D parameter from the legacy parameters
2 parents 913d604 + 1971af6 commit 63dbe43

File tree

4 files changed

+119
-5
lines changed

4 files changed

+119
-5
lines changed

src/router/legacyPermalinkManagement.routerPlugin.js

+34-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import proj4 from 'proj4'
22

33
import { DISABLE_DRAWING_MENU_FOR_LEGACY_ON_HOSTNAMES } from '@/config'
44
import { transformLayerIntoUrlString } from '@/router/storeSync/LayerParamConfig.class'
5+
import { backgroundMatriceBetween2dAnd3d as backgroundMatriceBetweenLegacyAndNew } from '@/store/plugins/2d-to-3d-management.plugin'
56
import { LV95, WEBMERCATOR, WGS84 } from '@/utils/coordinates/coordinateSystems'
67
import CustomCoordinateSystem from '@/utils/coordinates/CustomCoordinateSystem.class'
78
import SwissCoordinateSystem from '@/utils/coordinates/SwissCoordinateSystem.class'
@@ -51,7 +52,8 @@ const handleLegacyParam = (
5152
store,
5253
newQuery,
5354
latlongCoordinates,
54-
legacyCoordinates
55+
legacyCoordinates,
56+
cameraPosition
5557
) => {
5658
const { projection } = store.state.position
5759
let newValue
@@ -83,9 +85,11 @@ const handleLegacyParam = (
8385

8486
case 'lon':
8587
latlongCoordinates[0] = Number(legacyValue)
88+
cameraPosition[0] = Number(legacyValue)
8689
break
8790
case 'lat':
8891
latlongCoordinates[1] = Number(legacyValue)
92+
cameraPosition[1] = Number(legacyValue)
8993
break
9094

9195
// taking all layers related param aside so that they can be processed later (see below)
@@ -123,6 +127,18 @@ const handleLegacyParam = (
123127
newValue = legacyValue
124128
break
125129

130+
case 'elevation':
131+
cameraPosition[2] = Number(legacyValue)
132+
break
133+
134+
case 'pitch':
135+
cameraPosition[3] = Number(legacyValue)
136+
break
137+
138+
case 'heading':
139+
cameraPosition[4] = Number(legacyValue)
140+
break
141+
126142
// if no special work to do, we just copy past legacy params to the new viewer
127143
default:
128144
newValue = legacyValue
@@ -145,6 +161,7 @@ const handleLegacyParams = (legacyParams, store, to, next) => {
145161
const { projection } = store.state.position
146162
let legacyCoordinates = []
147163
let latlongCoordinates = []
164+
let cameraPosition = []
148165
// TODO BGDIINF_SB-2685: remove once legacy prod is decommissioned
149166
const isOnDevelopmentHost = DISABLE_DRAWING_MENU_FOR_LEGACY_ON_HOSTNAMES.some(
150167
(hostname) => hostname === store.state.ui.hostname
@@ -157,9 +174,24 @@ const handleLegacyParams = (legacyParams, store, to, next) => {
157174
store,
158175
newQuery,
159176
latlongCoordinates,
160-
legacyCoordinates
177+
legacyCoordinates,
178+
cameraPosition
161179
)
162180
})
181+
if (cameraPosition.length >= 3) {
182+
cameraPosition.push('')
183+
newQuery['camera'] = cameraPosition.join(',')
184+
newQuery['3d'] = true
185+
newQuery['sr'] = WEBMERCATOR.epsgNumber
186+
187+
// Handle different background layer from legacy 3D parameter
188+
if (newQuery['bgLayer']) {
189+
const newBackgroundLayer = backgroundMatriceBetweenLegacyAndNew[newQuery['bgLayer']]
190+
if (newBackgroundLayer) {
191+
newQuery['bgLayer'] = newBackgroundLayer
192+
}
193+
}
194+
}
163195

164196
// Convert legacies coordinates if needed
165197
if (latlongCoordinates.length === 2) {
@@ -241,7 +273,6 @@ const legacyPermalinkManagementRouterPlugin = (router, store) => {
241273
// to.query only parse the query after the /#? and legacy params are at the root /?
242274
const legacyParams =
243275
window.location && window.location.search ? parseLegacyParams(window.location.search) : null
244-
245276
router.beforeEach((to, from, next) => {
246277
// Waiting for the app to enter the MapView before dealing with legacy param, otherwise
247278
// the storeSync plugin might overwrite some parameters. To handle legacy param we also

src/store/plugins/2d-to-3d-management.plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DEFAULT_PROJECTION } from '@/config'
22
import { WEBMERCATOR } from '@/utils/coordinates/coordinateSystems'
33

4-
const backgroundMatriceBetween2dAnd3d = {
4+
export const backgroundMatriceBetween2dAnd3d = {
55
'ch.swisstopo.pixelkarte-farbe': 'ch.swisstopo.swisstlm3d-karte-farbe_3d',
66
'ch.swisstopo.pixelkarte-grau': 'ch.swisstopo.swisstlm3d-karte-grau_3d',
77
'ch.swisstopo.swissimage': 'ch.swisstopo.swissimage_3d',

tests/cypress/support/commands.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,13 @@ Cypress.Commands.add(
214214
errorMsg: 'Timeout waiting for all layers to be loaded',
215215
}
216216
)
217-
if ('3d' in queryParams && queryParams['3d'] === true) {
217+
218+
// In the legacy URL, 3d is not found. We check if the map in 3d or not by checking the pitch, heading, and elevation
219+
const isLegacy3d =
220+
'pitch' in queryParams || 'heading' in queryParams || 'elevation' in queryParams
221+
const is3d = '3d' in queryParams && queryParams['3d'] === true
222+
223+
if (is3d || isLegacy3d) {
218224
cy.get('[data-cy="cesium-map"]').should('be.visible')
219225
} else {
220226
cy.get('[data-cy="ol-map"]', { timeout: 10000 }).should('be.visible')

tests/cypress/tests-e2e/legacyParamImport.cy.js

+77
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,81 @@ describe('Test on legacy param import', () => {
288288
})
289289
})
290290
})
291+
292+
context('3D import', () => {
293+
const lat = 47.3
294+
const lon = 7.3
295+
const elevation = 215370
296+
const heading = 318
297+
const pitch = -45
298+
299+
it('transfers camera parameter from legacy URL to the new URL', () => {
300+
cy.goToMapView({
301+
lat,
302+
lon,
303+
elevation,
304+
heading,
305+
pitch,
306+
})
307+
308+
// checking in the store that the parameters have been converted into the new 3D parameters
309+
cy.readStoreValue('state.cesium.active').should('eq', true) // cesium should be active
310+
311+
// Checking camera position
312+
cy.readStoreValue('state.position.camera.x').should('eq', lon)
313+
cy.readStoreValue('state.position.camera.y').should('eq', lat)
314+
cy.readStoreValue('state.position.camera.z').should('eq', elevation)
315+
cy.readStoreValue('state.position.camera.heading').should('eq', heading)
316+
cy.readStoreValue('state.position.camera.pitch').should('eq', pitch)
317+
cy.readStoreValue('state.position.camera.roll').should('eq', 360)
318+
319+
// EPSG is set to 3857
320+
cy.readStoreValue('state.position.projection.epsgNumber').should('eq', 3857)
321+
})
322+
323+
it('transfers camera parameter from legacy URL to the new URL only heading', () => {
324+
cy.goToMapView({
325+
lat,
326+
lon,
327+
heading,
328+
})
329+
330+
// checking in the store that the parameters have been converted into the new 3D parameters
331+
cy.readStoreValue('state.cesium.active').should('eq', true) // cesium should be active
332+
333+
// Checking camera position
334+
cy.readStoreValue('state.position.camera.x').should('eq', lon)
335+
cy.readStoreValue('state.position.camera.y').should('eq', lat)
336+
cy.readStoreValue('state.position.camera.z').should('eq', 0)
337+
cy.readStoreValue('state.position.camera.heading').should('eq', heading)
338+
cy.readStoreValue('state.position.camera.pitch').should('eq', 0)
339+
cy.readStoreValue('state.position.camera.roll').should('eq', 360)
340+
341+
// EPSG is set to 3857
342+
cy.readStoreValue('state.position.projection.epsgNumber').should('eq', 3857)
343+
})
344+
345+
it('transfers camera parameter from legacy URL to the new URL only elevation', () => {
346+
cy.goToMapView({
347+
lat,
348+
lon,
349+
elevation,
350+
})
351+
352+
// checking in the store that the parameters have been converted into the new 3D parameters
353+
cy.readStoreValue('state.cesium.active').should('eq', true) // cesium should be active
354+
355+
// Checking camera position
356+
// x, y, and z seems recalculated when there is only elevation, so I just check that they are not null
357+
cy.readStoreValue('state.position.camera.x').should('not.be.null')
358+
cy.readStoreValue('state.position.camera.y').should('not.be.null')
359+
cy.readStoreValue('state.position.camera.z').should('not.be.null')
360+
cy.readStoreValue('state.position.camera.heading').should('eq', 360)
361+
cy.readStoreValue('state.position.camera.pitch').should('eq', -90)
362+
cy.readStoreValue('state.position.camera.roll').should('eq', 0)
363+
364+
// EPSG is set to 3857
365+
cy.readStoreValue('state.position.projection.epsgNumber').should('eq', 3857)
366+
})
367+
})
291368
})

0 commit comments

Comments
 (0)