【问题标题】:Overlapping Marker Spiderfier + MarkerWithLabel重叠标记 Spiderfier + MarkerWithLabel
【发布时间】:2015-01-22 16:55:36
【问题描述】:

使用带有Overlapping Marker SpiderfierMarkerWithLabel 的Google Maps JavaScript API v3 会在spiderfying 时产生不利影响:所有标记都会spiderfy 然后立即返回到它们的原始位置(not via unspiderfy)除了第一个标记。

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

【问题讨论】:

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


    【解决方案1】:

    问题源于 optimized Marker 属性,MarkerWithLabel 强制该属性为 false。将 optimized 保留为 true(默认设置)应该会导致正确的爬虫。这样做需要对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);
    }
    

    【讨论】:

      猜你喜欢
      • 2022-08-03
      • 2018-12-13
      • 2015-01-05
      • 2017-08-13
      • 2014-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多