Skip to content

Commit 275bd15

Browse files
committed
PB-2058: Fix not zooming when geolocation is activated.
1 parent 479e8b4 commit 275bd15

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

packages/viewer/src/store/modules/geolocation/utils/handleNewGeolocationPosition.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,25 @@ export default function handleNewGeolocationPosition(
3737
// Accuracy in in meter, so we don't need the decimal part and avoid dispatching event
3838
// if the accuracy did not change more than one metter
3939
const accuracy = round(position.coords.accuracy, 0)
40-
if (!isEqual(this.position, positionProjected) || this.accuracy !== accuracy) {
41-
this.setGeolocationPosition(positionProjected, dispatcher)
42-
this.setGeolocationAccuracy(accuracy, dispatcher)
43-
}
40+
4441
// if tracking is active, we center the view of the map on the position received and change
4542
// to the proper zoom
43+
// IMPORTANT: Call setCenterIfInBounds BEFORE updating position to avoid setCenter disabling tracking
4644
if (this.tracking) {
4745
setCenterIfInBounds.call(this, positionProjected, dispatcher)
46+
} else {
47+
log.debug({
48+
title: 'Geolocation store / handleNewPosition',
49+
titleColor: LogPreDefinedColor.Amber,
50+
messages: [
51+
`[handleNewGeolocationPosition] Skipping setCenterIfInBounds - tracking is false`,
52+
],
53+
})
54+
}
55+
56+
// Update position and accuracy after centering
57+
if (!isEqual(this.position, positionProjected) || this.accuracy !== accuracy) {
58+
this.setGeolocationPosition(positionProjected, dispatcher)
59+
this.setGeolocationAccuracy(accuracy, dispatcher)
4860
}
4961
}

0 commit comments

Comments
 (0)