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

Hiding markers is still displaying clusters with size 0 #267

Open
yanngit opened this issue Mar 23, 2022 · 9 comments
Open

Hiding markers is still displaying clusters with size 0 #267

yanngit opened this issue Mar 23, 2022 · 9 comments
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@yanngit
Copy link

yanngit commented Mar 23, 2022

Hi,
I'm currently building an interactive map with markers. So my code is adding a map with various markers, then adding a clustering and everything is working fine. Issue is appearing when I'm starting to hide some markers, by using marker.setVisible(false) and then rendering again my clusterer, with markerClusterer.render(). I can see on my map some cluster with size 0 appearing where I've hidden some markers.

Environment details

1.Using script api <script src="https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js"></script>
2. Inside a vuejs app

Steps to reproduce

  1. Create a map
  2. Add various markers
  3. Add a clustrer
  4. Render it to see everything is fine
  5. Hide markers dynamically, with a button click for example
  6. Render again the clusterer

You should see like me clusters of size 0

Code example

Rapid fiddle here : https://jsfiddle.net/2vzayxc4/3/
Click on hide button under the map, and zoom out to see it happening.

Thanks for the help, it's driving me crazy ;)

@yanngit yanngit added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Mar 23, 2022
@jpoehnelt
Copy link
Contributor

@yanngit Thank you for opening this issue. 🙏
Please check out these other resources that might be applicable:

This is an automated message, feel free to ignore.

@bensinca
Copy link

I just noticed this as well. I also tried various methods from here such as removing each marker, resetting or using the clearMarkers.

Still returning the size 0.

@jpoehnelt
Copy link
Contributor

There are two separate issues going on here.

  1. The default Algorithm is naive about marker visibility. The changed attribute is based upon a shallow diff of the markers array.
  2. The default Render still renders with 0.

@thexs-dev
Copy link

In the previous markerclustererplus there is an option ignoreHidden that would ignore those markers with visible equal false

Can that be added to this version?

@jpoehnelt
Copy link
Contributor

The workaround is to remove the marker from the MarkerClusterer when removing from the map or setting visible to false.

There are other related cases that could maybe be addressed:

  • is marker.getMap() the same as that of the clusterer?
  • is marker.getMap() null?
  • marker visibility is false?

@bensinca
Copy link

So far the only workaround, in my case, is to use the clearMarkers then addMarkers methods.

@LeLunZ
Copy link

LeLunZ commented Oct 3, 2022

I worked around this issue by adding the renderer and setting the visibility of a cluster marker like this:

visible: cluster.count > 0,

@coderwyd
Copy link

coderwyd commented Mar 6, 2023

I encountered the same problem. If you use clearMarker first and then addMarker, the count will be 0.

@coderwyd
Copy link

coderwyd commented Mar 6, 2023

I encountered the same problem. If you use clearMarker first and then addMarker, the count will be 0.

I should have solved the problem by using cluster.markers.length instead of cluster.count.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

6 participants