Skip to content

Commit 903f345

Browse files
committed
refactor(ol-style-flowline): migrate to script setup
1 parent c0a22c3 commit 903f345

File tree

3 files changed

+98
-102
lines changed

3 files changed

+98
-102
lines changed

src/components/styles/FlowLine.vue

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<template>
2+
<div>
3+
<slot></slot>
4+
</div>
5+
</template>
6+
7+
<script setup>
8+
import { inject, watch, onUnmounted, onMounted, computed } from "vue";
9+
10+
import FlowLine from "ol-ext/style/FlowLine";
11+
import Draw from "ol/interaction/Draw";
12+
import Modify from "ol/interaction/Modify";
13+
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties";
14+
15+
const props = defineProps({
16+
color: {
17+
type: [String, Function],
18+
},
19+
color2: {
20+
type: String,
21+
},
22+
width: {
23+
type: [Number, Function],
24+
},
25+
width2: {
26+
type: Number,
27+
},
28+
arrow: {
29+
type: Number,
30+
},
31+
arrowColor: {
32+
type: String,
33+
},
34+
});
35+
36+
const styledObj = inject("stylable", null);
37+
38+
const { properties } = usePropsAsObjectProperties(props);
39+
40+
const style = computed(() => new FlowLine(properties));
41+
42+
const setStyle = (val) => {
43+
if (styledObj instanceof Draw || styledObj instanceof Modify) {
44+
styledObj.getOverlay().setStyle(val);
45+
styledObj.value.dispatchEvent("styleChanged");
46+
return;
47+
}
48+
try {
49+
styledObj.value.setStyle(val);
50+
styledObj.value.changed();
51+
styledObj.value.dispatchEvent("styleChanged");
52+
} catch (error) {
53+
styledObj.value.style_ = val;
54+
styledObj.value.values_.style = val;
55+
56+
styledObj.value.changed();
57+
styledObj.value.dispatchEvent("styleChanged");
58+
}
59+
};
60+
61+
const styleFunc = computed(() => {
62+
return (feature) => {
63+
if (properties.overrideStyleFunction != null) {
64+
properties.overrideStyleFunction(feature, style.value);
65+
}
66+
return style.value;
67+
};
68+
});
69+
70+
watch(properties, () => {
71+
if (properties.overrideStyleFunction == null) {
72+
setStyle(style.value);
73+
} else {
74+
setStyle(styleFunc.value);
75+
}
76+
});
77+
78+
onMounted(() => {
79+
if (properties.overrideStyleFunction == null) {
80+
setStyle(style.value);
81+
} else {
82+
setStyle(styleFunc.value);
83+
}
84+
});
85+
86+
onUnmounted(() => {
87+
setStyle(null);
88+
});
89+
90+
defineExpose({
91+
style,
92+
});
93+
</script>
94+
95+
<style lang=""></style>

src/components/styles/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import OlStyleStroke from "./OlStyleStroke.vue";
44
import OlStyleFill from "./OlStyleFill.vue";
55
import OlStyleIcon from "./OlStyleIcon.vue";
66
import OlStyleText from "./OlStyleText.vue";
7-
import FlowLine from "./FlowLine.vue";
7+
import OlStyleFlowline from "./OlStyleFlowline.vue";
88

99
function install(app) {
1010
if (install.installed) {
@@ -19,7 +19,7 @@ function install(app) {
1919
app.component("ol-style-fill", OlStyleFill);
2020
app.component("ol-style-icon", OlStyleIcon);
2121
app.component("ol-style-text", OlStyleText);
22-
app.component(FlowLine.name, FlowLine);
22+
app.component("ol-style-flowline", OlStyleFlowline);
2323
}
2424

2525
export default install;
@@ -31,6 +31,6 @@ export {
3131
OlStyleFill,
3232
OlStyleIcon,
3333
OlStyleText,
34-
FlowLine,
34+
OlStyleFlowline,
3535
OlStyleCircle,
3636
};

0 commit comments

Comments
 (0)