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

map.getStyle() after map.setFilter(id, null) returns invalid Style JSON #5637

Closed
NicolasMinghetti opened this issue Nov 9, 2017 · 3 comments
Assignees
Labels

Comments

@NicolasMinghetti
Copy link

mapbox-gl-js version 0.41.0:

Steps to Trigger Behavior

  1. Add a source and layer to mapboxGL
  2. Set the filter of the layer to null
  3. map.setStyle(map.getStyle()); throws an error

https://jsbin.com/simifaf/2/edit?html,js,console,output

Expected Behavior

Set a filter to null with map.setFilter() is allowed by mapboxGL #4777
map.setStyle() should allow layers to have filter: null

Actual Behavior

map.setStyle() throws an error if a layer has its filter to null

@anandthakker
Copy link
Contributor

@NicolasMinghetti thanks for reporting this issue, and for including a test case!

It's true that Map#setFilter() accepts null as a way to remove a layer's filter. However, Map#setStyle() (and, similarly, Map#addLayer()) expect layers that conform to the Mapbox GL Style Specification, which doesn't currently allow for filter to be null.

If you want to remove a layer's filter via setStyle, you can do so by omitting the filter: property from the layer (rather than setting it to null or undefined)

@jrd
Copy link

jrd commented Nov 9, 2017

But then map.getStyle() should conform to the Mapbox GL Style Specification.
Why getStyle() returns layers with a filter attribute value as null?

You're right, setStyle() is doing the right job, but getStyle() does not.

@anandthakker
Copy link
Contributor

Ah - good point @jrd -- I'll reopen this and change the title to reflect that issue.

@anandthakker anandthakker reopened this Nov 9, 2017
@anandthakker anandthakker changed the title map.setSyle() throws an error when layer has filter= null map.getStyle() after map.setFilter(id, null) returns invalid Style JSON Nov 9, 2017
@jfirebaugh jfirebaugh self-assigned this Nov 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants