flutter-vector-map-tiles icon indicating copy to clipboard operation
flutter-vector-map-tiles copied to clipboard

[StyleReader] Converting JSON into a Style

Open shenlong-tanwen opened this issue 1 year ago • 7 comments

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.

shenlong-tanwen avatar Nov 09 '23 02:11 shenlong-tanwen

final jsonText = ...;
final json = jsonDecode(jsonText);
final style = ThemeReader().read(json);

josxha avatar Nov 29 '23 08:11 josxha

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

shenlong-tanwen avatar Nov 30 '23 01:11 shenlong-tanwen

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

Is there a way to somehow create a Style object out of our already read Theme object?

ibrahimcaj avatar Jan 13 '24 15:01 ibrahimcaj

Have you tried the constructor?

greensopinion avatar Feb 19 '24 19:02 greensopinion

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

Koboo avatar Aug 28 '24 08:08 Koboo

Makes sense. Similar work was started on #202 but it needs more work.

greensopinion avatar Aug 31 '24 16:08 greensopinion

I have opened #213, probably related :)

LeonP2ER avatar Sep 10 '24 08:09 LeonP2ER