Skip to content

Adding GeoJSON Layer in onMapCreated is unreliable #568

Description

@marcellangmaier

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:

 _onMapCreated(map.MapboxMap mapboxMap) async {
   this.mapboxMap = mapboxMap;
   await drawRoute();
 }

The method which adds the geojson layer

 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!);
 }

Simple example:
main.dart.zip
GeoJson file:
line.geojson.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions