How to add/draw polygons in Flutter Maps?
In Flutter Maps, you can add polygon and customize it easily by following the below steps.
Step 1: Add syncfusion_flutter_maps packages to your dependencies in pubspec.yaml file.
Step 2: Initialize the polygon points in the initState() method.
late List<MapLatLng> _polygon; @override void initState() { _polygon = <MapLatLng>[ MapLatLng(32.3078, -64.7505), MapLatLng(25.7617, -80.1918), MapLatLng(18.4655, -66.1057), ]; super.initState(); }
Step 3: Add MapPolygonLayer to the MapTileLayer sublayers property and set the polygon points to the MapPolygonLayer polygons property. You can customize polygon by using MapPolygonLayer color, stroke color and stroke width property.
@override Widget build(BuildContext context) { return SfMaps( layers: [ MapTileLayer( initialZoomLevel: 5, initialFocalLatLng: MapLatLng(25.7617, -72.1918), urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', sublayers: [ MapPolygonLayer( polygons: [ MapPolygon( points: _polygon, color: Colors.pink[200], strokeColor: Colors.pink[800], strokeWidth: 3, ) ].toSet(), ), ], ), ], ); }
Screenshot:
Check the below links for more features in Syncfusion® Flutter Maps.
- https://www.syncfusion.com/flutter-widgets/flutter-maps
- https://help.syncfusion.com/flutter/maps/vector-layers/polygon-layer
- https://pub.dev/packages/syncfusion_flutter_maps
Live samples,
- https://flutter.syncfusion.com/#/maps/shape-layer/range-color-mapping
- https://play.google.com/store/apps/details?id=com.syncfusion.flutter.examples
- https://apps.apple.com/us/app/syncfusion-flutter-ui-widgets/id1475231341
Conclusion
I hope you enjoyed learning about how to add/draw polygons in Flutter Maps.
You can refer to our Flutter Maps feature tour page to know about its other groundbreaking feature representations. You can also explore our Flutter Maps documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!