Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

mbgl::style::Style::getJSON should update according to runtime styling #12229

Closed
brunoabinader opened this issue Jun 27, 2018 · 3 comments
Closed
Labels
Core The cross-platform C++ core, aka mbgl feature GL JS parity For feature parity with Mapbox GL JS

Comments

@brunoabinader
Copy link
Member

In GL JS, map.getStyle() invokes style.serialize(), which serializes the current state stylesheet state. This means that every runtime styling change is going to affect the layer property values on the returned JSON object.

In GL Native, mbgl::style::Style::getJSON returns the same original style JSON set via either mbgl::style::Style::loadJSON or mbgl::style::Style::getURL.

We should follow GJ JS approach and keep the returned JSON up-to-date with the runtime styling changes.

@brunoabinader brunoabinader added feature GL JS parity For feature parity with Mapbox GL JS Core The cross-platform C++ core, aka mbgl labels Jun 27, 2018
@brunoabinader
Copy link
Member Author

/cc @mapbox/gl-core

@brunoabinader
Copy link
Member Author

To accomplish this, we could adopt the following plan:

  1. Add mbgl::style::Layer::asJSON() and mbgl::style::Source::asJSON(), and generate mbgl::style::Style::getJSON on the fly, or

  2. Adopt source/layer update observers in the style object that would eventually update the internal JSON stylesheet upon changes

Option 2) is tricky because it requires traversing the JSON to update individual entries on each runtime style change, but provides O(1) results for getJSON. Thus, I find option 1) more compelling as it keeps parity with GL JS implementation, and getJSON does not seem like a function that needs to be called multiple times.

Adding {Layer,Source}::asJSON requires a serialization mechanism similar to Conversion::stringify.

@jfirebaugh
Copy link
Contributor

Duplicate of #7563.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl feature GL JS parity For feature parity with Mapbox GL JS
Projects
None yet
Development

No branches or pull requests

2 participants