Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tooltips interactive themselves #7532

Merged
merged 4 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DivOverlay: process 'interactive' option
  • Loading branch information
johndoe committed Nov 7, 2021
commit df66fe1bb518ce799836fc05dbc343a464dc3e5d
14 changes: 14 additions & 0 deletions src/layer/DivOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export var DivOverlay = Layer.extend({
// @section
// @aka DivOverlay options
options: {
// @option interactive: Boolean = false
// If true, the popup/tooltip will listen to the mouse events.
interactive: false,

// @option offset: Point = Point(0, 7)
// The offset of the popup position. Useful to control the anchor
// of the popup when opening it on some overlays.
Expand Down Expand Up @@ -58,6 +62,11 @@ export var DivOverlay = Layer.extend({
}

this.bringToFront();

if (this.options.interactive) {
DomUtil.addClass(this._container, 'leaflet-interactive');
this.addInteractiveTarget(this._container);
}
},

onRemove: function (map) {
Expand All @@ -67,6 +76,11 @@ export var DivOverlay = Layer.extend({
} else {
DomUtil.remove(this._container);
}

if (this.options.interactive) {
DomUtil.removeClass(this._container, 'leaflet-interactive');
this.removeInteractiveTarget(this._container);
}
},

// @namespace Popup
Expand Down
14 changes: 0 additions & 14 deletions src/layer/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ export var Tooltip = DivOverlay.extend({
// If true, the tooltip will follow the mouse instead of being fixed at the feature center.
sticky: false,

// @option interactive: Boolean = false
// If true, the tooltip will listen to the mouse events.
interactive: false,

// @option opacity: Number = 0.9
// Tooltip container opacity.
opacity: 0.9
Expand All @@ -68,11 +64,6 @@ export var Tooltip = DivOverlay.extend({
DivOverlay.prototype.onAdd.call(this, map);
this.setOpacity(this.options.opacity);

if (this.options.interactive) {
DomUtil.addClass(this._container, 'leaflet-interactive');
this.addInteractiveTarget(this._container);
}

// @namespace Map
// @section Tooltip events
// @event tooltipopen: TooltipEvent
Expand All @@ -93,11 +84,6 @@ export var Tooltip = DivOverlay.extend({
onRemove: function (map) {
DivOverlay.prototype.onRemove.call(this, map);

if (this.options.interactive) {
DomUtil.removeClass(this._container, 'leaflet-interactive');
this.removeInteractiveTarget(this._container);
}

// @namespace Map
// @section Tooltip events
// @event tooltipclose: TooltipEvent
Expand Down