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

Add a "layers" parameter to "Evented#on" #1002

Closed
jfirebaugh opened this issue Feb 17, 2015 · 7 comments
Closed

Add a "layers" parameter to "Evented#on" #1002

jfirebaugh opened this issue Feb 17, 2015 · 7 comments
Assignees

Comments

@jfirebaugh
Copy link
Contributor

Map events should accept an optional second parameter which is the name of a layer or an array of layer names for which to delegate events. Internally, this would bind an event handler that uses featuresAt and dispatches the event only when it matches features from the given layer(s). The features themselves would be passed as a member of the event object. For example:

map.on('click', 'poi', function(e) {
    (new Popup())
        .setLatLng(e.features[0].latLng)
        .setHTML(e.features[0].properties.description)
        .addTo(map);
});

This should not require setting interactive: true for each layer separately; binding a delegated event should automatically enable interactivity for the specified layers.

@mourner
Copy link
Member

mourner commented Feb 17, 2015

This should not require setting interactive: true for each layer separately; binding a delegated event should automatically enable interactivity for the specified layers.

This may be tricky, because you need to reparse tiles when interactive for a layer changes.

@lucaswoj
Copy link
Contributor

We should do this as soon as #2224 lands

@arthurhammer
Copy link

Playing with v0.35 and pretty happy about this change. Any plans to support multiple layers to query with on?

@anandthakker
Copy link
Contributor

Seems like a doable enhancement to me -- @jfirebaugh did you encounter any subtleties in implementing this that would make this problematic?

@mourner
Copy link
Member

mourner commented Apr 11, 2017

Looks like a one-line change to me since underlying queryRenderedFeatures already accepts an array of layer ids.

@jfirebaugh
Copy link
Contributor Author

Yeah, should be straightforward. @arthurhammer can you open a new issue so we don't lose track of the request?

@arthurhammer
Copy link

Done in #4578. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants