Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

maximumbuster
Copy link
Collaborator

This is very much a WIP but shows an example of how we could create sources and layers using the native sdks. It also uses expressions parsed from text to make styling more flexible at runtime with data driven and camera driven styling.

@maximumbuster maximumbuster marked this pull request as draft May 13, 2020 23:34
Copy link
Collaborator

@tobrun tobrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff @maximumbuster, to support a real style API and making that easy to maintain, I would like to look into the possibility of generating all of this code. This is also what we do upstream for Android and iOS: eg https://github.com/mapbox/mapbox-gl-native-android/blob/master/scripts/generate-style-code.js

@maximumbuster
Copy link
Collaborator Author

@tobrun that sounds cool, you mean generate the function to convert the properties json to layer properties?

@m0nac0
Copy link
Collaborator

m0nac0 commented Jun 6, 2020

Sounds like we could use the code_builder package for that.

@tobrun
Copy link
Collaborator

tobrun commented Jun 8, 2020

@tobrun that sounds cool, you mean generate the function to convert the properties json to layer properties?

Ideally we would generate:

  • dart public API
  • iOS and Android conversion code
  • tests

Sounds like we could use the code_builder package for that.

That looks cool 😄 . Note that this approach however would result in supporting the full style-spec logic (and that would be a substantial amount of work). If we would reuse the EJS template based setup from gl-native we would only need to adapt a platform implementation of the code generator and provide EJS template files.

@Shailevy
Copy link

This looks super interesting, any updates on this?

@gregoireLem
Copy link

gregoireLem commented Feb 3, 2021

Any update ? Style layer and source would be really appreciated 👍 Our app draws more than 1000 symbols dynamically. Which makes the map very slow to draw everything

@vicobz
Copy link

vicobz commented Feb 10, 2021

We need this so much please 🙏

@maximumbuster
Copy link
Collaborator Author

Haven't worked on this for a while but I had an implementation with sources, expressions and line+symbol layers working for android and ios here: https://github.com/maximumbuster/flutter-mapbox-gl/tree/layers.

Not sure what it would take to get this merged in the main repo but feel free to copy code from my repo if you want.

Copy link
Collaborator

@felix-ht felix-ht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maximumbuster The question is how we go forward from here. This seems pretty complete.

@tobrun Adding typed interface for the properties would be great, but this seems usable and useful as it is (with a few changes). Adding proper types - with code generation - seems very much doable in a future release - especially if we do this merge with that in mind. Delaying this for another two years does not seem like a good idea.

However i agree that doing the code generation at least for the native side might be good idea.

I will implement this myself - i'll write a full implementation - with code generation.
Hopefully done in the few weeks. @maximumbuster will will base in your code tho - i hope thats fine with you!


//FIXME: Add your Mapbox access token here
static const String ACCESS_TOKEN = "YOUR_TOKEN_HERE";
static const String ACCESS_TOKEN = "pk.eyJ1Ijoib3V0d2F5LWFkbWluIiwiYSI6ImNrMnRxYnQ3bzFlNTEzbXVpNXIxZG00dG0ifQ.jt1gMJMirDNJneqN3G1O8w";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove your token

s.dependency 'Flutter'
s.dependency 'MapboxAnnotationExtension', '~> 0.0.1-beta.1'
s.dependency 'Mapbox-iOS-SDK', '~> 5.6.0'
s.dependency 'Mapbox-iOS-SDK', '~> 5.2'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this required?

init(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?, registrar: FlutterPluginRegistrar) {
if let args = args as? [String: Any] {
if let token = args["accessToken"] as? NSString{
if let token = args["accessToken"] as? String? {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the reason for this change?

void _onStyleLoadedCallback() {
controller.addSource("source_1", geojson);
controller.addLineLayer("source_1", "layer_1", {
'line-width': "[\"interpolate\", [\"linear\"], [\"zoom\"], 15.0, 1.0, 23.0, 10.0]"
Copy link
Collaborator

@felix-ht felix-ht Oct 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if you could change addLineLayer to not expect Map<string, string> and instead use Map<String, dynamic>. JsonEncode will work on anything thats also valid as an option for the parameter as the parameters are expected to work with json anyhow. As invokeMethod takes care of that you can simply pass the properties as you do now. For native you could remove the code that decodes the values, as the whole object would already have been decoded right away.

This line could then be written as:
'line-width': ["interpolate", ["linear"], ["zoom"], 15.0, 1.0, 23.0, 10.0]

which feels much less hacky. Also this has the added benefit that as invokeMethod tries to encode to json, that is whatever has been passed in is not valid json the error happens on the dart side and not in the native code.

}

void _onStyleLoadedCallback() {
controller.addSource("source_1", geojson);
Copy link
Collaborator

@felix-ht felix-ht Oct 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my other comment I would change the geojson parameter of addSource to Map<String, dynamic>. Much less hacky than messing with strings. invoke will work regardless. If someone wants really to use a string then its trivial to call jsonDecode to get a map.

'setSymbolTextIgnorePlacement() has not been implemented.');
}

Future<void> addSymbolLayer(String sourceId, String layerId, Map<String, String> properties) async {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename this to addSymbolLayerDynamic so that we can add a typed version called addSymbolLayer in the future?

await MapboxGlPlatform.getInstance(_id).addSource(sourceId, geojson);
}

Future<void> addSymbolLayer(String sourceId, String layerId, Map<String, String> properties) async {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addSymbolLayerDynamic for future typesafe version?

await MapboxGlPlatform.getInstance(_id).addSymbolLayer(sourceId, layerId, properties);
}

Future<void> addLineLayer(String sourceId, String layerId, Map<String, String> properties) async {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addLineLayerDynamic for future typesafe version?

@felix-ht
Copy link
Collaborator

closing in favor of #723

@felix-ht felix-ht closed this Nov 12, 2021
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

Successfully merging this pull request may close these issues.

7 participants