Skip to content

Commit 45efa3c

Browse files
committed
fix(ol-style): correctly handle style changes for interactions
1 parent 72fcc41 commit 45efa3c

File tree

1 file changed

+18
-36
lines changed

1 file changed

+18
-36
lines changed

src/components/styles/OlStyle.vue

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,58 +21,40 @@ const props = withDefaults(
2121
{}
2222
);
2323
24-
const styledObj = inject<Ref<Draw | Modify | Style | null> | null>(
24+
const styledObj = inject<Ref<Draw | Modify | Style> | undefined>(
2525
"stylable",
26-
null
26+
undefined
2727
);
2828
const { properties } = usePropsAsObjectProperties(props);
2929
3030
const style = computed(() => new Style(properties));
3131
3232
const setStyle = (val: Style | null) => {
33-
if (styledObj?.value instanceof Draw || styledObj?.value instanceof Modify) {
34-
styledObj.value?.getOverlay().setStyle(val);
35-
styledObj.value.changed();
36-
styledObj.value?.dispatchEvent("styleChanged");
33+
const st = styledObj?.value;
34+
if (!st) {
3735
return;
3836
}
39-
try {
40-
if (styledObj?.value) {
37+
if (st instanceof Draw || st instanceof Modify) {
38+
st.getOverlay().setStyle(val);
39+
st.changed();
40+
st.dispatchEvent("styleChanged");
41+
} else {
42+
try {
4143
// @ts-ignore
42-
if (styledObj.value.setStyle) {
43-
// @ts-ignore
44-
styledObj.value.setStyle(val);
45-
}
44+
st.setStyle(val);
4645
// @ts-ignore
47-
if (styledObj.value.changed) {
48-
// @ts-ignore
49-
styledObj.value.changed();
50-
}
46+
st.changed();
5147
// @ts-ignore
52-
if (styledObj.value.dispatchEvent) {
53-
// @ts-ignore
54-
styledObj.value.dispatchEvent("styleChanged");
55-
}
56-
}
57-
} catch (error) {
58-
if (styledObj?.value) {
48+
st.dispatchEvent("styleChanged");
49+
} catch (error) {
5950
// @ts-ignore
60-
styledObj.value.style_ = val;
51+
st.style_ = val;
6152
// @ts-ignore
62-
if (styledObj.value.values_) {
63-
// @ts-ignore
64-
styledObj.value.values_.style = val;
65-
}
53+
st.values_.style = val;
6654
// @ts-ignore
67-
if (styledObj.value?.changed) {
68-
// @ts-ignore
69-
styledObj.value?.changed();
70-
}
55+
st.changed();
7156
// @ts-ignore
72-
if (styledObj.value?.dispatchEvent) {
73-
// @ts-ignore
74-
styledObj.value?.dispatchEvent("styleChanged");
75-
}
57+
st.dispatchEvent("styleChanged");
7658
}
7759
}
7860
};

0 commit comments

Comments
 (0)