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

Clicking a cluster zooms on marker outside it if the marker has a visible infoWindow #623

Open
smohadjer opened this issue May 19, 2023 · 4 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

@smohadjer
Copy link

smohadjer commented May 19, 2023

When the infoWindow of a marker is visible and we click on a cluster somewhere else on the map, the map zooms and centers on the marker with infoWindow instead of zooming and centering on markers inside the cluster.

@smohadjer smohadjer 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 19, 2023
@wangela
Copy link
Member

wangela commented May 19, 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.

@smohadjer 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.

@smohadjer smohadjer changed the title If an infoWindow is open on a map, clicking a cluster instead of zooming on markers inside the cluster will center the map on marker with visible infoWindow Clicking a cluster zooms on marker outside it if the marker has a visible infoWindow May 19, 2023
@smohadjer
Copy link
Author

If I disable infoWindow's auto panning by setting disableAutoPan to true, this bug doesn't happen, so I think the problem happens because a click on cluster pushes the visible infoWindow out of map's visible viewport, so perhaps the bug is not in MarkerClusterer, but in how AutoPan is implemented by Google Maps.

@HarrisonMaindonald
Copy link

@smohadjer While this bug is active, I was able to create a work around to this by adding a click event listener to the MarkerClusterer and use that event listener to close the active infoWindow

@smohadjer
Copy link
Author

smohadjer commented May 20, 2023

@HarrisonMaindonald I already tried that workaround, but that doesn't fix the problem completely. For example if infowindow is visible for a marker and you zoom out so that marker goes inside a cluster, now the call to close the infowindow won't close it anymore and if you click on a cluster it will still zoom and center the map on wrong marker. To solve the problem I ended up disabling autopan inside cluster's click handler before map.fitBounds() is called and then enabling it after map.fitBounds() call with a delay.

    const onClusterClickHandler = (event, cluster, map) => {
      // close any open infoWindow so that map doesn't center on wrong marker
      infoWindow.close();

      // disable AutoPan to avoid bug
      infoWindow.setOptions({
        disableAutoPan: true
      });

      map.fitBounds(cluster.bounds);

      // enable AutoPan after cluster has finished centering the map
      window.setTimeout(() => {
        infoWindow.setOptions({
          disableAutoPan: false
        });
      }, 500);
    };

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

4 participants