Skip to content

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

Closed

Description

@jfirebaugh

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.

Activity

  1. mourner commented on Feb 17, 2015

    @mourner
    Member

    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.

  2. lucaswoj commented on Mar 15, 2016

    @lucaswoj
    Contributor

    We should do this as soon as #2224 lands

  3. changed the title [-]`layer`/`layers` parameter for delegated events[/-] [+]Add a "layers" parameter to "Evented#on" [/+] on Jul 28, 2016
  4. self-assigned this
    on Mar 30, 2017
  5. arthurhammer commented on Apr 11, 2017

    @arthurhammer

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

  6. anandthakker commented on Apr 11, 2017

    @anandthakker
    Contributor

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

  7. mourner commented on Apr 11, 2017

    @mourner
    Member

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

  8. jfirebaugh commented on Apr 11, 2017

    @jfirebaugh
    ContributorAuthor

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

  9. arthurhammer commented on Apr 12, 2017

    @arthurhammer

    Done in #4578. Thanks!

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions