flutter-vector-map-tiles
flutter-vector-map-tiles copied to clipboard
[StyleReader] Converting JSON into a Style
Currently, it is only possible to provide a URL to fetch and read the style JSON from. For our application, we store the style JSON in our server and require a header with authentication set to fetch them, and so, we fetch them independently and receive the JSON from the server. But currently, it is not possible to parse the JSON into a Style. It would be great if the library had the ability to fetch the Style from a URL but also support parsing a JSON into a Style as well.
It would also be better if we could pass additional headers to the _httpGet method in StyleReader so we can use the existing code to fetch the Style from our servers as well.
final jsonText = ...;
final json = jsonDecode(jsonText);
final style = ThemeReader().read(json);
final jsonText = ...; final json = jsonDecode(jsonText); final style = ThemeReader().read(json);
Thank you for the suggestion. But that is for the ThemeReader which only generates a Theme object from the given JSON. What we want is a similar one, but not to generate a Theme object, but a Style object which includes the Tile providers, theme, sprites, etc. Something like a StyleReader
final jsonText = ...; final json = jsonDecode(jsonText); final style = ThemeReader().read(json);Thank you for the suggestion. But that is for the
ThemeReaderwhich only generates aThemeobject from the given JSON. What we want is a similar one, but not to generate aThemeobject, but aStyleobject which includes the Tile providers, theme, sprites, etc. Something like aStyleReader
Is there a way to somehow create a Style object out of our already read Theme object?
Have you tried the constructor?
Hey folks,
first of all, thank you @greensopinion for updating to the newest dependencies and for maintaining this library! <3
We would need a StyleReader.read(String json) method, to skip the execution of the _httpGet. I'm facing the same issue as @shenlong-tanwen because I wanted to cache styles locally as json in files.
Decoding the json myself and then using the constructor of Style could work, but would exclude the validation from the read() method and is a lot of unnecessary work here. :)
I would really appreciate a way by vector-map-tiles itself. I could also do a PR if you want me to! :)
https://github.com/greensopinion/flutter-vector-map-tiles/blob/main/lib/src/style/style.dart#L50
Makes sense. Similar work was started on #202 but it needs more work.
I have opened #213, probably related :)