Skip to content

Commit 6aa8823

Browse files
committed
refactor(ol-interaction-transform): migrate to script setup
1 parent 919a2c4 commit 6aa8823

File tree

12 files changed

+208
-250
lines changed

12 files changed

+208
-250
lines changed

docs/componentsguide/interactions/transform/index.md

Lines changed: 56 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -53,86 +53,67 @@ import TransformDemo from "@demos/TransformDemo.vue"
5353
</ol-map>
5454
</template>
5555
56-
<script>
56+
<script setup>
5757
import { ref } from "vue";
5858
import { GeoJSON } from "ol/format";
5959
60-
export default {
61-
setup() {
62-
const map = ref("");
63-
const center = ref([-102.13121, 40.2436]);
64-
const projection = ref("EPSG:4326");
65-
const zoom = ref(5);
66-
const rotation = ref(0);
67-
68-
const drawEnabled = ref(false);
69-
70-
const geojsonObject = {
71-
type: "FeatureCollection",
72-
crs: {
73-
type: "name",
74-
properties: {
75-
name: "EPSG:4326",
76-
},
77-
},
78-
features: [
79-
{
80-
type: "Feature",
81-
geometry: {
82-
type: "Polygon",
83-
coordinates: [
84-
[
85-
[-103.86923852630616, 43.45599322423934],
86-
[-103.90891107984544, 39.34240191087722],
87-
[-98.76630637117387, 39.558687199211114],
88-
[-98.89435771175386, 43.945405844902986],
89-
[-103.86923852630616, 43.45599322423934],
90-
],
91-
],
92-
},
93-
},
94-
{
95-
type: "Feature",
96-
geometry: {
97-
type: "Polygon",
98-
coordinates: [
99-
[
100-
[-103.85636392303468, 38.10970692739486],
101-
[-103.86770698495866, 33.218572724914544],
102-
[-98.20654544301988, 33.6532810221672],
103-
[-98.4408283538437, 38.31894739375114],
104-
[-103.85636392303468, 38.10970692739486],
105-
],
106-
],
107-
},
108-
},
109-
],
110-
};
111-
112-
const zones = ref([]);
113-
114-
const drawend = (event) => {
115-
zones.value.push(event.feature);
116-
drawEnabled.value = false;
117-
};
118-
119-
zones.value = new GeoJSON().readFeatures(geojsonObject);
120-
121-
const geoJsonFormat = new GeoJSON();
122-
123-
return {
124-
map,
125-
geoJsonFormat,
126-
zones,
127-
center,
128-
projection,
129-
zoom,
130-
rotation,
131-
drawEnabled,
132-
drawend,
133-
};
60+
const map = ref("");
61+
const center = ref([-102.13121, 40.2436]);
62+
const projection = ref("EPSG:4326");
63+
const zoom = ref(5);
64+
const rotation = ref(0);
65+
const drawEnabled = ref(false);
66+
67+
const geojsonObject = {
68+
type: "FeatureCollection",
69+
crs: {
70+
type: "name",
71+
properties: {
72+
name: "EPSG:4326",
73+
},
13474
},
75+
features: [
76+
{
77+
type: "Feature",
78+
geometry: {
79+
type: "Polygon",
80+
coordinates: [
81+
[
82+
[-103.86923852630616, 43.45599322423934],
83+
[-103.90891107984544, 39.34240191087722],
84+
[-98.76630637117387, 39.558687199211114],
85+
[-98.89435771175386, 43.945405844902986],
86+
[-103.86923852630616, 43.45599322423934],
87+
],
88+
],
89+
},
90+
},
91+
{
92+
type: "Feature",
93+
geometry: {
94+
type: "Polygon",
95+
coordinates: [
96+
[
97+
[-103.85636392303468, 38.10970692739486],
98+
[-103.86770698495866, 33.218572724914544],
99+
[-98.20654544301988, 33.6532810221672],
100+
[-98.4408283538437, 38.31894739375114],
101+
[-103.85636392303468, 38.10970692739486],
102+
],
103+
],
104+
},
105+
},
106+
],
135107
};
108+
109+
const zones = ref([]);
110+
111+
const drawend = (event) => {
112+
zones.value.push(event.feature);
113+
drawEnabled.value = false;
114+
};
115+
116+
zones.value = new GeoJSON().readFeatures(geojsonObject);
136117
</script>
137118
```
138119

src/components/interaction/OlClusterSelectInteraction.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="">
2-
<slot> </slot>
2+
<slot></slot>
33
</template>
44

55
<script setup>

src/components/interaction/OlDragRotateInteraction.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="">
2-
<slot> </slot>
2+
<slot></slot>
33
</template>
44

55
<script setup>

src/components/interaction/OlDragRotateZoomInteraction.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="">
2-
<slot> </slot>
2+
<slot></slot>
33
</template>
44

55
<script setup>

src/components/interaction/OlDrawInteraction.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="">
2-
<slot> </slot>
2+
<slot></slot>
33
</template>
44

55
<script setup>

src/components/interaction/OlModifyInteraction.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="">
2-
<slot> </slot>
2+
<slot></slot>
33
</template>
44

55
<script setup>

src/components/interaction/OlSelectInteraction.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="">
2-
<slot> </slot>
2+
<slot></slot>
33
</template>
44

55
<script setup>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<template lang="">
2+
<slot></slot>
3+
</template>
4+
5+
<script setup>
6+
import { provide, inject, watch, onMounted, onUnmounted, computed } from "vue";
7+
8+
import Transform from "ol-ext/interaction/Transform";
9+
10+
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties";
11+
12+
const props = defineProps({
13+
enableRotatedTransform: {
14+
type: Boolean,
15+
default: false,
16+
},
17+
condition: {
18+
type: Function,
19+
},
20+
addCondition: {
21+
type: Function,
22+
},
23+
filter: {
24+
type: Function,
25+
},
26+
layers: {
27+
type: Array,
28+
},
29+
hitTolerance: {
30+
type: Number,
31+
default: 2,
32+
},
33+
translateFeature: {
34+
type: Boolean,
35+
default: true,
36+
},
37+
scale: {
38+
type: Boolean,
39+
default: true,
40+
},
41+
rotate: {
42+
type: Boolean,
43+
default: true,
44+
},
45+
keepAspectRatio: {
46+
type: Boolean,
47+
default: false,
48+
},
49+
translate: {
50+
type: Boolean,
51+
default: true,
52+
},
53+
stretch: {
54+
type: Boolean,
55+
default: true,
56+
},
57+
});
58+
59+
const map = inject("map");
60+
61+
const { properties } = usePropsAsObjectProperties(props);
62+
63+
const transform = computed(() => {
64+
const interaction = new Transform({
65+
...properties,
66+
});
67+
68+
return interaction;
69+
});
70+
71+
watch(transform, (newVal, oldVal) => {
72+
map.removeInteraction(oldVal);
73+
map.addInteraction(newVal);
74+
75+
map.changed();
76+
});
77+
78+
onMounted(() => {
79+
map.addInteraction(transform.value);
80+
});
81+
82+
onUnmounted(() => {
83+
map.removeInteraction(transform.value);
84+
});
85+
86+
provide("stylable", transform);
87+
</script>
88+
89+
<style lang=""></style>

src/components/interaction/TransformInteraction.vue

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/components/interaction/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import OlSelectInteraction from "./OlSelectInteraction.vue";
55
import OlDrawInteraction from "./OlDrawInteraction.vue";
66
import OlModifyInteraction from "./OlModifyInteraction.vue";
77
import OlSnapInteraction from "./OlSnapInteraction.vue";
8-
import TransformInteraction from "./TransformInteraction.vue";
8+
import OlTransformInteraction from "./OlTransformInteraction.vue";
99

1010
function install(app) {
1111
if (install.installed) {
@@ -21,7 +21,7 @@ function install(app) {
2121
app.component("ol-interaction-draw", OlDrawInteraction);
2222
app.component("ol-interaction-modify", OlModifyInteraction);
2323
app.component("ol-interaction-snap", OlSnapInteraction);
24-
app.component(TransformInteraction.name, TransformInteraction);
24+
app.component("ol-interaction-transform", OlTransformInteraction);
2525
}
2626

2727
export default install;
@@ -35,5 +35,5 @@ export {
3535
OlDrawInteraction,
3636
OlModifyInteraction,
3737
OlSnapInteraction,
38-
TransformInteraction,
38+
OlTransformInteraction,
3939
};

0 commit comments

Comments
 (0)