在Google Maps API v3中使用MarkerClusterer限制缩放级别时出错 [英] Error when restricting zoom levels using MarkerClusterer in Google Maps API v3

查看:568
本文介绍了在Google Maps API v3中使用MarkerClusterer限制缩放级别时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的代码在这里找到:将Spiderfier JS集成到markerClusterer V3中,以爆炸多标记具有完全相同的long / lat 限制缩放级别,当点击MarkerClusterer创建的群集包含点在同一位置。



现场示例如下:
http://www.adultlearnersfestival.com/newsite/yourarea/map.html



我在Firebug中遇到错误:

 错误:TypeError:markers is undefined 

并且无法计算出导致它的原因。具体的代码是:

  var minClusterZoom = 14; 
mc.setMaxZoom(minClusterZoom);
gm.event.addListener(mc,'clusterclick',function(cluster){
map.fitBounds(cluster.getBounds()); //适合点击
的集群边界如果(map.getZoom()> minClusterZoom + 1)//如果放大过去15(第一级没有集群),缩小到15
map.setZoom(minClusterZoom + 1);
}) ;

非常感谢任何帮助。
- Tom

解决方案

我采用了不同的方法: markerClusterer点击缩放并编辑MarkerClusterer来源如下



  / ** 
*如果设置了该选项,则触发clusterclick事件和缩放。
* /
ClusterIcon.prototype.triggerClusterClick = function(){
var markerClusterer = this.cluster_.getMarkerClusterer();

//触发clusterclick事件。
google.maps.event.trigger(markerClusterer,'clusterclick',this.cluster_);

if(markerClusterer.isZoomOnClick()){
//放大集群。
this.map_.fitBounds(this.cluster_.getBounds());
}
}; b




code> / **
*如果设置了该选项,则触发clusterclick事件和缩放。
* /
ClusterIcon.prototype.triggerClusterClick = function(){
var markerClusterer = this.cluster_.getMarkerClusterer();

//触发clusterclick事件。
google.maps.event.trigger(markerClusterer,'clusterclick',this.cluster_);

if(markerClusterer.isZoomOnClick()){
//放大集群。
this.map_.fitBounds(this.cluster_.getBounds());

//修改放大函数
if(this.map_.getZoom()> markerClusterer.getMaxZoom()+ 1)
this.map_.setZoom(markerClusterer.getMaxZoom ()+1);
}
};


I'm using code found here: Integrating Spiderfier JS into markerClusterer V3 to explode multi-markers with exact same long / lat to restrict zoom levels when clicking on MarkerClusterer created clusters containing points at the same location.

Live example is here: http://www.adultlearnersfestival.com/newsite/yourarea/map.html

I'm getting an error in Firebug however:

Error: TypeError: markers is undefined 

and can't work out what's causing it. The specific code is:

var minClusterZoom = 14;
mc.setMaxZoom(minClusterZoom);
gm.event.addListener(mc, 'clusterclick', function(cluster) {
  map.fitBounds(cluster.getBounds()); // Fit the bounds of the cluster clicked on
  if( map.getZoom() > minClusterZoom+1 ) // If zoomed in past 15 (first level without clustering), zoom out to 15
  map.setZoom(minClusterZoom+1);
});

Any help much appreciated. - Tom

解决方案

I took a different approach suggested here: markerClusterer on click zoom and edited the MarkerClusterer source as follows

from this

/**
 * Triggers the clusterclick event and zoom's if the option is set.
 */
ClusterIcon.prototype.triggerClusterClick = function() {
  var markerClusterer = this.cluster_.getMarkerClusterer();

  // Trigger the clusterclick event.
  google.maps.event.trigger(markerClusterer, 'clusterclick', this.cluster_);

  if (markerClusterer.isZoomOnClick()) {
    // Zoom into the cluster.
    this.map_.fitBounds(this.cluster_.getBounds());
  }
};

to this

/**
 * Triggers the clusterclick event and zoom's if the option is set.
 */
ClusterIcon.prototype.triggerClusterClick = function() {
  var markerClusterer = this.cluster_.getMarkerClusterer();

  // Trigger the clusterclick event.
  google.maps.event.trigger(markerClusterer, 'clusterclick', this.cluster_);

  if (markerClusterer.isZoomOnClick()) {
    // Zoom into the cluster.
    this.map_.fitBounds(this.cluster_.getBounds());

    // modified zoom in function
        if( this.map_.getZoom() > markerClusterer.getMaxZoom()+1 )
          this.map_.setZoom(markerClusterer.getMaxZoom()+1);
  }
};

这篇关于在Google Maps API v3中使用MarkerClusterer限制缩放级别时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆