我正在尝试使用MarkerClusterer对地图上的标记进行聚类。问题是,我没有使用默认标记(google.maps.Marker),而是使用一个继承自google.maps.OverlayView的自定义类。
不幸的是,似乎该库是在假定使用基本标记的情况下开发的,事实上,我会因为我的类未实现google.maps.Marker中定义的方法而出现错误。
是否可能通过保留我的自定义标记来使用MarkerClusterer?
编辑:比我预期的要简单得多,我通过在我的自定义类中实现了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;
};