3
3
</template >
4
4
5
5
<script setup lang="ts">
6
- import { provide , inject , watch , onMounted , onUnmounted , computed } from " vue" ;
6
+ import {
7
+ provide ,
8
+ inject ,
9
+ watch ,
10
+ onMounted ,
11
+ onUnmounted ,
12
+ shallowRef ,
13
+ } from " vue" ;
7
14
import Transform , {
8
15
type RotateEvent ,
9
16
type ScaleEvent ,
@@ -18,6 +25,7 @@ import {
18
25
type CommonEvents ,
19
26
} from " @/composables/useOpenLayersEvents" ;
20
27
import { always } from " ol/events/condition" ;
28
+ import { TRUE } from " ol/functions" ;
21
29
22
30
const props = withDefaults (defineProps <Options >(), {
23
31
translateFeature: true ,
@@ -26,6 +34,7 @@ const props = withDefaults(defineProps<Options>(), {
26
34
keepAspectRatio: always ,
27
35
translate: true ,
28
36
stretch: true ,
37
+ selection: TRUE ,
29
38
});
30
39
31
40
type Emits = CommonEvents & {
@@ -51,9 +60,13 @@ const map = inject<Map>("map");
51
60
52
61
const properties = usePropsAsObjectProperties (props );
53
62
54
- const transform = computed (() => new Transform (properties as Options ));
63
+ function createTransform() {
64
+ return new Transform (properties as Options );
65
+ }
66
+
67
+ const transform = shallowRef (createTransform ());
55
68
56
- useOpenLayersEvents (transform , [
69
+ const { updateOpenLayersEventHandlers } = useOpenLayersEvents (transform , [
57
70
" select" ,
58
71
" rotatestart" ,
59
72
" rotating" ,
@@ -68,8 +81,9 @@ useOpenLayersEvents(transform, [
68
81
69
82
watch (transform , (newVal , oldVal ) => {
70
83
map ?.removeInteraction (oldVal );
84
+ transform .value = createTransform ();
85
+ updateOpenLayersEventHandlers ();
71
86
map ?.addInteraction (newVal );
72
-
73
87
map ?.changed ();
74
88
});
75
89
@@ -84,6 +98,6 @@ onUnmounted(() => {
84
98
provide (" stylable" , transform );
85
99
86
100
defineExpose ({
87
- transform ,
101
+ transform: transform . value ,
88
102
});
89
103
</script >
0 commit comments