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

Commit 6ee63e8

Browse files
authored
[google_maps_flutter_web] Support for Holes in Polygons (#3412)
1 parent d950dda commit 6ee63e8

File tree

7 files changed

+94
-5
lines changed

7 files changed

+94
-5
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ Eitan Schwartz <eshvartz@gmail.com>
6060
Chris Rutkowski <chrisrutkowski89@gmail.com>
6161
Juan Alvarez <juan.alvarez@resideo.com>
6262
Aleksandr Yurkovskiy <sanekyy@gmail.com>
63+
Anton Borries <mail@antonborri.es>

packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.1.0+10
2+
3+
* Update `package:google_maps_flutter_platform_interface` to `^1.1.0`.
4+
* Add support for Polygon Holes.
5+
16
## 0.1.0+9
27

38
* Update Flutter SDK constraint.

packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ Set<Polygon> _rawOptionsToInitialPolygons(Map<String, dynamic> rawOptions) {
366366
points: rawPolygon['points']
367367
?.map<LatLng>((rawPoint) => LatLng.fromJson(rawPoint))
368368
?.toList(),
369+
holes: rawPolygon['holes']
370+
?.map<List<LatLng>>((List hole) => hole
371+
?.map<LatLng>((rawPoint) => LatLng.fromJson(rawPoint))
372+
?.toList())
373+
?.toList(),
369374
);
370375
}) ??
371376
[]);
@@ -473,9 +478,13 @@ gmaps.CircleOptions _circleOptionsFromCircle(Circle circle) {
473478

474479
gmaps.PolygonOptions _polygonOptionsFromPolygon(
475480
gmaps.GMap googleMap, Polygon polygon) {
476-
List<gmaps.LatLng> paths = [];
481+
List<gmaps.LatLng> path = [];
477482
polygon.points.forEach((point) {
478-
paths.add(_latLngToGmLatLng(point));
483+
path.add(_latLngToGmLatLng(point));
484+
});
485+
List<List<gmaps.LatLng>> paths = [path];
486+
polygon.holes?.forEach((hole) {
487+
paths.add(hole.map((point) => _latLngToGmLatLng(point)).toList());
479488
});
480489
return gmaps.PolygonOptions()
481490
..paths = paths

packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: google_maps_flutter_web
22
description: Web platform implementation of google_maps_flutter
33
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter
4-
version: 0.1.0+9
4+
version: 0.1.0+10
55

66
flutter:
77
plugin:
@@ -16,7 +16,7 @@ dependencies:
1616
flutter_web_plugins:
1717
sdk: flutter
1818
meta: ^1.1.7
19-
google_maps_flutter_platform_interface: ^1.0.5
19+
google_maps_flutter_platform_interface: ^1.1.0
2020
google_maps: ^3.4.5
2121
stream_transform: ^1.2.0
2222
sanitize_html: ^1.4.1

packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ void main() {
166166
[43.354762, -5.850824],
167167
],
168168
},
169+
{
170+
'polygonId': 'polygon-2-with-holes',
171+
'points': [
172+
[43.355114, -5.851333],
173+
[43.354797, -5.851860],
174+
[43.354469, -5.851318],
175+
[43.354762, -5.850824],
176+
],
177+
'holes': [
178+
[
179+
[41.354797, -6.851860],
180+
[41.354469, -6.851318],
181+
[41.354762, -6.850824],
182+
]
183+
]
184+
},
169185
],
170186
'polylinesToAdd': [
171187
{
@@ -202,6 +218,9 @@ void main() {
202218
expect(capturedMarkers.first.infoWindow.snippet, 'snippet for test');
203219
expect(capturedMarkers.first.infoWindow.title, 'title for test');
204220
expect(capturedPolygons.first.polygonId.value, 'polygon-1');
221+
expect(capturedPolygons.elementAt(1).polygonId.value,
222+
'polygon-2-with-holes');
223+
expect(capturedPolygons.elementAt(1).holes, isNot(null));
205224
expect(capturedPolylines.first.polylineId.value, 'polyline-1');
206225
});
207226

packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import 'dart:ui';
1010
import 'package:integration_test/integration_test.dart';
1111
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
1212
import 'package:google_maps_flutter_web/google_maps_flutter_web.dart';
13+
import 'package:google_maps/google_maps.dart' as gmaps;
14+
import 'package:google_maps/google_maps_geometry.dart' as geometry;
1315
import 'package:flutter_test/flutter_test.dart';
1416

1517
// This value is used when comparing the results of
@@ -190,6 +192,59 @@ void main() {
190192
expect(polygon.get('strokeColor'), '#c0ffee');
191193
expect(polygon.get('strokeOpacity'), closeTo(1, _acceptableDelta));
192194
});
195+
196+
testWidgets('Handle Polygons with holes', (WidgetTester tester) async {
197+
final polygons = {
198+
Polygon(
199+
polygonId: PolygonId('BermudaTriangle'),
200+
points: [
201+
LatLng(25.774, -80.19),
202+
LatLng(18.466, -66.118),
203+
LatLng(32.321, -64.757),
204+
],
205+
holes: [
206+
[
207+
LatLng(28.745, -70.579),
208+
LatLng(29.57, -67.514),
209+
LatLng(27.339, -66.668),
210+
],
211+
],
212+
),
213+
};
214+
215+
controller.addPolygons(polygons);
216+
217+
expect(controller.polygons.length, 1);
218+
expect(controller.polygons, contains(PolygonId('BermudaTriangle')));
219+
expect(controller.polygons, isNot(contains(PolygonId('66'))));
220+
});
221+
222+
testWidgets('Polygon with hole has a hole', (WidgetTester tester) async {
223+
final polygons = {
224+
Polygon(
225+
polygonId: PolygonId('BermudaTriangle'),
226+
points: [
227+
LatLng(25.774, -80.19),
228+
LatLng(18.466, -66.118),
229+
LatLng(32.321, -64.757),
230+
],
231+
holes: [
232+
[
233+
LatLng(28.745, -70.579),
234+
LatLng(29.57, -67.514),
235+
LatLng(27.339, -66.668),
236+
],
237+
],
238+
),
239+
};
240+
241+
controller.addPolygons(polygons);
242+
243+
final polygon = controller.polygons.values.first.polygon;
244+
final pointInHole = gmaps.LatLng(28.632, -68.401);
245+
246+
expect(geometry.poly.containsLocation(pointInHole, polygon), false);
247+
});
193248
});
194249

195250
group('PolylinesController', () {

packages/google_maps_flutter/google_maps_flutter_web/test/web/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<html>
66
<head>
77
<title>Browser Tests</title>
8-
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
8+
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=geometry"></script>
99
</head>
1010
<body>
1111
<script src="main.dart.js"></script>

0 commit comments

Comments
 (0)