Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Prev Previous commit
Next Next commit
Support Holes in Polygon
  • Loading branch information
Anton Borries committed Jan 13, 2021
commit a2d607ead56ee87bc872851570d1fea85015f937
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ Set<Polygon> _rawOptionsToInitialPolygons(Map<String, dynamic> rawOptions) {
points: rawPolygon['points']
?.map<LatLng>((rawPoint) => LatLng.fromJson(rawPoint))
?.toList(),
holes: rawPolygon['holes']
?.map<List<LatLng>>((List hole) => hole
?.map<LatLng>((rawPoint) => LatLng.fromJson(rawPoint))
?.toList())
?.toList(),
);
}) ??
[]);
Expand Down Expand Up @@ -473,9 +478,13 @@ gmaps.CircleOptions _circleOptionsFromCircle(Circle circle) {

gmaps.PolygonOptions _polygonOptionsFromPolygon(
gmaps.GMap googleMap, Polygon polygon) {
List<gmaps.LatLng> paths = [];
List<gmaps.LatLng> path = [];
polygon.points.forEach((point) {
paths.add(_latLngToGmLatLng(point));
path.add(_latLngToGmLatLng(point));
});
List<List<gmaps.LatLng>> paths = [path];
polygon.holes?.forEach((hole) {
paths.add(hole.map((point) => _latLngToGmLatLng(point)).toList());
});
return gmaps.PolygonOptions()
..paths = paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
flutter_web_plugins:
sdk: flutter
meta: ^1.1.7
google_maps_flutter_platform_interface: ^1.0.5
google_maps_flutter_platform_interface: ^1.1.0
google_maps: ^3.4.5
stream_transform: ^1.2.0
sanitize_html: ^1.4.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,30 @@ void main() {
expect(polygon.get('strokeColor'), '#c0ffee');
expect(polygon.get('strokeOpacity'), closeTo(1, _acceptableDelta));
});

testWidgets('Handle Polygons with holes', (WidgetTester tester) async {
final polygons = {
Polygon(
polygonId: PolygonId('BermudaTriangle'),
points: [LatLng(25.774, -80.19),
LatLng(18.466, -66.118),
LatLng(32.321, -64.757),],
holes: [
[
LatLng(28.745, -70.579 ),
LatLng(29.57, -67.514 ),
LatLng(27.339, -66.668 ),
],
],
),
};

controller.addPolygons(polygons);

expect(controller.polygons.length, 1);
expect(controller.polygons, contains(PolygonId('BermudaTriangle')));
expect(controller.polygons, isNot(contains(PolygonId('66'))));
});
});

group('PolylinesController', () {
Expand Down