Fire event after MarkerClusterer has finished

独自空忆成欢 提交于 2019-11-30 20:19:49

I was just wondering the same thing. This is how I did it:

google.maps.event.addListener(markerClusterer, 'clusteringend', myFunction);

Will the map "idle" event work for you? It should fire once the MarkerClusterer has finished (assuming you are loading the MarkerClusterer when the page loads).

It seems this library is not being maintained. It does not work with v3 properly for years and no solution has been developed.

So, I downloaded the non-minimised version and put it into source code for the projects I am working. Accepted solution will only work(for v3) if you make the below changes directly in the library:

find createClusters_ function add google.maps.event.trigger(this, "clusteringend", this); after the for loop. So it will look like below:

MarkerClusterer.prototype.createClusters_ = function() {
  if (!this.ready_) {
    return;
  }

  // Get our current map view bounds.
  // Create a new bounds object so we don't affect the map.
  var mapBounds = new google.maps.LatLngBounds(this.map_.getBounds().getSouthWest(),
      this.map_.getBounds().getNorthEast());
  var bounds = this.getExtendedBounds(mapBounds);

  for (var i = 0, marker; marker = this.markers_[i]; i++) {
    if (!marker.isAdded && this.isMarkerInBounds_(marker, bounds)) {
      this.addToClosestCluster_(marker);
    }
  }
  google.maps.event.trigger(this, "clusteringend", this);
};

Now you can use:

google.maps.event.addListener(markerClusterer, 'clusteringend', myFunction);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!