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
New method setInteractive(interactive)
for interactive layers
#5442
Comments
any plans about this feature development? |
@maxdeepfield no plans, as far as I know. I'd be happy to guide if someone would be willing to take this on. |
I would like to see a method like that. It feels false to re-create a marker/line just because I want to change the behavior of the interactivity |
I really need this functionality too, any updates or workarounds @perliedman? |
Made this little function as a "plugin": L.Layer.prototype.setInteractive = function (interactive) {
if (this.getLayers) {
this.getLayers().forEach(layer => {
layer.setInteractive(interactive);
});
return;
}
if (!this._path) {
return;
}
this.options.interactive = interactive;
if (interactive) {
L.DomUtil.addClass(this._path, 'leaflet-interactive');
} else {
L.DomUtil.removeClass(this._path, 'leaflet-interactive');
}
}; Just call it like every other function e.g. |
Thanks @Jadaw1n ! That worked like a charm, here it is in Typescript for anyone who wants it: export class InteractiveImageOverlay extends L.ImageOverlay {
setInteractive(interactive: boolean) {
this.options.interactive = interactive;
if (interactive) {
L.DomUtil.addClass(this.getElement(), 'leaflet-interactive');
this._map.on('click', (event: L.LeafletMouseEvent) => {
this.fireEvent('click', event);
});
} else {
L.DomUtil.removeClass(this.getElement(), 'leaflet-interactive');
this._map.removeEventListener('click');
}
}
} |
… markers) when ALS layer is not being selected. Added setInteractive(), getInteractive() and isInteractive() methods to L.Layer (thanks to Piero "Jadaw1n" Steinger; comment: Leaflet/Leaflet#5442 (comment); home page: https://github.com/Jadaw1n)
@Jadaw1n it is a nice solution you've shared, unfortunately for me it doesn't work with canvas elements |
setInteractive(interactive)
for interactive layers
@Jadaw1n Wanted to say thanks for your code. I ran into this issue changing my rendering from canvas to SVG. Surprised this isn't in leaflet by now. |
For interactive layers (layers with the
interactive
option, or extending the virtualInteractiveLayer
class), we could provide asetInteractive
method to change the state after the layer is created.As it is now, there's no way to change the interactive state after a layer has been created, causing issues like #5441.
The text was updated successfully, but these errors were encountered: