Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[google_maps_flutter_web] Support for Holes in Polygons #3412

Merged
merged 13 commits into from
Jan 16, 2021
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ Eitan Schwartz <eshvartz@gmail.com>
Chris Rutkowski <chrisrutkowski89@gmail.com>
Juan Alvarez <juan.alvarez@resideo.com>
Aleksandr Yurkovskiy <sanekyy@gmail.com>
Anton Borries <mail@antonborri.es>
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.0+10

* Update `package:google_maps_flutter_platform_interface` to `^1.1.0`.
* Add support for Polygon Holes.

## 0.1.0+9

* Update Flutter SDK constraint.
Expand Down
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
@@ -1,7 +1,7 @@
name: google_maps_flutter_web
description: Web platform implementation of google_maps_flutter
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter
version: 0.1.0+9
version: 0.1.0+10

flutter:
plugin:
Expand All @@ -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,32 @@ 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'))));
ditman marked this conversation as resolved.
Show resolved Hide resolved
});
});

group('PolylinesController', () {
Expand Down