Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing a reactive variable to ol-geom-line-string coordinate no longer stays in sync with variable. #387

Open
marktlinn opened this issue Oct 15, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@marktlinn
Copy link
Contributor

Describe the bug
I have a component that is making use of <ol-geom-line-string> e.g. <ol-geom-line-string :coordinates="coordinateArray"></ol-geom-line-string> passing a ref containing an array of coordinate arrays to the ol-geom-line-string.

In the initial versions of our app we had been using Vue3 OpenLayers version 4.0.2 and the reactivity worked as expected. On pushing a new coordinate to the ref coordinateArray the new values were being reflected in the geom line being extended to match the values in the Vue ref. Now that is not the case.

Affected version(s)

Please run npm list --depth=0 vue vue3-openlayers ol ol-ext ol-contextmenu and paste the output below:
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Vue3-openlayers: "11.2.0" (also tested on "11.2.1")
Node:  v20.10.0

To Reproduce
Steps to reproduce the behavior:
Create a geom-line-string element and pass :coordinate a array of coordinates that has a new coordinate pushed to it as some set interval.

On the map as the reactive variable coordinateArray has most coordinates pushed to it they should be shown on the map.

Expected behavior
The expected behaviour is that when passed a reactive variable containing coordinates the reactive variable is updated (e.g. additional coordinates are pushed to the array) these updates should be reflected in the map with the geom-line growing, shrinking etc.

Desktop (please complete the following information):

  • Browser chrome
@marktlinn marktlinn added the bug Something isn't working label Oct 15, 2024
@d-koppenhagen
Copy link
Collaborator

I think it's cause the property is not watched deeply. Have you tried to pass a new reference instead of directly pushing into the existing one?

Like this:

const coordinates = ref([/* ... */])

// ...

coordinates.value = [...coordinates.value, newValue]

@marktlinn
Copy link
Contributor Author

Thank you for your response.

Yes, passing a new reference works and is what we're currently doing, but when tracking a large growing array it leads to inefficiencies in needing to copy and create a new reference each time versus a simple .push() operation on an existing array. The Vue reactivity system supports tracking appending elements to an array via the push method as well as supporting other array methods.

This worked in prior versions of Vue3 OpenLayers so was it intentionally removed, or is there an option to have it watched deeply? It feels like if such reactivity is supported natively by Vue it would be great if there were at least an option to enable deep watch.

@d-koppenhagen
Copy link
Collaborator

So, I don't think it was removed intentionally. Does it make a difference when you switch from ref to reactive?

@marktlinn
Copy link
Contributor Author

No, unfortunately not, it doesn't draw or update the <ol-geom-line-string>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants