Skip to content

Commit b1bb37e

Browse files
committed
fix(ol-overlay): prevent re-compute overlay, use shallowRef instead and watch property changes
this makes `autoPan` work. closes #257
1 parent 3eb1fff commit b1bb37e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Diff for: src/components/map/OlOverlay.vue

+14-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
watch,
1515
onMounted,
1616
onUnmounted,
17-
computed,
17+
shallowRef,
1818
} from "vue";
1919
2020
import type Map from "ol/Map";
@@ -35,7 +35,7 @@ const htmlContent = ref<HTMLElement>();
3535
3636
const { properties } = usePropsAsObjectProperties(props);
3737
38-
const overlay = computed(() => new Overlay(properties));
38+
const overlay = shallowRef(new Overlay(properties));
3939
4040
useOpenLayersEvents(overlay, [
4141
"change:element",
@@ -71,10 +71,18 @@ onMounted(() => {
7171
7272
onUnmounted(() => removeOverlay(overlay.value));
7373
74-
watch(overlay, (newVal, oldVal) => {
75-
removeOverlay(oldVal);
76-
map?.addOverlay(newVal);
77-
});
74+
watch(
75+
() => properties,
76+
(newValue) => {
77+
for (const key in newValue) {
78+
const keyInObj = key as keyof typeof newValue;
79+
if (newValue[keyInObj]) {
80+
overlay.value.set(key, newValue[keyInObj]);
81+
}
82+
}
83+
},
84+
{ deep: true },
85+
);
7886
7987
watchEffect(
8088
() => {

Diff for: src/demos/OverlayDemo.vue

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
:position="[item + 37.9 + offset, 40.1]"
1919
v-for="item in list"
2020
:key="item"
21+
:autoPan="true"
2122
>
2223
<div class="overlay-content">
2324
{{ item }}

0 commit comments

Comments
 (0)