将 Google Maps JavaScript API v3 与Overlapping Marker Spiderfier和MarkerWithLabel 一起使用会在蜘蛛化时产生不利影响:除了第一个标记外,所有标记都会蜘蛛化,然后立即返回其原始位置(不是通过 unspiderfy)。
也就是说,标记事件在蜘蛛化后被position_changed
触发一次,其中是蜘蛛化的标记数。n - 1
n
将 Google Maps JavaScript API v3 与Overlapping Marker Spiderfier和MarkerWithLabel 一起使用会在蜘蛛化时产生不利影响:除了第一个标记外,所有标记都会蜘蛛化,然后立即返回其原始位置(不是通过 unspiderfy)。
也就是说,标记事件在蜘蛛化后被position_changed
触发一次,其中是蜘蛛化的标记数。n - 1
n
问题源于optimized
MarkerWithLabel 强制为 false 的 Marker 属性。保留optimized
为 true(默认设置)应该会导致正确的爬虫。这样做需要对MarkerWithLabel 源进行修补:删除设置的行optimized = false
:
function MarkerWithLabel(opt_options) {
opt_options = opt_options || {};
opt_options.labelContent = opt_options.labelContent || "";
opt_options.labelAnchor = opt_options.labelAnchor || new google.maps.Point(0, 0);
opt_options.labelClass = opt_options.labelClass || "markerLabels";
opt_options.labelStyle = opt_options.labelStyle || {};
opt_options.labelInBackground = opt_options.labelInBackground || false;
if (typeof opt_options.labelVisible === "undefined") {
opt_options.labelVisible = true;
}
if (typeof opt_options.raiseOnDrag === "undefined") {
opt_options.raiseOnDrag = true;
}
if (typeof opt_options.clickable === "undefined") {
opt_options.clickable = true;
}
if (typeof opt_options.draggable === "undefined") {
opt_options.draggable = false;
}
// if (typeof opt_options.optimized === "undefined") {
// opt_options.optimized = false;
// }
opt_options.crossImage = opt_options.crossImage || "http" + (document.location.protocol === "https:" ? "s" : "") + "://maps.gstatic.com/intl/en_us/mapfiles/drag_cross_67_16.png";
opt_options.handCursor = opt_options.handCursor || "http" + (document.location.protocol === "https:" ? "s" : "") + "://maps.gstatic.com/intl/en_us/mapfiles/closedhand_8_8.cur";
// opt_options.optimized = false; // Optimized rendering is not supported
this.label = new MarkerLabel_(this, opt_options.crossImage, opt_options.handCursor); // Bind the label to the marker
// Call the parent constructor. It calls Marker.setValues to initialize, so all
// the new parameters are conveniently saved and can be accessed with get/set.
// Marker.set triggers a property changed event (called "propertyname_changed")
// that the marker label listens for in order to react to state changes.
google.maps.Marker.apply(this, arguments);
}