Skip to content

Commit e5b9612

Browse files
committed
refactor(ol-interaction-dragrotatezoom): migrate to script setup
1 parent d37f923 commit e5b9612

File tree

5 files changed

+61
-87
lines changed

5 files changed

+61
-87
lines changed

docs/componentsguide/interactions/dragrotatezoom/index.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,12 @@ import DragRotateZoomDemo from "@demos/DragRotateZoomDemo.vue"
3434
</ol-map>
3535
</template>
3636
37-
<script>
37+
<script setup>
3838
import { ref } from "vue";
39-
export default {
40-
setup() {
41-
const center = ref([-102.13121, 40.2436]);
42-
const projection = ref("EPSG:4326");
43-
const zoom = ref(5);
4439
45-
return {
46-
center,
47-
projection,
48-
zoom,
49-
};
50-
},
51-
};
40+
const center = ref([-102.13121, 40.2436]);
41+
const projection = ref("EPSG:4326");
42+
const zoom = ref(5);
5243
</script>
5344
```
5445

src/components/interaction/DragRotateAndZoomInteraction.vue

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template lang="">
2+
<slot> </slot>
3+
</template>
4+
5+
<script setup>
6+
import { inject, watch, onMounted, onUnmounted, computed } from "vue";
7+
8+
import DragRotateAndZoom from "ol/interaction/DragRotateAndZoom";
9+
10+
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties";
11+
12+
const props = defineProps({
13+
condition: {
14+
type: Function,
15+
},
16+
duration: {
17+
type: Number,
18+
default: 400,
19+
},
20+
});
21+
22+
const map = inject("map");
23+
24+
const { properties } = usePropsAsObjectProperties(props);
25+
26+
const dragrotatezoom = computed(() => {
27+
const s = new DragRotateAndZoom({
28+
...properties,
29+
});
30+
31+
return s;
32+
});
33+
34+
watch(dragrotatezoom, (newVal, oldVal) => {
35+
map.removeInteraction(oldVal);
36+
map.addInteraction(newVal);
37+
38+
map.changed();
39+
});
40+
41+
onMounted(() => {
42+
map.addInteraction(dragrotatezoom.value);
43+
});
44+
45+
onUnmounted(() => {
46+
map.removeInteraction(dragrotatezoom.value);
47+
});
48+
</script>
49+
50+
<style lang=""></style>
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import OlClusterSelectInteraction from "./OlClusterSelectInteraction.vue";
22
import OlDragRotateInteraction from "./OlDragRotateInteraction.vue";
3+
import OlDragRotateZoomInteraction from "./OlDragRotateZoomInteraction.vue";
34
import SelectInteraction from "./SelectInteraction.vue";
45
import DrawInteraction from "./DrawInteraction.vue";
56
import SnapInteraction from "./SnapInteraction.vue";
67
import ModifyInteraction from "./ModifyInteraction.vue";
78
import TransformInteraction from "./TransformInteraction.vue";
8-
import DragRotateAndZoomInteraction from "./DragRotateAndZoomInteraction.vue";
99

1010
function install(app) {
1111
if (install.installed) {
@@ -16,15 +16,12 @@ function install(app) {
1616

1717
app.component("ol-interaction-clusterselect", OlClusterSelectInteraction);
1818
app.component("ol-interaction-dragrotate", OlDragRotateInteraction);
19+
app.component("ol-interaction-dragrotatezoom", OlDragRotateZoomInteraction);
1920
app.component(SelectInteraction.name, SelectInteraction);
2021
app.component(DrawInteraction.name, DrawInteraction);
2122
app.component(SnapInteraction.name, SnapInteraction);
2223
app.component(ModifyInteraction.name, ModifyInteraction);
2324
app.component(TransformInteraction.name, TransformInteraction);
24-
app.component(
25-
DragRotateAndZoomInteraction.name,
26-
DragRotateAndZoomInteraction
27-
);
2825
}
2926

3027
export default install;
@@ -33,10 +30,10 @@ export {
3330
install,
3431
OlClusterSelectInteraction,
3532
OlDragRotateInteraction,
33+
OlDragRotateZoomInteraction,
3634
SelectInteraction,
3735
DrawInteraction,
3836
SnapInteraction,
3937
ModifyInteraction,
4038
TransformInteraction,
41-
DragRotateAndZoomInteraction,
4239
};

src/demos/DragRotateZoomDemo.vue

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,10 @@
1919
</ol-map>
2020
</template>
2121

22-
<script>
22+
<script setup>
2323
import { ref } from "vue";
24-
export default {
25-
setup() {
26-
const center = ref([-102.13121, 40.2436]);
27-
const projection = ref("EPSG:4326");
28-
const zoom = ref(5);
2924
30-
return {
31-
center,
32-
projection,
33-
zoom,
34-
};
35-
},
36-
};
25+
const center = ref([-102.13121, 40.2436]);
26+
const projection = ref("EPSG:4326");
27+
const zoom = ref(5);
3728
</script>

0 commit comments

Comments
 (0)