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

[BUG] hide/show advanced markers does not work #625

Open
vicb opened this issue May 21, 2023 · 9 comments
Open

[BUG] hide/show advanced markers does not work #625

vicb opened this issue May 21, 2023 · 9 comments
Assignees
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

@vicb
Copy link
Contributor

vicb commented May 21, 2023

Environment details

I am using the beta channel of Google Maps and @googlemaps/markerclusterer at 2.1.3

I am adding a bunch of marker to a clusterer:

      for (const launch of this.launches) {
        markers.push(
          new google.maps.marker.AdvancedMarkerElement({
            position: { lat: launch.lat, lng: launch.lon },
            title: launch.title,
          }),
        );
      }
      this.clusterer.addMarkers(markers);
      this.clusterer.setMap(this.map);

At this point everything works fine.

Then I hide the markers:

      this.clusterer.setMap(null);

After that all the markers are hidden as expected

Then I want to show the markers again:

      this.clusterer.setMap(this.map);
      this.clusterer.render(); // calling that makes no difference

That has no effect.
I would effect the marker the show after this call.
But I have to zoom (either in on out) for the marker to re-appear.

I would be up to create a repro if you have a starter template - all the GMaps starters for the JS API website seem to have an issue with the API key.

@vicb vicb 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 May 21, 2023
@wangela
Copy link
Member

wangela commented May 21, 2023

If you would like to upvote the priority of this issue, please comment below or react with 👍 so we can see what is popular when we triage.

@vicb Thank you for opening this issue. 🙏
Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

@vicb
Copy link
Contributor Author

vicb commented May 21, 2023

I have done a screencast of the issue.
You can see that when I re-enable the sites nothing happens until I zoom on the map.

Also I tried to setMap(null) / setMap(map) on an advanced marker and it works well w/o the Clusterer -see this jsfiddle

@novakand
Copy link

Good afternoon. Same problem. Already have a solution?

@askurat
Copy link

askurat commented Jan 4, 2024

Was there ever a fix for this? I am having the same issue.

@amuramoto
Copy link
Member

amuramoto commented Jan 4, 2024

Did a little debugging on this. The MarkerClusterer.clusters array is being emptied when MarkerClusterer.setMap() is called, regardless of whether it's being called with map or null. Not sure why this would be happening since as far as I can tell MarkerClusterer.setMap() is just OverlayView.setMap(), which should just add and remove the overlay from the map. I would think the members of the MarkerClusterer instance would remain intact, but that doesn't seem to be the case.

@amuramoto
Copy link
Member

amuramoto commented Jan 4, 2024

A workaround is to iterate MarkerClusterer.clusters and call setMap on each Cluster.marker rather than on MarkerClusterer:

clusterer.clusters.map(cluster => cluster.marker.setMap(null))
clusterer.clusters.map(cluster => cluster.marker.setMap(map))

See ln 47-53 of this jsFiddle.

@t53m1
Copy link

t53m1 commented Mar 1, 2024

@amuramoto your fiddle is working as expected but in my code I am receiving a ts error. I have attached the screenshot below. Any way to work around this?

Screenshot 2024-03-01 at 12 55 46 PM

@t53m1
Copy link

t53m1 commented Mar 1, 2024

I got it working by ignoring the warnings/errors. This does hide the markers and clusters, but once you zoom in/out, they rerender

@FlorianBruniaux
Copy link

Hello, any news on this ?

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

7 participants