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

Draw plugin breaks when map style changes #512

Closed
Naimikan opened this issue Sep 28, 2016 · 15 comments
Closed

Draw plugin breaks when map style changes #512

Naimikan opened this issue Sep 28, 2016 · 15 comments

Comments

@Naimikan
Copy link

When I draw something on map and I change the map style, draw plugin breaks and I can't draw anything more. Draw plugin throws me this error:

"The layer 'gl-draw-polygon-fill-inactive.cold' does not exist in the map's style and cannot be queried for features."

Example:
http://codepen.io/Naimikan/pen/JRJOVN?editors=1111

I want to draw a polygon on style, save it, change style and continue drawing other polygons on other styles. I think I have to create style's layer on style change because style change won't do it by itself.

@mcwhittemore
Copy link
Contributor

@Naimikan your codepen is not working for me. That said, you cannot use map.setStyle with Draw as of right now. Moving from satellite to streets destroys the layers added by Draw. This could be handled by Draw if Draw listened to style change events and rebuilt the layers needed by Draw if they had been destroyed.

@guillec
Copy link

guillec commented Nov 7, 2016

@Naimikan @mcwhittemore is there a work around for this?
I have the same problem and need.

Best,

@mcwhittemore
Copy link
Contributor

@guillec - I don't think I'll have the space to do this in the next few weeks, but I am more than willing to work with someone on a PR and get this merged.

@jisaacks
Copy link
Contributor

jisaacks commented Nov 9, 2016

@mcwhittemore I am having this issue as well. Can you describe to me what is causing the problem and how I may address it. Happy to work on a PR.

@mcwhittemore
Copy link
Contributor

@jisaacks - When the style of the map is changed the custom map layers that Draw requires are destroyed but Draw doesn't know this so it keeps trying to reference them which results in the above errors. The solution is to listen to the style change event and make sure that after it is fired, the map still has the required layers. If it does not, they should be added.

@guillec
Copy link

guillec commented Nov 9, 2016

@jisaacks @mcwhittemore thank you guys!

@Naimikan
Copy link
Author

@jisaacks @mcwhittemore thanks!

@jisaacks
Copy link
Contributor

@mcwhittemore There doesn't seem to be any events fired when the style is changed Do you have any advice on how to listen for the style change. Should I make a PR to mapbox-gl-js to add an event?

@mcwhittemore
Copy link
Contributor

mcwhittemore commented Nov 10, 2016

@jisaacks - The render event is the best option I see.

@lucaswoj - is there a better way to detect style changes than the render event?

@mcwhittemore
Copy link
Contributor

mcwhittemore commented Nov 10, 2016

I just talked with @lucaswoj. The data is what we should use.

image

@lucaswoj
Copy link

lucaswoj commented Nov 10, 2016

👍 note that we're going to be adding a styledata event very soon which will be even more specific to style changes mapbox/mapbox-gl-js#3578

@jisaacks
Copy link
Contributor

@mcwhittemore @lucaswoj I added a PR #540 or are y'all wanting to wait until mapbox/mapbox-gl-js#3578 is released and use that?

@samanpwbb
Copy link
Contributor

Here's a solution that has worked well for the Mapbox team in the past – use two maps: #494 (comment)

@jisaacks
Copy link
Contributor

@samanpwbb that would require everyone who uses multple styles to unnecesarily have to do this duplicate map hack. What if they wanted to use several styles, etc. It just seems like we should fix the issue and not force users to use work-arounds. PR #540 fixes the errors and even keeps the polygons when changing map.

@mcwhittemore
Copy link
Contributor

@jisaacks - sorry for the delay here, I've been out on family leave. I'll get to reviewing this today.

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

Successfully merging a pull request may close this issue.

6 participants