lib/leaflet.label/src/Marker.Label.js in leaflet-js-0.6.beta4 vs lib/leaflet.label/src/Marker.Label.js in leaflet-js-0.7.0

- old
+ new

@@ -7,136 +7,21 @@ // L.Marker.options.icon therefore missing our mixin above. L.Marker.mergeOptions({ icon: new L.Icon.Default() }); +L.Marker.include(L.BaseMarkerMethods); L.Marker.include({ - showLabel: function () { - if (this._label && this._map) { - this._label.setLatLng(this._latlng); - this._map.showLabel(this._label); - } - - return this; - }, - - hideLabel: function () { - if (this._label) { - this._label.close(); - } - return this; - }, - - setLabelNoHide: function (noHide) { - if (this._labelNoHide === noHide) { - return; - } - - this._labelNoHide = noHide; - - if (noHide) { - this._removeLabelRevealHandlers(); - this.showLabel(); - } else { - this._addLabelRevealHandlers(); - this.hideLabel(); - } - }, - - bindLabel: function (content, options) { - var anchor = L.point(this.options.icon.options.labelAnchor) || new L.Point(0, 0); - - anchor = anchor.add(L.Label.prototype.options.offset); - - if (options && options.offset) { - anchor = anchor.add(options.offset); - } - - options = L.Util.extend({offset: anchor}, options); - - this._labelNoHide = options.noHide; - - if (!this._label) { - if (!this._labelNoHide) { - this._addLabelRevealHandlers(); - } - - this - .on('remove', this.hideLabel, this) - .on('move', this._moveLabel, this); - - this._hasLabelHandlers = true; - } - - this._label = new L.Label(options, this) - .setContent(content); - - return this; - }, - - unbindLabel: function () { - if (this._label) { - this.hideLabel(); - - this._label = null; - - if (this._hasLabelHandlers) { - if (!this._labelNoHide) { - this._removeLabelRevealHandlers(); - } - - this - .off('remove', this.hideLabel, this) - .off('move', this._moveLabel, this); - } - - this._hasLabelHandlers = false; - } - return this; - }, - - updateLabelContent: function (content) { - if (this._label) { - this._label.setContent(content); - } - }, - - _addLabelRevealHandlers: function () { - this - .on('mouseover', this.showLabel, this) - .on('mouseout', this.hideLabel, this); - - if (L.Browser.touch) { - this.on('click', this.showLabel, this); - } - }, - - _removeLabelRevealHandlers: function () { - this - .off('mouseover', this.showLabel, this) - .off('mouseout', this.hideLabel, this) - .off('remove', this.hideLabel, this) - .off('move', this._moveLabel, this); - - if (L.Browser.touch) { - this.off('click', this.showLabel, this); - } - }, - - _moveLabel: function (e) { - this._label.setLatLng(e.latlng); - }, - _originalUpdateZIndex: L.Marker.prototype._updateZIndex, _updateZIndex: function (offset) { var zIndex = this._zIndex + offset; this._originalUpdateZIndex(offset); - if (this._label) { - this._label.updateZIndex(zIndex); + if (this.label) { + this.label.updateZIndex(zIndex); } }, _originalSetOpacity: L.Marker.prototype.setOpacity, @@ -151,10 +36,20 @@ _updateOpacity: function () { var absoluteOpacity = this.options.opacity === 0 ? 0 : 1; this._originalUpdateOpacity(); - if (this._label) { - this._label.setOpacity(this.options.labelHasSemiTransparency ? this.options.opacity : absoluteOpacity); + if (this.label) { + this.label.setOpacity(this.options.labelHasSemiTransparency ? this.options.opacity : absoluteOpacity); } + }, + + _originalSetLatLng: L.Marker.prototype.setLatLng, + + setLatLng: function (latlng) { + if (this.label && !this._labelNoHide) { + this.hideLabel(); + } + + return this._originalSetLatLng(latlng); } }); \ No newline at end of file