question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New method `setInteractive(interactive)` for interactive layers

See original GitHub issue

For interactive layers (layers with the interactive option, or extending the virtual InteractiveLayer class), we could provide a setInteractive 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.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:11
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
Jadaw1ncommented, Sep 24, 2018

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. layer.setInteractive(true) or layerGroup.setInteractive(false).

2reactions
jmayer86commented, Jan 28, 2019

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');
        }
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a way to make FeatureGroup or LayerGroup un ...
L.Layer.include({ setInteractive: function (interactive) { if (this. ... Note this only works for elements that have a getElement() method.
Read more >
Interactive feature input—ArcGIS Pro | Documentation
Select a feature layer from the map. Browse to a feature class. Interactive input—add a new layer and interactively create features. Feature input...
Read more >
Touch events - Notes of Phaser 3 - GitHub Pages
Register interactive¶. Call gameObject.setInteractive(...) to register touch input of Game Object before listening touching events. Set hit area ...
Read more >
H.map.Style - HERE Developer
setInteractive (layerIds, interactive) ... Returned configuration object represents the extracted layers and can be used for creating a new H.map.
Read more >
Record Set interactive table input - Esri Community
This is done using the recordset data type (much in the same way as a feature set allows interactive drawing) and a template...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found