扩展传单标记时出现问题

los*_*ion 5 leaflet

我正在尝试扩展传单Marker类以创建位置标记.我的位置标记包含一个代表用户位置的内圈和一个代表用户位置精确度的外圈.我正在扩展课程,因为我想展示很多用户位置,我不想为每个用户创建2个标记.

我有问题让弹出窗口工作.两件事情:

  1. 弹出窗口不起作用,即永远不会出现.
  2. 我可以将弹出窗口仅绑定到内圈(用户位置),而不是外圈(精度)

这是一个插件,蓝色标记是弹出的标准圆,绿色是我的扩展标记,弹出不起作用. http://plnkr.co/edit/5tz538?p=preview

码:

L.LocationMarker = L.Marker.extend({
  initialize: function (latlng, options) {
    L.Marker.prototype.initialize.call(this, latlng);

    this._accuracyCircle = L.circle(latlng, 0, {
      color: options.color,
      fillColor: options.color,
      fillOpacity: 0.15,
      weight: 2,
      opacity: 0.5
    });

    this._locationMarker = L.circleMarker(latlng, {
      color: options.color,
      fillColor: options.color,
      fillOpacity: 0.7,
      weight: 2,
      opacity: 0.9,
      radius: 5
    });

    this._location = L.layerGroup([this._accuracyCircle, this._locationMarker]);
  },

  addTo: function (map) {
    map.addLayer(this._location);
    return this;
  },

  onAdd: function (map) {
    this._map = map;
    map.addLayer(this._location);
  },

  onRemove: function (map) {
    map.removeLayer(this._location);
  },

  getLatLng: function() {
    return this._locationMarker.getLatLng();
  },

  setLatLng: function (latlng) {
    this._accuracyCircle.setLatLng(latlng);
    this._locationMarker.setLatLng(latlng);
    return this;
  },

  setAccuracy: function (accuracy) {
    this._accuracyCircle.setRadius(accuracy ? accuracy : 0);
    return this;
  }
});

L.locationMarker = function (latlng, options) {
  return new L.LocationMarker(latlng, options);
};
Run Code Online (Sandbox Code Playgroud)

los*_*ion 3

知道了。我必须重写弹出方法才能仅处理 locationMarker。

bindPopup: function (content, options) {
this._locationMarker.bindPopup(content, options);
    return this;
},

setPopupContent: function (content) {
this._locationMarker.setPopupContent(content);
    return this;
},

unbindPopup: function () {
this._locationMarker.unbindPopup();
    return this;
},

_movePopup: function (e) {
this._locationMarker.setLatLng(e.latlng);
}
Run Code Online (Sandbox Code Playgroud)

笨蛋: http: //plnkr.co/edit/5tz538?p =preview