Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[StyleReader] Converting JSON into a Style #183

Open
shenlong-tanwen opened this issue Nov 9, 2023 · 7 comments
Open

[StyleReader] Converting JSON into a Style #183

shenlong-tanwen opened this issue Nov 9, 2023 · 7 comments

Comments

@shenlong-tanwen
Copy link

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.

@josxha
Copy link
Contributor

josxha commented Nov 29, 2023

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

@shenlong-tanwen
Copy link
Author

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

@ibrahimcaj
Copy link

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?

@greensopinion
Copy link
Owner

Have you tried the constructor?

@Koboo
Copy link

Koboo commented Aug 28, 2024

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

@greensopinion
Copy link
Owner

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

@LeonP2ER
Copy link
Contributor

I have opened #213, probably related :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants