Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSLUX-769: FIX for profile measures in v3 #177

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/bundle/components/profile_v3/profile-measures_v3.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<script setup lang="ts">
import { computed } from 'vue'
import { storeToRefs } from 'pinia'

import FeatureElevationProfile from '@/components/feature-elevation-profile/feature-elevation-profile.vue'
import { useProfileMeasuresv3Store } from '../../stores/profile-measures_v3.store'

const profilev3Store = useProfileMeasuresv3Store()
const { closeEvent_v3, feature_v3 } = storeToRefs(profilev3Store)
const activateProfile = computed(
() =>
feature_v3.value &&
feature_v3.value.getGeometry()?.getType() === 'LineString'
)

function onClose() {
closeEvent_v3.value = Date.now()
feature_v3.value = undefined // Reset profile data and graph when closing profile measures
}

/**
* This component is a wrapper to use original <feature-elevation-profile> in v3
Expand All @@ -21,9 +20,5 @@ const activateProfile = computed(
</script>

<template>
<feature-elevation-profile
v-if="activateProfile"
:feature="feature_v3"
@close="() => (closeEvent_v3 = Date.now())"
/>
<feature-elevation-profile :feature="feature_v3" @close="onClose" />
</template>
4 changes: 2 additions & 2 deletions src/bundle/stores/profile-draw_v3.store.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -22,7 +22,7 @@ export const useProfileDrawv3Store = defineStore(

function setProfileData(
map: Map,
feature: Feature & DrawnFeature,
feature: DrawnFeature,
profileData: ProfileData
) {
feature_v3.value = undefined
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/stores/profile-measures_v3.store.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -28,7 +28,7 @@ export const useProfileMeasuresv3Store = defineStore(

function setProfileData(
map: Map,
feature: Feature & DrawnFeature,
feature: DrawnFeature,
profileData: ProfileData
) {
feature_v3.value = undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})

Expand Down
16 changes: 8 additions & 8 deletions src/composables/map/profile-position.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -51,14 +51,17 @@ 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

onMounted(() => {
map = useMap().getOlMap()
createLayerFeaturePosition()
attachPointerMove()
})

onUnmounted(() => detachPointerMove())

watch(
Expand All @@ -75,7 +78,6 @@ export default function useProfilePosition(
watch(profileData, profileData => {
if (profileData) {
constructProfileLine(profileData)
attachPointerMove()
}
})

Expand Down Expand Up @@ -130,20 +132,18 @@ export default function useProfilePosition(
*/
function attachPointerMove() {
if (listenerIdPointerMove === undefined) {
listenerIdPointerMove = listen(
map,
'pointermove',
<ListenerFunction>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()
}
}
Expand Down
Loading