diff --git a/src/layer/DivOverlay.js b/src/layer/DivOverlay.js index 83c9fe12185..36c0b241fee 100644 --- a/src/layer/DivOverlay.js +++ b/src/layer/DivOverlay.js @@ -160,13 +160,8 @@ export var DivOverlay = Layer.extend({ }, // prepare bound overlay to open: update latlng pos / content source (for FeatureGroup) - _prepareOpen: function (source, latlng) { - if (source instanceof Layer) { - this._source = source; - } else { - latlng = source; - source = this._source; - } + _prepareOpen: function (latlng) { + var source = this._source; if (!source._map) { return false; } if (source instanceof FeatureGroup) { diff --git a/src/layer/Popup.js b/src/layer/Popup.js index 12bcf7234e0..99bd0ea4fb2 100644 --- a/src/layer/Popup.js +++ b/src/layer/Popup.js @@ -416,8 +416,8 @@ Layer.include({ // @method openPopup(latlng?: LatLng): this // Opens the bound popup at the specified `latlng` or at the default popup anchor if no `latlng` is passed. - openPopup: function (target, latlng) { - if (this._popup && this._popup._prepareOpen(target, latlng)) { + openPopup: function (latlng) { + if (this._popup && this._popup._prepareOpen(latlng)) { // open the popup on the map this._map.openPopup(this._popup, latlng); } @@ -436,12 +436,12 @@ Layer.include({ // @method togglePopup(): this // Opens or closes the popup bound to this layer depending on its current state. - togglePopup: function (target) { + togglePopup: function () { if (this._popup) { if (this._popup._map) { this.closePopup(); } else { - this.openPopup(target); + this.openPopup(); } } return this; @@ -469,33 +469,25 @@ Layer.include({ }, _openPopup: function (e) { - var target = e.layer || e.target; - - if (!this._popup) { + if (!this._popup || !this._map) { return; } - - if (!this._map) { - return; - } - // prevent map click DomEvent.stop(e); - // if this inherits from Path its a vector and we can just - // open the popup at the new location - if (target instanceof Path) { - this.openPopup(target, e.latlng); + var target = e.layer || e.target; + if (this._popup._source === target && !(target instanceof Path)) { + // treat it like a marker and figure out + // if we should toggle it open/closed + if (this._map.hasLayer(this._popup)) { + this.closePopup(); + } else { + this.openPopup(e.latlng); + } return; } - - // otherwise treat it like a marker and figure out - // if we should toggle it open/closed - if (this._map.hasLayer(this._popup) && this._popup._source === target) { - this.closePopup(); - } else { - this.openPopup(target, e.latlng); - } + this._popup._source = target; + this.openPopup(e.latlng); }, _movePopup: function (e) { diff --git a/src/layer/Tooltip.js b/src/layer/Tooltip.js index fac6f5ea92c..8e434d92102 100644 --- a/src/layer/Tooltip.js +++ b/src/layer/Tooltip.js @@ -324,8 +324,8 @@ Layer.include({ // @method openTooltip(latlng?: LatLng): this // Opens the bound tooltip at the specified `latlng` or at the default tooltip anchor if no `latlng` is passed. - openTooltip: function (target, latlng) { - if (this._tooltip && this._tooltip._prepareOpen(target, latlng)) { + openTooltip: function (latlng) { + if (this._tooltip && this._tooltip._prepareOpen(latlng)) { // open the tooltip on the map this._map.openTooltip(this._tooltip, latlng); @@ -355,12 +355,12 @@ Layer.include({ // @method toggleTooltip(): this // Opens or closes the tooltip bound to this layer depending on its current state. - toggleTooltip: function (target) { + toggleTooltip: function () { if (this._tooltip) { if (this._tooltip._map) { this.closeTooltip(); } else { - this.openTooltip(target); + this.openTooltip(); } } return this; @@ -388,12 +388,12 @@ Layer.include({ }, _openTooltip: function (e) { - var target = e.layer || e.target; - if (!this._tooltip || !this._map) { return; } - this.openTooltip(target, this._tooltip.options.sticky ? e.latlng : undefined); + this._tooltip._source = e.layer || e.target; + + this.openTooltip(this._tooltip.options.sticky ? e.latlng : undefined); }, _moveTooltip: function (e) {