33</template >
44
55<script setup lang="ts">
6- import type { Ref } from " vue" ;
76import {
8- provide ,
97 inject ,
10- watch ,
118 onMounted ,
129 onUnmounted ,
10+ provide ,
11+ type Ref ,
12+ shallowRef ,
1313 toRefs ,
14- ref ,
14+ watch ,
1515} from " vue" ;
16+ import type { GeometryFunction } from " ol/interaction/Draw" ;
1617import Draw from " ol/interaction/Draw" ;
1718import type Map from " ol/Map" ;
1819import type VectorSource from " ol/source/Vector" ;
1920import type { Type as GeometryType } from " ol/geom/Geometry" ;
20- import type { GeometryFunction } from " ol/interaction/Draw" ;
2121import type { Condition } from " ol/events/condition" ;
2222import { useOpenLayersEvents } from " @/composables/useOpenLayersEvents" ;
2323
@@ -93,9 +93,12 @@ function createDraw() {
9393 });
9494}
9595
96- let draw = createDraw ();
96+ const draw = shallowRef ( createDraw () );
9797
98- useOpenLayersEvents (draw , [" drawstart" , " drawend" ]);
98+ const { updateOpenLayersEventHandlers } = useOpenLayersEvents (draw , [
99+ " drawstart" ,
100+ " drawend" ,
101+ ]);
99102
100103watch (
101104 [
@@ -115,25 +118,26 @@ watch(
115118 wrapX ,
116119 ],
117120 () => {
118- draw .abortDrawing ();
119- map ?.removeInteraction (draw );
120- draw = createDraw ();
121- map ?.addInteraction (draw );
121+ draw .value .abortDrawing ();
122+ map ?.removeInteraction (draw .value );
123+ draw .value = createDraw ();
124+ updateOpenLayersEventHandlers ();
125+ map ?.addInteraction (draw .value );
122126 map ?.changed ();
123127 },
124128);
125129
126130onMounted (() => {
127- map ?.addInteraction (draw );
131+ map ?.addInteraction (draw . value );
128132});
129133
130134onUnmounted (() => {
131- map ?.removeInteraction (draw );
135+ map ?.removeInteraction (draw . value );
132136});
133137
134- provide (" stylable" , ref ( draw ) );
138+ provide (" stylable" , draw );
135139
136140defineExpose ({
137- draw ,
141+ draw: draw . value ,
138142});
139143 </script >
0 commit comments