js-markerclusterer
js-markerclusterer copied to clipboard
Clicking a cluster zooms on marker outside it if the marker has a visible infoWindow
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.
If you would like to upvote the priority of this issue, please comment below or react with :+1: 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:
- Check the issue tracker - bugs and feature requests for Google Maps Platform APIs and SDKs
- Open a support case - Get 1:1 support in Cloud Console.
- Discord - chat with other developers
- StackOverflow - use the
google-mapstag
This is an automated message, feel free to ignore.
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.
@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
@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);
};