mapbox / mapbox-maps-flutter

Interactive, thoroughly customizable maps for Flutter powered by Mapbox Maps SDK
https://www.mapbox.com/mobile-maps-sdk
Other
291 stars 119 forks source link

Polygons from GeoJson #200

Open ilyosbekkk opened 1 year ago

ilyosbekkk commented 1 year ago

I am trying to draw polygons on the map and in example section of this repository polygons are drawn using Polygon annotations. I fetch geoJson from backend, so is there any ways to draw polygons right from this geoJson without using annotations?

asianrider commented 1 year ago

You can create a source using the geojson:

mapboxMap.style.addSource(GeoJsonSource(id: 'myPolygons', data: jsonEncode(myGeoJson)));
mapboxMap.style.addLayer(FillLayer(id: 'polys', sourceId: 'myPolygons', fillColor: 0xff0000));
aardrop commented 8 months ago

@asianrider, that didn't work for me, at least not for a list. What class is your "myGeoJson" for your polygons? In the examples on the project, they are adding single objects like LineString but no collections of objects or multiple ones, so there are no examples of this that I can find.