2011-11-28 64 views
3

我试图用MarkerClusterer到clusterize在我的地图标记。 问题是我没有使用默认的标记(google.maps.Marker),而是一个自定义的类,它从hinerits google.maps.OverlayView。 不幸的是,似乎该库已开发假定使用基本标记的,其实我得到的错误,因为我的课没有实现在google.maps.Marker定义的方法。 是否有可能让我的自定义标记使用MarkerClusterer谷歌地图V3:聚类自定义标记

编辑:它比我想象的,我通过实现2种方法在我的自定义类解决容易得多:))

调用setVisible(为getPosition(以帮助他人下面是我完整的界面(没有完整的实现):

BFPushpin = function(config) 
{ 
    this.setMap(config.map); 
    this.set("position", config.position); 
    // other settings... 
}; 

// my class extends google.maps.OverlayView 
BFPushpin.prototype = new google.maps.OverlayView(); 

BFPushpin.prototype.getBounds = function() 
{ 
    return new google.maps.LatLngBounds(this.position, this.position); 
}; 

BFPushpin.prototype.getPoint = function() 
{ 
    var bounds = this.getBounds(); 
    var projection = this.getProjection(); 
    var sw = projection.fromLatLngToDivPixel(bounds.getSouthWest()); 
     var ne = projection.fromLatLngToDivPixel(bounds.getNorthEast()); 

    return new google.maps.Point(sw.x, ne.y); 
}; 

BFPushpin.prototype.getSuperContainer = function() 
{ 
    var panes = this.getPanes(); 
    return jQuery(panes ? panes.overlayImage : ""); 
}; 

BFPushpin.prototype.getContainer = function() 
{ 
    // return inner container 
}; 

BFPushpin.prototype._generatePopupContent = function() 
{ 
    // return markup for the popupwindow 
}; 

BFPushpin.prototype._addListeners = function() 
{ 
    // add handlers for the pushpin 
}; 

BFPushpin.prototype.onAdd = function() 
{ 
    // customize content here 
}; 

BFPushpin.prototype.onRemove = function() 
{ 
    // remove pin container here 
}; 

BFPushpin.prototype.draw = function() 
{ 
    // set display style here 
}; 

BFPushpin.prototype.setVisible = function(visible) 
{ 
    // set display block or hidden 
}; 

BFPushpin.prototype.getPosition = function() 
{ 
    return this.position; 
}; 
+0

林通过您的解决方案有点困惑。我正在尝试做类似的事情,我有一个自定义覆盖图,它从OverlayView“继承”,并且通过简单列举我自己在绘图函数中创建的对象列表来绘制标记。那么你如何在这里协调使用“标记”,以便群集运行? – Brandon

+0

你是否为每个标记渲染一个完整的覆盖图? – Brandon

回答

1

或者只是定义MarkerClusterer在标记上所期望的函数。 setMap和getPosition()以及其他一些。

+0

这是危险的,因为你永远不知道哪些方法可以通过未来的版本/其他图书馆和方法等 – TMS

+0

使用不是真的,因为你只是实现的标记接口,这是API在美丽的貂,你不应该有问题。 MarkerClusterer只关心获取物品的位置并能够设置其可见性/地图。 – skarE

0

你应该可能定义新的标记类,使其也继承自google.maps.Marker(即,它实现了它的接口)。 MarkerClusterer使用此接口是合乎逻辑的 - 它必须假设标记是为了与它们一起工作的标记:-)