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

"once" event on specific layer throws an error #9059

Closed
cs09g opened this issue Dec 4, 2019 · 4 comments
Closed

"once" event on specific layer throws an error #9059

cs09g opened this issue Dec 4, 2019 · 4 comments

Comments

@cs09g
Copy link
Contributor

cs09g commented Dec 4, 2019

mapbox-gl-js version:
v1.5.0

browser:
latest chrome

Steps to Trigger Behavior

  1. add geojson layer
  2. add once event on the layer
  3. dispatch the event

Link to Demonstration

https://jsfiddle.net/cs09g/3rdf45ox/

Expected Behavior

the handler should be fired once.

Actual Behavior

error message in console

BTW, is once method deprecated? It's missing from API docs.

@kkaefer
Copy link
Member

kkaefer commented Dec 4, 2019

@cs09g the demo you linked doesn't include a callback function. That means the code that's trying to invoke the function fails. However, it looks like the linked JSFiddle might be incomplete. Can you check that it is indeed what you intended to post?

@cs09g
Copy link
Contributor Author

cs09g commented Dec 4, 2019

@kkaefer oops, could you check the fiddle again? click the gray line on the map.

FYI, the missing code is

map.once("click", "route", (e) => {
  console.log(e);
});

@kkaefer
Copy link
Member

kkaefer commented Dec 4, 2019

The syntax allowing specifying the layer ID is only implemented for on, not for once. It's a little bit unfortunate since the Map object's on method overrides the Evented class' on method, inserting the layerId parameter in the middle. No such override exists for once, which is why it's not listed on the API documentation.

@kkaefer kkaefer closed this as completed Dec 4, 2019
@ryanhamley
Copy link
Contributor

ryanhamley commented Dec 4, 2019

There's an open PR to add this exact functionality if you'd like to give it a review @kkaefer. I worked on it with the author so I can't review it as well. #8875

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

3 participants