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

Changing the latitude or longitude of a marker: componentShouldUpdate() receives wrong values #28

Open
derwaldgeist opened this issue Mar 25, 2020 · 0 comments

Comments

@derwaldgeist
Copy link

derwaldgeist commented Mar 25, 2020

I am clustering markers on a map, where the marker positions change over time. It's a reactive app where marker positions are influenced by underlying data changes; think of Uber car positions being tracked on a map.

If new data is received, I check - for every marker - if the latitude/longitude values have been changed and re-render them only if this is the case. For this, I am using componentShouldUpdate() to compare the previous and next props.

This works if I place the markers on the map directly, i.e. without clustering them. If the markers are placed as children of a Cluster, however, the componentShouldUpdate() method always receives the initial value of latitude and longitude. Any dynamic changes of these values won't be reflected in the marker positions. They stay where they were initially placed.

This only happens if the markers are passed in as an array, where each marker has its unique key that does not change over time (as you would expect it). Think of the number plates of each car. If I change the keys of the markers to random keys on each re-render, longitude and latitude are passed in correctly. But this of course causes many unnecessary re-renders.

It seems as if the Cluster caches the markers somehow and does not update their lat/lon values if these change, even if the markers are currently visible to the user (i.e. not clustered) on the current zoom level.

Is there a way to prevent this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant