Skip to content

Commit f027dca

Browse files
committed
fix(ol-interaction-transform): ol-interaction-transform not working
`selection` was not set
1 parent 1c3e85c commit f027dca

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/components/interaction/OlInteractionTransform.vue

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

55
<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";
714
import Transform, {
815
type RotateEvent,
916
type ScaleEvent,
@@ -18,6 +25,7 @@ import {
1825
type CommonEvents,
1926
} from "@/composables/useOpenLayersEvents";
2027
import { always } from "ol/events/condition";
28+
import { TRUE } from "ol/functions";
2129
2230
const props = withDefaults(defineProps<Options>(), {
2331
translateFeature: true,
@@ -26,6 +34,7 @@ const props = withDefaults(defineProps<Options>(), {
2634
keepAspectRatio: always,
2735
translate: true,
2836
stretch: true,
37+
selection: TRUE,
2938
});
3039
3140
type Emits = CommonEvents & {
@@ -51,9 +60,13 @@ const map = inject<Map>("map");
5160
5261
const properties = usePropsAsObjectProperties(props);
5362
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());
5568
56-
useOpenLayersEvents(transform, [
69+
const { updateOpenLayersEventHandlers } = useOpenLayersEvents(transform, [
5770
"select",
5871
"rotatestart",
5972
"rotating",
@@ -68,8 +81,9 @@ useOpenLayersEvents(transform, [
6881
6982
watch(transform, (newVal, oldVal) => {
7083
map?.removeInteraction(oldVal);
84+
transform.value = createTransform();
85+
updateOpenLayersEventHandlers();
7186
map?.addInteraction(newVal);
72-
7387
map?.changed();
7488
});
7589
@@ -84,6 +98,6 @@ onUnmounted(() => {
8498
provide("stylable", transform);
8599
86100
defineExpose({
87-
transform,
101+
transform: transform.value,
88102
});
89103
</script>

0 commit comments

Comments
 (0)