Skip to content

Commit e0119bf

Browse files
authored
Merge pull request #495 from geoadmin/feat-BGDIINF_SB-geolocation
BGDIINF_SB-2890: Made the geolocation working with any projection
2 parents eb04ec6 + 8faf54f commit e0119bf

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/store/plugins/geolocation-management.plugin.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { IS_TESTING_WITH_CYPRESS } from '@/config'
22
import i18n from '@/modules/i18n'
3-
import { WEBMERCATOR, WGS84 } from '@/utils/coordinates/coordinateSystems'
3+
import { WGS84 } from '@/utils/coordinates/coordinateSystems'
44
import log from '@/utils/logging'
55
import proj4 from 'proj4'
66

77
let geolocationWatcher = null
88
let firstTimeActivatingGeolocation = true
99

10-
const readPositionEpsg3857 = (position) => {
10+
const readPosition = (position, projection) => {
1111
const { coords } = position
12-
return proj4(WGS84.epsg, WEBMERCATOR.epsg, [coords.longitude, coords.latitude])
12+
return proj4(WGS84.epsg, projection.epsg, [coords.longitude, coords.latitude])
1313
}
1414

1515
const handlePositionAndDispatchToStore = (position, store) => {
16-
const positionEpsg3857 = readPositionEpsg3857(position)
17-
store.dispatch('setGeolocationPosition', positionEpsg3857)
16+
const positionProjected = readPosition(position, store.state.position.projection)
17+
store.dispatch('setGeolocationPosition', positionProjected)
1818
store.dispatch('setGeolocationAccuracy', position.coords.accuracy)
1919
// if tracking is active, we center the view of the map on the position received
2020
if (store.state.geolocation.tracking) {
21-
store.dispatch('setCenter', positionEpsg3857)
21+
store.dispatch('setCenter', positionProjected)
2222
}
2323
}
2424

0 commit comments

Comments
 (0)