Skip to content

Commit

Permalink
DivOverlay/Popup/Tooltip: refactor to avoid of undocumented arguments…
Browse files Browse the repository at this point in the history
… for public methods
  • Loading branch information
johndoe committed Nov 1, 2021
1 parent d4e5316 commit e33ca9c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
9 changes: 2 additions & 7 deletions src/layer/DivOverlay.js
Expand Up @@ -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) {
Expand Down
40 changes: 16 additions & 24 deletions src/layer/Popup.js
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions src/layer/Tooltip.js
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e33ca9c

Please sign in to comment.