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

Accept multiple layers for Map#on #4578

Closed
arthurhammer opened this issue Apr 12, 2017 · 5 comments
Closed

Accept multiple layers for Map#on #4578

arthurhammer opened this issue Apr 12, 2017 · 5 comments

Comments

@arthurhammer
Copy link

#1002 (pull #4329) added a layer parameter to Map#on to handle mouse-related events for a specific layer. Currently, on accepts a single layer. It would be great if passing in an array of layers was supported. I believe this would make handling mouse-events even easier.

@arthurhammer arthurhammer changed the title Accept multiple layers parameter to Map#on Accept multiple layers for Map#on Apr 12, 2017
@mourner
Copy link
Member

mourner commented Apr 14, 2017

Thanks for creating the issue! Want to go slightly further and submit a pull request for this? Should be a quick change.

stepankuzmin added a commit to stepankuzmin/mapbox-gl-js that referenced this issue Apr 17, 2017
@stepankuzmin
Copy link
Contributor

stepankuzmin commented Apr 17, 2017

Hi there! If you don't mind, I've created PR for this issue #4596.

I'm not sure about comparing delegatedListener.layers with layers param in Map#off (see https://github.com/mapbox/mapbox-gl-js/pull/4596/files#diff-c6d02b0c73aa7597f4224ec35497cfe2R639). Should we preserve layers order in Map#off?

@jfirebaugh
Copy link
Contributor

I'm not sure about comparing delegatedListener.layers with layers param in Map#off (see https://github.com/mapbox/mapbox-gl-js/pull/4596/files#diff-c6d02b0c73aa7597f4224ec35497cfe2R639). Should we preserve layers order in Map#off?

This is a great question. Specifically, how should the following cases behave:

  • on(['a', 'b']) followed by off(['b', 'a'])
  • on(['a', 'b']) followed by off(['a'])
  • on(['a', 'b']) followed by on(['a']) followed by off(['a'])
  • on(['a', 'b']) followed by on(['a']) followed by off(['a', 'b'])
  • on(['a']) followed by on(['a', 'b']) followed by off(['a', 'b'])

The ambiguity and additional complexity of these cases makes me think we probably shouldn't implement this. If someone needs it, they can add/remove listeners in a loop.

@jfirebaugh
Copy link
Contributor

Let's keep the API simple.

@stepankuzmin
Copy link
Contributor

This actually makes sense. Thanks for review!

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

4 participants