From 80ac6dbb8ca1c95035d0468213f42cd1d0276eb3 Mon Sep 17 00:00:00 2001 From: AlitaBernachot Date: Tue, 3 Dec 2024 10:41:18 +0100 Subject: [PATCH 1/2] fix: profile measures for v3 --- .../components/profile_v3/profile-draw_v3.vue | 4 +++- .../profile_v3/profile-measures_v3.vue | 17 ++++++----------- src/bundle/stores/profile-draw_v3.store.ts | 4 ++-- src/bundle/stores/profile-measures_v3.store.ts | 4 ++-- .../feature-elevation-profile.vue | 2 ++ .../map/profile-position.composable.ts | 16 ++++++++-------- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/bundle/components/profile_v3/profile-draw_v3.vue b/src/bundle/components/profile_v3/profile-draw_v3.vue index 3cfd11cf..d63db6da 100644 --- a/src/bundle/components/profile_v3/profile-draw_v3.vue +++ b/src/bundle/components/profile_v3/profile-draw_v3.vue @@ -21,5 +21,7 @@ const activateProfile = computed( diff --git a/src/bundle/components/profile_v3/profile-measures_v3.vue b/src/bundle/components/profile_v3/profile-measures_v3.vue index de368835..8b790c86 100644 --- a/src/bundle/components/profile_v3/profile-measures_v3.vue +++ b/src/bundle/components/profile_v3/profile-measures_v3.vue @@ -1,5 +1,4 @@ diff --git a/src/bundle/stores/profile-draw_v3.store.ts b/src/bundle/stores/profile-draw_v3.store.ts index 2c362fa5..40a5c084 100644 --- a/src/bundle/stores/profile-draw_v3.store.ts +++ b/src/bundle/stores/profile-draw_v3.store.ts @@ -1,6 +1,6 @@ import { Ref, ref } from 'vue' import { acceptHMRUpdate, defineStore } from 'pinia' -import { Feature, Map } from 'ol' +import { Map } from 'ol' import { DrawnFeature } from '@/services/draw/drawn-feature' import { ProfileData } from '@/components/common/graph/elevation-profile' @@ -22,7 +22,7 @@ export const useProfileDrawv3Store = defineStore( function setProfileData( map: Map, - feature: Feature & DrawnFeature, + feature: DrawnFeature, profileData: ProfileData ) { feature_v3.value = undefined diff --git a/src/bundle/stores/profile-measures_v3.store.ts b/src/bundle/stores/profile-measures_v3.store.ts index 9c2ffa06..8a9f5d19 100644 --- a/src/bundle/stores/profile-measures_v3.store.ts +++ b/src/bundle/stores/profile-measures_v3.store.ts @@ -1,6 +1,6 @@ import { Ref, ref } from 'vue' import { acceptHMRUpdate, defineStore } from 'pinia' -import { Feature, Map } from 'ol' +import { Map } from 'ol' import { DrawnFeature } from '@/services/draw/drawn-feature' import { ProfileData } from '@/components/common/graph/elevation-profile' @@ -28,7 +28,7 @@ export const useProfileMeasuresv3Store = defineStore( function setProfileData( map: Map, - feature: Feature & DrawnFeature, + feature: DrawnFeature, profileData: ProfileData ) { feature_v3.value = undefined diff --git a/src/components/feature-elevation-profile/feature-elevation-profile.vue b/src/components/feature-elevation-profile/feature-elevation-profile.vue index ca5284eb..9fd4a6fd 100644 --- a/src/components/feature-elevation-profile/feature-elevation-profile.vue +++ b/src/components/feature-elevation-profile/feature-elevation-profile.vue @@ -84,6 +84,8 @@ watchEffect(() => { if (props.feature && !props.feature.profileData) { profileData.value = undefined // Force refresh the graph props.feature?.getProfile().then(data => (profileData.value = data)) + } else { + profileData.value = undefined } }) diff --git a/src/composables/map/profile-position.composable.ts b/src/composables/map/profile-position.composable.ts index 31336f0f..90b8d9ec 100644 --- a/src/composables/map/profile-position.composable.ts +++ b/src/composables/map/profile-position.composable.ts @@ -10,7 +10,7 @@ import { } from 'vue' import { storeToRefs } from 'pinia' import { Map, MapBrowserEvent } from 'ol' -import { EventsKey, listen, ListenerFunction, unlistenByKey } from 'ol/events' +import { EventsKey, listen, unlistenByKey } from 'ol/events' import { LineString, Point } from 'ol/geom' import GeometryLayout from 'ol/geom/GeometryLayout' import { transform } from 'ol/proj' @@ -51,6 +51,7 @@ export default function useProfilePosition( const displayGeoMarker = ref(true) // deactivate geomarker when mode edition const virtualLineProfile = new LineString([0, 0], GeometryLayout.XYM) // don't add to the map, it is used to compute the distance between the user cursor and the feature (represented by the virtual line) const activePositioning = ref(true) + const throttledPointerMove = throttle(evt => onPointerMove(evt), 15) // Keep fn def as const for unlisten let map: Map let listenerIdPointerMove: EventsKey | undefined @@ -58,7 +59,9 @@ export default function useProfilePosition( onMounted(() => { map = useMap().getOlMap() createLayerFeaturePosition() + attachPointerMove() }) + onUnmounted(() => detachPointerMove()) watch( @@ -75,7 +78,6 @@ export default function useProfilePosition( watch(profileData, profileData => { if (profileData) { constructProfileLine(profileData) - attachPointerMove() } }) @@ -130,20 +132,18 @@ export default function useProfilePosition( */ function attachPointerMove() { if (listenerIdPointerMove === undefined) { - listenerIdPointerMove = listen( - map, - 'pointermove', - throttle(evt => onPointerMove(evt), 20) - ) + listenerIdPointerMove = listen(map, 'pointermove', throttledPointerMove) } } /** - * Unlisten 'pointermove' event on map + * Unlisten 'pointermove' event on map and remove geomarker */ function detachPointerMove() { if (listenerIdPointerMove) { unlistenByKey(listenerIdPointerMove) + listenerIdPointerMove = undefined + overlay?.removeGeoMarker() } } From 549f5acd05bf50834da6e04e46e41cff99d03454 Mon Sep 17 00:00:00 2001 From: AlitaBernachot Date: Wed, 4 Dec 2024 17:49:55 +0100 Subject: [PATCH 2/2] refactor: remove useless ref element --- src/bundle/components/profile_v3/profile-draw_v3.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bundle/components/profile_v3/profile-draw_v3.vue b/src/bundle/components/profile_v3/profile-draw_v3.vue index d63db6da..3cfd11cf 100644 --- a/src/bundle/components/profile_v3/profile-draw_v3.vue +++ b/src/bundle/components/profile_v3/profile-draw_v3.vue @@ -21,7 +21,5 @@ const activateProfile = computed(