Skip to content

Commit

Permalink
DivOverlay: common function toggle
Browse files Browse the repository at this point in the history
Refactor Layer\ togglePopup/Tooltip: use common function DivOverlay\toggle
  • Loading branch information
johndoe committed Mar 31, 2021
1 parent 85c11e9 commit 0dafdad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
11 changes: 11 additions & 0 deletions src/layer/DivOverlay.js
Expand Up @@ -178,6 +178,17 @@ export var DivOverlay = Layer.extend({
return this;
},

// @method toggle(parent?: Layer): this
// Opens or closes the overlay bound to layer depending on its current state.
toggle: function (parent, target) {
if (this._map) {
this.close();
} else {
this._open(arguments.length ? parent : this._source, target);
}
return this;
},

_open: function (parent, layer, latlng) {
if (!parent._map) { return; }

Expand Down
6 changes: 1 addition & 5 deletions src/layer/Popup.js
Expand Up @@ -413,11 +413,7 @@ Layer.include({
// Opens or closes the popup bound to this layer depending on its current state.
togglePopup: function (target) {
if (this._popup) {
if (this._popup._map) {
this._popup.close();
} else {
this.openPopup(target);
}
this._popup.toggle(this, target);
}
return this;
},
Expand Down
6 changes: 1 addition & 5 deletions src/layer/Tooltip.js
Expand Up @@ -331,11 +331,7 @@ Layer.include({
// Opens or closes the tooltip bound to this layer depending on its current state.
toggleTooltip: function (target) {
if (this._tooltip) {
if (this._tooltip._map) {
this._tooltip.close();
} else {
this.openTooltip(target);
}
this._tooltip.toggle(this, target);
}
return this;
},
Expand Down

0 comments on commit 0dafdad

Please sign in to comment.