Skip to content

Commit

Permalink
Popup/Tooltip content function: allow return undefined
Browse files Browse the repository at this point in the history
In this case Popup/Tooltip is not shown.

Useful when only some sublayers need popups:
- previously: it was necessary to attach independent popups to each sublayer
- now: it's enough to have common content function attached to parent layer
  • Loading branch information
johndoe committed Apr 18, 2019
1 parent e079588 commit df506ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/layer/DivOverlay.js
Expand Up @@ -175,6 +175,10 @@ export var DivOverlay = Layer.extend({
this.fire('contentupdate');
},

_hasContentFor: function (layer) {
return typeof this._content !== 'function' || this._content(layer || this);
},

_updatePosition: function () {
if (!this._map) { return; }

Expand Down
2 changes: 1 addition & 1 deletion src/layer/Popup.js
Expand Up @@ -434,7 +434,7 @@ Layer.include({
latlng = layer.getCenter ? layer.getCenter() : layer.getLatLng();
}

if (this._popup && this._map) {
if (this._popup && this._map && this._popup._hasContentFor(layer)) {
// set popup source to this layer
this._popup._source = layer;

Expand Down
2 changes: 1 addition & 1 deletion src/layer/Tooltip.js
Expand Up @@ -328,7 +328,7 @@ Layer.include({
latlng = layer.getCenter ? layer.getCenter() : layer.getLatLng();
}

if (this._tooltip && this._map) {
if (this._tooltip && this._map && this._tooltip._hasContentFor(layer)) {

// set tooltip source to this layer
this._tooltip._source = layer;
Expand Down

0 comments on commit df506ca

Please sign in to comment.