1
1
<template >
2
2
<div
3
- v-if =" CurrentActivity && state.position "
3
+ v-if =" CurrentActivity"
4
4
id =" position"
5
5
class =" row items-center no-padding k-position"
6
6
>
14
14
size =" sm"
15
15
:handler =" onCopy"
16
16
/>
17
- <KAction
17
+ <!-- KAction
18
18
id="hide-position"
19
19
icon="cancel"
20
20
tooltip="KPosition.HIDE"
21
21
size="sm"
22
22
:handler="onHide"
23
- />
23
+ /-- >
24
24
</div >
25
25
</template >
26
26
27
27
<script setup>
28
28
import _ from ' lodash'
29
- import { ref , computed , watch , onBeforeUnmount } from ' vue'
29
+ import { ref , computed , onMounted , onBeforeUnmount } from ' vue'
30
30
import { Notify , copyToClipboard } from ' quasar'
31
- import { Store , Layout , i18n , utils as kdkCoreUtils } from ' ../../../core.client'
32
- import { formatUserCoordinates } from ' ../utils'
33
- import { useCurrentActivity } from ' ../composables/activity.js'
34
- import KAction from ' ../../../core/client/components/action/KAction.vue'
31
+ import { Store , Layout , i18n } from ' ../../../../ core.client.js '
32
+ import { formatUserCoordinates } from ' ../../ utils.js '
33
+ import { useCurrentActivity } from ' ../../ composables/activity.js'
34
+ import KAction from ' ../../../../ core/client/components/action/KAction.vue'
35
35
36
36
// Props
37
37
const props = defineProps ({
38
- size : {
39
- type: Number ,
40
- default: 48
38
+ target : {
39
+ type: String ,
40
+ default: ' target '
41
41
}
42
42
})
43
43
44
44
// Data
45
- const { CurrentActivityContext , CurrentActivity } = useCurrentActivity ()
46
- const { state } = CurrentActivityContext
47
- const position = ref (state .position )
45
+ const { CurrentActivity } = useCurrentActivity ()
46
+ const position = ref (null )
48
47
49
48
// Computed
50
49
const formattedPosition = computed (() => {
51
50
if (_ .isNil (position .value )) return i18n .t (' KPositionIndicator.OUTSIDE_MAP' )
52
51
return formatUserCoordinates (position .value .latitude , position .value .longitude , Store .get (' locationFormat' , ' FFf' ))
53
52
})
54
53
55
- // Watch
56
- watch (() => state .position , () => {
57
- if (state .position ) show ()
58
- else hide ()
59
- })
60
-
61
54
// Function
62
55
function updatePosition () {
63
56
position .value = CurrentActivity .value .is2D () ? CurrentActivity .value .getCenter () : CurrentActivity .value .getCameraEllipsoidTarget ()
64
- }
65
- function show () {
66
- // Update page content with sticky target
67
- const target = {
68
- id: ' position-target' ,
69
- component: ' QImg' ,
70
- src: ' icons/kdk/target.svg' ,
71
- height: ` ${ props .size } px` ,
72
- width: ` ${ props .size } px` ,
73
- position: ' center' ,
74
- offset: [0 , - props .size / 2 ],
75
- style: ' pointer-events: none; background-color: #00000020; border-radius: 50%;'
76
- }
77
- console .log (target)
78
- kdkCoreUtils .bindContent (target, CurrentActivity .value )
79
- const stickies = Layout .getStickies ().components
80
- stickies .splice (stickies .length , 0 , target)
81
- // Listen move events
82
- CurrentActivity .value .$engineEvents .on (' movestart' , updatePosition)
83
- CurrentActivity .value .$engineEvents .on (' move' , updatePosition)
84
- CurrentActivity .value .$engineEvents .on (' moveend' , updatePosition)
85
- // Update the position
86
- updatePosition ()
87
- }
88
- function hide () {
89
- const stickies = Layout .getStickies ().components
90
- const index = _ .findIndex (stickies, component => component .id === ' position-target' )
91
- if (index >= 0 ) stickies .splice (index, 1 )
92
- // Stop listening move events
93
- CurrentActivity .value .$engineEvents .off (' movestart' , updatePosition)
94
- CurrentActivity .value .$engineEvents .off (' move' , updatePosition)
95
- CurrentActivity .value .$engineEvents .off (' moveend' , updatePosition)
57
+ console .log (position .value )
96
58
}
97
59
async function onCopy () {
98
60
try {
@@ -102,13 +64,24 @@ async function onCopy () {
102
64
Notify .create ({ type: ' negative' , message: i18n .t (' KPositionIndicator.CANNOT_COPY_POSITION' ) })
103
65
}
104
66
}
105
- function onHide () {
106
- Object .assign (state, { position: false })
107
- }
108
67
68
+ onMounted (() => {
69
+ // Show target sticky
70
+ if (props .target ) Layout .setStickyVisible (props .target , true )
71
+ // Listen move events
72
+ CurrentActivity .value .$engineEvents .on (' movestart' , updatePosition)
73
+ CurrentActivity .value .$engineEvents .on (' move' , updatePosition)
74
+ CurrentActivity .value .$engineEvents .on (' moveend' , updatePosition)
75
+ // Update the position
76
+ updatePosition ()
77
+ })
109
78
// Hooks
110
79
onBeforeUnmount (() => {
111
- if (state .position ) onHide ()
80
+ if (props .target ) Layout .setStickyVisible (props .target , false )
81
+ // Stop listening move events
82
+ CurrentActivity .value .$engineEvents .off (' movestart' , updatePosition)
83
+ CurrentActivity .value .$engineEvents .off (' move' , updatePosition)
84
+ CurrentActivity .value .$engineEvents .off (' moveend' , updatePosition)
112
85
})
113
86
</script >
114
87
0 commit comments