You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How are you adding the data to the map - by addSource and addLayer? If so, those API calls are adding properties to the style. So, setting the style replaces it, including the things you added: there is no concept of overlay or 'added data' in mapbox gl js, it is all one map.
Yes I'm using addSource and addLayer. Ok I understand, so maybe it should be clarified in the docs? I guess I'm not the only who has been be surprised :) Thanks for your fast answer.
Do you have an idea of how this could be clarified? I think our docs are pretty explicit about the actual behavior of the library, and the expectation that setStyle won't affect a modified style (or that addSource modifies something other than the style) is a misapplied assumption from other mapping libraries.
setStyle (style)
Replaces the map's style object. Remember: addSource and addLayer API calls are adding properties to the style. So, setting the style replaces it, including the things you added.
I don't think that this is a good addition to documentation. The same is true of setFilter calls, and everything else that explicitly says that it changes styles in the documentation. While it's unfortunate that this cost you some time, our documentation only has space to say what the behavior is, not the many things it isn't.
Reacted by Jefferson Francisco, Tomer Borenstein, Nick Coronado, Ben Sainsbury, Louis Haddrell, Rosamund Pearce, Gaspar Karm, mdajab, clem, ROTGP and 6 more
Activity
tmcw commentedon Feb 18, 2016
How are you adding the data to the map - by addSource and addLayer? If so, those API calls are adding properties to the style. So, setting the style replaces it, including the things you added: there is no concept of overlay or 'added data' in mapbox gl js, it is all one map.
nicooprat commentedon Feb 18, 2016
Yes I'm using
addSourceandaddLayer. Ok I understand, so maybe it should be clarified in the docs? I guess I'm not the only who has been be surprised :) Thanks for your fast answer.tmcw commentedon Feb 18, 2016
Do you have an idea of how this could be clarified? I think our docs are pretty explicit about the actual behavior of the library, and the expectation that setStyle won't affect a modified style (or that addSource modifies something other than the style) is a misapplied assumption from other mapping libraries.
nicooprat commentedon Feb 18, 2016
Yeah Mapbox docs are pretty clear indeed, but despite having spent some hours reading it again and again, this behavior looked like a bug to me :) So I think what you just explained could be added here in the docs: https://www.mapbox.com/mapbox-gl-js/api/#Map.setStyle
tmcw commentedon Feb 18, 2016
I don't think that this is a good addition to documentation. The same is true of setFilter calls, and everything else that explicitly says that it changes styles in the documentation. While it's unfortunate that this cost you some time, our documentation only has space to say what the behavior is, not the many things it isn't.