所以我有一个应用程序,其中包含一个带有(几百个)标记的地图。我使用markerclusterer。由谷歌提供的js集群我的标记,使整个事情更容易看。我正在使用API V3。

我对这一切都很满意。但是我想要做的是在markerclusterer完成对所有标记进行聚类时执行一些操作。我试过自己做,但没有看。

有什么建议吗?(我假设这会比我想象的更容易,我的大脑只是油炸)

有帮助吗?

解决方案

我只是想知道同样的事情。这就是我的确方式:

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

其他提示

将映射“空闲”事件为您工作?一旦MarkerClusterer完成,它应该发射(假设您在页面加载时加载MarkerClusterer)。

看来这个图书馆没有得到维护。它不能与v3正常工作多年,没有解决方案已经开发。

所以,我下载了非最小化版本,并将其放入我正在工作的项目的源代码中。如果您直接在库中进行以下更改,则接受的解决方案仅适用于v3:

查找createClusters_函数添加 google.maps.event.trigger(this, "clusteringend", this); 在for循环之后。所以它看起来如下所示:

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

现在你可以使用:

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top