L.CircleMarker
從L.Path
不L.Marker
擴展,所以如果你比較https://github.com/Leaflet/Leaflet.label/blob/master/src/Path.Label.js和https://github.com/Leaflet/Leaflet.label/blob/master/src/Marker.Label.js你可以找到Path
沒有任何選項,這個邏輯,你必須自己實現。例如:
L.CircleMarker.include({
bindLabel: function (content, options) {
if (!this._label || this._label.options !== options) {
this._label = new L.Label(options, this);
}
this._label.setContent(content);
this._labelNoHide = options && options.noHide;
if (!this._showLabelAdded) {
if (this._labelNoHide) {
this
.on('remove', this.hideLabel, this)
.on('move', this._moveLabel, this);
this._showLabel({latlng: this.getLatLng()});
} else {
this
.on('mouseover', this._showLabel, this)
.on('mousemove', this._moveLabel, this)
.on('mouseout remove', this._hideLabel, this);
if (L.Browser.touch) {
this.on('click', this._showLabel, this);
}
}
this._showLabelAdded = true;
}
return this;
},
unbindLabel: function() {
if (this._label) {
this._hideLabel();
this._label = null;
this._showLabelAdded = false;
if (this._labelNoHide) {
this
.off('remove', this._hideLabel, this)
.off('move', this._moveLabel, this);
} else {
this
.off('mouseover', this._showLabel, this)
.off('mousemove', this._moveLabel, this)
.off('mouseout remove', this._hideLabel, this);
}
}
return this;
}
});
L.circleMarker([53.902257, 27.541640] ,{title: 'unselected'}).addTo(map).bindLabel('Destination', { noHide: true });
我移動線'this._showLabel({經緯度:this.getLatLng()});'出noHide條件的成另一種方法包括:' showLabel:function(){...}'。這允許我創建圓,將其添加到地圖,然後調用'circle.showLabel()'。 – jakeorr 2014-05-30 18:29:29
太棒了!雖然在標籤上方顯示彈出窗口時它不會消失... – Egidi 2015-02-09 09:10:58