33</template >
44
55<script setup lang="ts">
6- import { computed , type Ref } from " vue" ;
6+ import type { Ref } from " vue" ;
77import { provide , inject , watch , onMounted , onUnmounted , toRefs } from " vue" ;
88import type Collection from " ol/Collection" ;
99import Modify from " ol/interaction/Modify" ;
@@ -44,7 +44,7 @@ const {
4444 hitDetection,
4545} = toRefs (props );
4646
47- const modify = computed (() => {
47+ function createModify() {
4848 const m = new Modify ({
4949 source: source ?.value ,
5050 features: features ?.value ,
@@ -65,7 +65,9 @@ const modify = computed(() => {
6565 });
6666
6767 return m ;
68- });
68+ }
69+
70+ let modify = createModify ();
6971
7072watch (
7173 [
@@ -77,20 +79,20 @@ watch(
7779 hitDetection ,
7880 ],
7981 () => {
80- map ?. removeInteraction ( modify .value );
81- map ?.addInteraction (modify . value );
82- modify . value . changed ();
83-
82+ modify .dispose ( );
83+ map ?.removeInteraction (modify );
84+ modify = createModify ();
85+ map ?. addInteraction ( modify );
8486 map ?.changed ();
8587 }
8688);
8789
8890onMounted (() => {
89- map ?.addInteraction (modify . value );
91+ map ?.addInteraction (modify );
9092});
9193
9294onUnmounted (() => {
93- map ?.removeInteraction (modify . value );
95+ map ?.removeInteraction (modify );
9496});
9597
9698provide (" stylable" , modify );
0 commit comments