Skip to content

Commit 7197e5d

Browse files
committed
WIP
1 parent 479e8b4 commit 7197e5d

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

packages/viewer/src/store/modules/geolocation/actions/setGeolocationActive.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ActionDispatcher } from '@/store/types'
55

66
import handleGeolocationError from '@/store/modules/geolocation/utils/handleGeolocationError'
77
import handleNewGeolocationPosition from '@/store/modules/geolocation/utils/handleNewGeolocationPosition'
8-
import setCenterIfInBounds from '@/store/modules/geolocation/utils/setCenterIfInBounds'
8+
import setCenterIfInBounds, { resetFirstTime } from '@/store/modules/geolocation/utils/setCenterIfInBounds'
99

1010
interface GeolocationActivationOptions {
1111
/**
@@ -35,6 +35,7 @@ export default function setGeolocationActive(
3535
optionsOrDispatcher: GeolocationActivationOptions | ActionDispatcher,
3636
dispatcherOrNothing?: ActionDispatcher
3737
): void {
38+
console.log('[setGeolocationActive] Called with active:', active)
3839
this.active = active
3940

4041
const dispatcher = dispatcherOrNothing ?? (optionsOrDispatcher as ActionDispatcher)
@@ -44,11 +45,13 @@ export default function setGeolocationActive(
4445
this.errorCount = 0 // reset the error counter when starting the geolocation
4546

4647
const { usePreviousPosition = true } = options
47-
48+
console.log('[setGeolocationActive] usePreviousPosition:', usePreviousPosition)
49+
console.log('[setGeolocationActive] this.position:', this.position)
4850
if (usePreviousPosition && this.position) {
4951
// if we have a previous position, use it first to be more reactive but set
5052
// bad accuracy as we don't know how exact it is.
51-
if (this.tracking) {
53+
console.log('[setGeolocationActive] tracking is', this.tracking)
54+
if (this.tracking === false) {
5255
// only center if tracking (e.g., in 3D mode we don't center)
5356
setCenterIfInBounds.call(this, this.position, dispatcher)
5457
}
@@ -60,6 +63,7 @@ export default function setGeolocationActive(
6063
}
6164
navigator.geolocation.getCurrentPosition(
6265
(position) => {
66+
console.log('[setGeolocationActive] Current position:', position)
6367
log.debug({
6468
title: 'Geolocation store / setGeolocationActive',
6569
titleColor: LogPreDefinedColor.Amber,

packages/viewer/src/store/modules/geolocation/actions/setGeolocationTracking.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { GeolocationStore } from '@/store/modules/geolocation/types/geolocation'
22
import type { ActionDispatcher } from '@/store/types'
33

4-
import setCenterIfInBounds from '@/store/modules/geolocation/utils/setCenterIfInBounds'
4+
import setCenterIfInBounds, { resetFirstTime } from '@/store/modules/geolocation/utils/setCenterIfInBounds'
55

66
export default function setGeolocationTracking(
77
this: GeolocationStore,
@@ -12,6 +12,9 @@ export default function setGeolocationTracking(
1212

1313
// If tracking has been re-enabled by clicking on the geolocation button, we re-center the map.
1414
if (this.tracking && this.position) {
15+
// Reset firstTime so that re-enabling tracking will zoom to location
16+
console.log('[setGeolocationTracking] Resetting firstTime and calling setCenterIfInBounds')
17+
resetFirstTime()
1518
setCenterIfInBounds.call(this, this.position, dispatcher)
1619
}
1720
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,34 @@ import useUIStore from '@/store/modules/ui'
1919
*/
2020
let firstTime: boolean = true
2121

22+
/**
23+
* Resets the firstTime flag. This should be called when geolocation is deactivated
24+
* so that the next activation will zoom to the user's location.
25+
*/
26+
export function resetFirstTime(): void {
27+
firstTime = true
28+
}
29+
2230
export default function setCenterIfInBounds(
2331
this: GeolocationStore,
2432
center: SingleCoordinate,
2533
dispatcher: ActionDispatcher
2634
): void {
35+
console.log('[setCenterIfInBounds] Called with center:', center)
36+
2737
const cesiumStore = useCesiumStore()
2838
const positionStore = usePositionStore()
2939
const uiStore = useUIStore()
3040

3141
const lv95BoundsInCurrentProjection = LV95.getBoundsAs(positionStore.projection)
3242

3343
if (lv95BoundsInCurrentProjection?.isInBounds(center)) {
44+
console.log('[setCenterIfInBounds] Position in bounds, firstTime:', firstTime, 'center equals:', isEqual(positionStore.center, center))
3445
if (!isEqual(positionStore.center, center)) {
3546
positionStore.setCenter(center, dispatcher)
3647

3748
if (firstTime) {
49+
console.log('[setCenterIfInBounds] First time - setting zoom to', positionStore.projection.get1_25000ZoomLevel())
3850
firstTime = false
3951
if (cesiumStore.active && positionStore.camera) {
4052
positionStore.setCameraPosition(
@@ -51,7 +63,11 @@ export default function setCenterIfInBounds(
5163
)
5264
}
5365
positionStore.setZoom(positionStore.projection.get1_25000ZoomLevel(), dispatcher)
66+
} else {
67+
console.log('[setCenterIfInBounds] Not first time - skipping zoom')
5468
}
69+
} else {
70+
console.log('[setCenterIfInBounds] Center already equals position - skipping')
5571
}
5672
} else {
5773
log.warn({

0 commit comments

Comments
 (0)