How to Create a Polygon Hole in Flutter SfMaps?
In Syncfusion® Flutter Maps, you can add a polygon hole and customize it easily by following these steps.
Step 1: Add the syncfusion_flutter_maps packages to your dependencies in the pubspec.yaml file.
Step 2: By initializing the MapPolygonLayer.inverted constructor, you can apply color to the areas other than the polygon. To do that, add MapPolygonLayer.inverted objects to the MapTileLayer sublayers collection and set the polygons collection. You can customize the MapPolygonLayer.inverted color, strokeColor, and strokeWidth properties.
late List<MapLatLng> _polygonPoints; @override void initState() { _polygonPoints = <MapLatLng>[ MapLatLng(41.04621681452063, -104.0625), MapLatLng(41.04621681452063, -102.0849609375), MapLatLng(40.01078714046552, -102.041015625), MapLatLng(40.04443758460856, -95.44921875), MapLatLng(42.48830197960227, -96.3720703125), MapLatLng(43.03677585761058, -98.4375), MapLatLng(43.068887774169625, -104.0625), MapLatLng(41.04621681452063, -104.0625), ]; super.initState(); } @override Widget build(BuildContext context) { return SfMaps( layers: [ MapTileLayer( initialZoomLevel: 4, initialFocalLatLng: MapLatLng(34.9709225,-100.2187212), urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', sublayers: [ MapPolygonLayer.inverted( polygons: [ MapPolygon( points: _polygonPoints, ) ].toSet(), color: Colors.black.withOpacity(0.5), strokeColor: Colors.purple, strokeWidth: 2.0, ), ], ), ], ); }
Screenshot
Check the following links for more features in Syncfusion® Flutter Maps:
Live samples
Conclusion
I hope you enjoyed learning about how to create a polygon hole in Flutter Maps.
You can refer to our Flutter Maps feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
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. We are always happy to assist you!