Skip to content

Commit

Permalink
fix(ol-source-*): re-use existing source on update to bind interactio…
Browse files Browse the repository at this point in the history
…ns correctly

closes #364
  • Loading branch information
d-koppenhagen committed Aug 1, 2024
1 parent 63940e9 commit 7dfd962
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/composables/useSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ export default function useSource<T extends Source>(
props: ConstructorParameters<typeof SourceClass>[0],
eventsToHandle: string[] = [],
) {
const source = updateSource();

function updateSource() {
const properties = usePropsAsObjectProperties({
function getProperties() {
return usePropsAsObjectProperties({
...props,
...(props.projection
? {
Expand All @@ -33,11 +31,24 @@ export default function useSource<T extends Source>(
}
: {}),
});
const s = shallowRef(new SourceClass(properties));
useOpenLayersEvents(s, eventsToHandle);
}

const source = shallowRef(new SourceClass(getProperties()));
updateSource();

function updateSource() {
layer?.value?.setSource(null);
layer?.value?.setSource(s.value);
return s;
const properties = getProperties();
source.value.setProperties(properties);
for (const key in properties) {
const keyInObj = key as keyof typeof properties;
if (properties[keyInObj] !== undefined) {
source.value.set(key, properties[keyInObj]);
}
}
layer?.value?.setSource(source.value);
useOpenLayersEvents(source, eventsToHandle);
return source;
}

function removeSource() {
Expand Down

0 comments on commit 7dfd962

Please # to comment.