mapbox / mapbox/mapbox-maps-flutter
Adding GeoJSON Layer in onMapCreated is unreliable
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 380
- Forks
- 204
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached main.dart example and the _onMapCreated and drawRoute entry points; review the mapbox_maps_flutter version in pubspec.yaml and reproduce the intermittent GeoJSON rendering with line.geojson. Done means the GeoJSON source and line layer are displayed reliably when created from onMapCreated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100