Skip to content

Commit d37f923

Browse files
committed
refactor(ol-interaction-dragrotate): migrate to script setup
1 parent 8c241ff commit d37f923

File tree

5 files changed

+61
-81
lines changed

5 files changed

+61
-81
lines changed

docs/componentsguide/interactions/dragrotate/index.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,12 @@ import DragRotateDemo from "@demos/DragRotateDemo.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/DragRotateInteraction.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 DragRotate from "ol/interaction/DragRotate";
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: 250,
19+
},
20+
});
21+
22+
const map = inject("map");
23+
24+
const { properties } = usePropsAsObjectProperties(props);
25+
26+
const dragrotate = computed(() => {
27+
const s = new DragRotate({
28+
...properties,
29+
});
30+
31+
return s;
32+
});
33+
34+
watch(dragrotate, (newVal, oldVal) => {
35+
map.removeInteraction(oldVal);
36+
map.addInteraction(newVal);
37+
38+
map.changed();
39+
});
40+
41+
onMounted(() => {
42+
map.addInteraction(dragrotate.value);
43+
});
44+
45+
onUnmounted(() => {
46+
map.removeInteraction(dragrotate.value);
47+
});
48+
</script>
49+
50+
<style lang=""></style>

src/components/interaction/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import OlClusterSelectInteraction from "./OlClusterSelectInteraction.vue";
2+
import OlDragRotateInteraction from "./OlDragRotateInteraction.vue";
23
import SelectInteraction from "./SelectInteraction.vue";
34
import DrawInteraction from "./DrawInteraction.vue";
45
import SnapInteraction from "./SnapInteraction.vue";
@@ -14,6 +15,7 @@ function install(app) {
1415
install.installed = true;
1516

1617
app.component("ol-interaction-clusterselect", OlClusterSelectInteraction);
18+
app.component("ol-interaction-dragrotate", OlDragRotateInteraction);
1719
app.component(SelectInteraction.name, SelectInteraction);
1820
app.component(DrawInteraction.name, DrawInteraction);
1921
app.component(SnapInteraction.name, SnapInteraction);
@@ -30,6 +32,7 @@ export default install;
3032
export {
3133
install,
3234
OlClusterSelectInteraction,
35+
OlDragRotateInteraction,
3336
SelectInteraction,
3437
DrawInteraction,
3538
SnapInteraction,

src/demos/DragRotateDemo.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)