传单中的圆圈标记的标签

vai*_*hah 8 javascript leaflet

我可以像这样添加标签给circlemarker

L.circleMarker(points[i],{title: 'unselected'}).bindLabel('Destination').addTo(map);
Run Code Online (Sandbox Code Playgroud)

这会添加鼠标悬停在圆圈标记上的标签.

但我想添加静态标签,无论鼠标是否在该圆圈标记上都会出现.

我指的是这个演示http://leaflet.github.com/Leaflet.label/用于向圆形标记添加静态标签,但有些我不能这样做.它与标记工作正常但有圆圈标记静态标签不起作用.

还有其他方法在圆圈标记上添加标签吗?

tbi*_*icr 11

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 });
Run Code Online (Sandbox Code Playgroud)