Skip to content

Commit 4d7c408

Browse files
committed
fix(ol-interaction-modify): don't re-compute modify interaction
1 parent 37cd6c5 commit 4d7c408

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/components/interaction/OlModifyInteraction.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
</template>
44

55
<script setup lang="ts">
6-
import { computed, type Ref } from "vue";
6+
import type { Ref } from "vue";
77
import { provide, inject, watch, onMounted, onUnmounted, toRefs } from "vue";
88
import type Collection from "ol/Collection";
99
import 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
7072
watch(
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
8890
onMounted(() => {
89-
map?.addInteraction(modify.value);
91+
map?.addInteraction(modify);
9092
});
9193
9294
onUnmounted(() => {
93-
map?.removeInteraction(modify.value);
95+
map?.removeInteraction(modify);
9496
});
9597
9698
provide("stylable", modify);

0 commit comments

Comments
 (0)