Skip to content

Commit 7a2f58f

Browse files
committed
refactor(ol-style-circle): migrate to script setup
1 parent e3e83ef commit 7a2f58f

File tree

4 files changed

+74
-88
lines changed

4 files changed

+74
-88
lines changed

docs/componentsguide/styles/circle/index.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Styling a feature inside a vector layer.
2121
<ol-map
2222
:loadTilesWhileAnimating="true"
2323
:loadTilesWhileInteracting="true"
24-
style="height:400px"
24+
style="height: 400px"
2525
>
2626
<ol-view
2727
ref="view"
@@ -51,23 +51,13 @@ Styling a feature inside a vector layer.
5151
</ol-map>
5252
</template>
5353
54-
<script>
54+
<script setup>
5555
import { ref } from "vue";
56-
export default {
57-
setup() {
58-
const center = ref([40, 40]);
59-
const projection = ref("EPSG:4326");
60-
const zoom = ref(8);
61-
const rotation = ref(0);
62-
63-
return {
64-
center,
65-
projection,
66-
zoom,
67-
rotation,
68-
};
69-
},
70-
};
56+
57+
const center = ref([40, 40]);
58+
const projection = ref("EPSG:4326");
59+
const zoom = ref(8);
60+
const rotation = ref(0);
7161
</script>
7262
```
7363

src/components/styles/Circle.vue

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<template>
2+
<div>
3+
<slot></slot>
4+
</div>
5+
</template>
6+
7+
<script setup>
8+
import CircleStyle from "ol/style/Circle";
9+
import Fill from "ol/style/Fill";
10+
import Stroke from "ol/style/Stroke";
11+
12+
import { inject, watch, onMounted, onUnmounted, provide, computed } from "vue";
13+
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties";
14+
15+
const props = defineProps({
16+
radius: {
17+
type: Number,
18+
},
19+
scale: {
20+
type: Number,
21+
},
22+
});
23+
24+
const style = inject("style", null);
25+
const styledObj = inject("styledObj", null);
26+
27+
const { properties } = usePropsAsObjectProperties(props);
28+
29+
const createCircleStyle = (properties) => {
30+
return new CircleStyle({
31+
...properties,
32+
fill: new Fill(),
33+
stroke: new Stroke(),
34+
});
35+
};
36+
37+
const circle = computed(() => createCircleStyle(properties));
38+
39+
const applyStyle = () => {
40+
style.value.setImage(null);
41+
style.value.setImage(circle.value);
42+
styledObj.value.changed();
43+
};
44+
watch(properties, () => {
45+
applyStyle();
46+
});
47+
48+
watch(style, () => {
49+
applyStyle();
50+
});
51+
52+
onMounted(() => {
53+
style.value.setImage(circle.value);
54+
});
55+
56+
onUnmounted(() => {
57+
style.value.setImage(null);
58+
});
59+
60+
provide("circle", circle);
61+
provide("styledObj", styledObj);
62+
</script>
63+
64+
<style lang=""></style>

src/components/styles/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import OlStyle from "./OlStyle.vue";
2-
import Circle from "./Circle.vue";
2+
import OlStyleCircle from "./OlStyleCircle.vue";
33
import Stroke from "./Stroke.vue";
44
import Fill from "./Fill.vue";
55
import Icon from "./Icon.vue";
@@ -14,7 +14,7 @@ function install(app) {
1414
install.installed = true;
1515

1616
app.component("ol-style", OlStyle);
17-
app.component(Circle.name, Circle);
17+
app.component("ol-style-circle", OlStyleCircle);
1818
app.component(Stroke.name, Stroke);
1919
app.component(Fill.name, Fill);
2020
app.component(Icon.name, Icon);
@@ -32,5 +32,5 @@ export {
3232
Icon,
3333
Text,
3434
FlowLine,
35-
Circle,
35+
OlStyleCircle,
3636
};

0 commit comments

Comments
 (0)