重叠Marker Spiderfier + MarkerWithLabel

时间:2014-11-24 20:54:54

标签: google-maps-markers overlay-view markerspiderfier

使用带有Overlapping Marker SpiderfierMarkerWithLabel的Google Maps JavaScript API v3会在蜘蛛网上产生负面影响:所有标记都会发生蜘蛛侠,然后立即返回其原始位置(通过unspiderfy)除了第一个标记。

也就是说,标记事件position_changed在蜘蛛网之后会被触发额外n - 1次,其中n是蜘蛛标记的数量。

enter image description here

1 个答案:

答案 0 :(得分:1)

问题源于optimized Marker属性,MarkerWithLabel强制为false。将optimized保留为真(默认设置)应该导致正确的蜘蛛网。这样做需要MarkerWithLabel source的补丁:删除设置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);
}

enter image description here