js-markerclusterer icon indicating copy to clipboard operation
js-markerclusterer copied to clipboard

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

Open smohadjer opened this issue 2 years ago • 4 comments

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 avatar May 19 '23 12:05 smohadjer

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:

This is an automated message, feel free to ignore.

wangela avatar May 19 '23 12:05 wangela

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 avatar May 19 '23 13:05 smohadjer

@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 avatar May 20 '23 04:05 HarrisonMaindonald

@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);
    };

smohadjer avatar May 20 '23 06:05 smohadjer