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

How to use data driven properties #28

Closed
dawid-niedzwiecki opened this issue Jan 9, 2023 · 4 comments
Closed

How to use data driven properties #28

dawid-niedzwiecki opened this issue Jan 9, 2023 · 4 comments

Comments

@dawid-niedzwiecki
Copy link

dawid-niedzwiecki commented Jan 9, 2023

Hello, how can I use data driven properties to pass a color for a line on LineLayer? The LineLayer object takes an int for the line-layer property, so I can't pass the ['get', 'custom-color'] to it :/ Actually that applies to any property in any type of layer...

@LjubiTech-Maxko
Copy link
Contributor

You can first add the layer with default properties and then use
mapboxMap.style.setStyleLayerProperty('layer_id', 'color', jsonEncode(['get','custom-color']))

@dawid-niedzwiecki
Copy link
Author

dawid-niedzwiecki commented Jan 10, 2023

You can first add the layer with default properties and then use mapboxMap.style.setStyleLayerProperty('layer_id', 'color', jsonEncode(['get','custom-color']))

Hey, I just tried that and I get this error:

PlatformException (PlatformException(Throwable, java.lang.Throwable: layer doesn't support this property, Cause: null, Stacktrace: java.lang.Throwable: layer doesn't support this property
	at com.mapbox.maps.mapbox_maps.StyleController.setStyleLayerProperty$lambda-18(StyleController.kt:212)
	at com.mapbox.maps.mapbox_maps.StyleController.$r8$lambda$WKv9Hkp6n6Ramjn-IsD3ANd83Co(Unknown Source:0)
	at com.mapbox.maps.mapbox_maps.StyleController$$ExternalSyntheticLambda35.onStyleLoaded(Unknown Source:8)
	at com.mapbox.maps.MapboxMap.getStyle(MapboxMap.kt:355)
	at com.mapbox.maps.mapbox_maps.StyleController.setStyleLayerProperty(StyleController.kt:208)
	at com.mapbox.maps.pigeons.FLTMapInterfaces$StyleManager$-CC.lambda$setup$15(FLTMapInterfaces.java:7200)
	at com.mapbox.maps.pigeons.FLTMapInterfaces$StyleManager$$ExternalSyntheticLambda40.onMessage(Unknown Source:2)
	at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage(BasicMessageChannel.java:217)
	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:250)
	at android.app.ActivityThread.main(ActivityThread.java:7806)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
, null))

This is how I create the layer:

await mapController.style.addSource(GeoJsonSource(id: 'styleSource', data: json.encode(geojson))); // Here geojson is a Map<String, dynamic>
await mapController.style.addLayer(
  LineLayer(
    id: 'styleLayer',
    sourceId: 'styleSource',
    lineCap: LineCap.ROUND,
    lineWidth: 3,
  ),
);
await mapController.style.setStyleLayerProperty(
  'styleLayer',
  'color',
  json.encode(['get', 'line-color']),
);

@LjubiTech-Maxko
Copy link
Contributor

Line layer does not have 'color' property, it is 'line-color'.

Check out this: https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#line

@dawid-niedzwiecki
Copy link
Author

Oh, okay, that's where the names come from :D Thanks!

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

2 participants