Skip to content

Changing map style remove its data #2144

Closed

Description

@nicooprat

When programmatically changing a map style with map.setStyle(), all its datas are removed. Example in video: http://streamable.com/3i0w

It's not documented but I guess it's not the supposed behavior.

Activity

  1. tmcw commented on Feb 18, 2016

    @tmcw
    Contributor

    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.

  2. nicooprat commented on Feb 18, 2016

    @nicooprat
    Author

    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.

  3. tmcw commented on Feb 18, 2016

    @tmcw
    Contributor

    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.

  4. nicooprat commented on Feb 18, 2016

    @nicooprat
    Author

    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

    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.
    
  5. tmcw commented on Feb 18, 2016

    @tmcw
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions