Skip to content

Commit

Permalink
PB-811: Only change the zoom in geolocation when tracking
Browse files Browse the repository at this point in the history
When not tracking, e.g. you have a permalink with geolocation with a fix center
and zoom, you don't want to change the zoom.
  • Loading branch information
ltshb committed Jul 12, 2024
1 parent b7c9016 commit da8973f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
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
25 changes: 14 additions & 11 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 @@ -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 da8973f

Please sign in to comment.