_onMapCreated(map.MapboxMap mapboxMap) async {
this.mapboxMap = mapboxMap;
await drawRoute();
}
Future<void> drawRoute() async {
var data = await rootBundle.loadString('assets/line.geojson');
var source = map.GeoJsonSource(id: "line", data: data);
await mapboxMap?.style.addSource(source);
var lineLayer = map.LineLayer(
id: "line_layer",
sourceId: "line",
lineJoin: map.LineJoin.ROUND,
lineCap: map.LineCap.ROUND,
lineColor: Colors.red.value,
lineWidth: 6.0,
// slot: map.LayerSlot.TOP
);
await mapboxMap?.style.addLayer(lineLayer!);
}
When I add a GeoJSON Layer in onMapCreated, sometimes it gets displayed, sometimes not.
https://github.com/mapbox/mapbox-maps-flutter/assets/26068556/0027f248-5a57-46d8-ad06-332f4a6fa58e
https://github.com/mapbox/mapbox-maps-flutter/assets/26068556/856634f2-d741-45c4-85f5-178b61050aa1
pubspec.yaml: mapbox_maps_flutter: ^2.0.0-rc.1
My _onMapCreated method:
The method which adds the geojson layer
Simple example:
main.dart.zip
GeoJson file:
line.geojson.zip