Skip to content

Commit

Permalink
Merge pull request #1004 from geoadmin/bug-PB-811-geolocalisation
Browse files Browse the repository at this point in the history
PB-811: Fix go to position if geolocation is active at startup - #patch
  • Loading branch information
ltshb authored Jul 12, 2024
2 parents b813fff + da8973f commit b24a85c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
9 changes: 7 additions & 2 deletions src/router/legacyPermalinkManagement.routerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,23 @@ const handleLegacyParam = (
break
// if no special work to do, we just copy past legacy params to the new viewer
default:
// NOTE: legacyValue is parsed using URLSearchParams which don't make any difference
// between &foo and &foo=
newValue = legacyValue
break
}

if (newValue) {
if (newValue !== undefined) {
// When receiving a query, the application will encode the URI components
// We decode those so that the new query won't encode encoded character
// for example, we avoid having " " becoming %2520 in the URI
newQuery[key] = decodeURIComponent(newValue)
log.info(
`[Legacy URL] ${param}=${legacyValue} parameter changed to ${key}=${decodeURIComponent(newValue)}`
`[Legacy URL] ${param}=${legacyValue} parameter changed to ${key}=${decodeURIComponent(newValue)}`,
newQuery
)
} else {
log.error(`[Legacy URL] ${param}=${legacyValue} parameter not processed`)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('Test all AbstractParamConfig class functionalities', () => {
})
expect(testInstance.readValueFromQuery({ test: 'true' })).to.be.true
expect(testInstance.readValueFromQuery({ test: 'false' })).to.be.false
expect(testInstance.readValueFromQuery({ test: '' })).to.be.false
expect(testInstance.readValueFromQuery({ test: '' })).to.be.true
// null value means the param without value, we want it to be true
expect(testInstance.readValueFromQuery({ test: null })).to.be.true
expect(testInstance.readValueFromQuery({})).to.be.undefined
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('Test all AbstractParamConfig class functionalities', () => {
})
expect(testInstance.readValueFromQuery({ test: 'true' })).to.be.true
expect(testInstance.readValueFromQuery({ test: 'false' })).to.be.false
expect(testInstance.readValueFromQuery({ test: '' })).to.be.false
expect(testInstance.readValueFromQuery({ test: '' })).to.be.true
// null value means the param without value, we want it to be true
expect(testInstance.readValueFromQuery({ test: null })).to.be.true
expect(testInstance.readValueFromQuery({})).to.be.true
Expand Down
3 changes: 2 additions & 1 deletion src/router/storeSync/abstractParamConfig.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export default class AbstractParamConfig {
// is present in the query (without a boolean value attached)
return (
queryValue === null ||
(typeof queryValue === 'string' && queryValue === 'true') ||
queryValue === 'true' ||
queryValue === '' ||
(typeof queryValue === 'boolean' && !!queryValue)
)
} else if (queryValue === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/geolocation.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const state = {
*
* @type Boolean
*/
tracking: false,
tracking: true,
/**
* Device position in the current application projection [x, y]
*
Expand Down
27 changes: 15 additions & 12 deletions src/store/plugins/geolocation-management.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,22 @@ const handlePositionAndDispatchToStore = (position, store) => {
accuracy: position.coords.accuracy,
...dispatcher,
})
// if tracking is active, we center the view of the map on the position received
// if tracking is active, we center the view of the map on the position received and change
// to the proper zoom
if (store.state.geolocation.tracking) {
setCenterIfInBounds(store, positionProjected)
// set zoom level if needed
let zoomLevel = STANDARD_ZOOM_LEVEL_1_25000_MAP
if (store.state.position.projection instanceof CustomCoordinateSystem) {
zoomLevel =
store.state.position.projection.transformStandardZoomLevelToCustom(zoomLevel)
}
if (store.state.position.zoom != zoomLevel) {
store.dispatch('setZoom', {
zoom: zoomLevel,
...dispatcher,
})
}
}
}

Expand Down Expand Up @@ -120,7 +133,7 @@ const handlePositionError = (error, store, state, options = {}) => {
}

const activeGeolocation = (store, state, options = {}) => {
const { useInitial = false } = options
const { useInitial = true } = options
if (
useInitial &&
store.state.geolocation.position[0] !== 0 &&
Expand Down Expand Up @@ -152,16 +165,6 @@ const activeGeolocation = (store, state, options = {}) => {

// handle current position
handlePositionAndDispatchToStore(position, store)

// set zoom level
let zoomLevel = STANDARD_ZOOM_LEVEL_1_25000_MAP
if (state.position.projection instanceof CustomCoordinateSystem) {
zoomLevel = state.position.projection.transformStandardZoomLevelToCustom(zoomLevel)
}
store.dispatch('setZoom', {
zoom: zoomLevel,
...dispatcher,
})
},
(error) => handlePositionError(error, store, state, { reactivate: true }),
{
Expand Down

0 comments on commit b24a85c

Please sign in to comment.