Skip to content

Commit

Permalink
[google_maps_flutter_platform_interface] Adds support for holes in po…
Browse files Browse the repository at this point in the history
…lygon overlays to the Google Maps plugin (flutter#3135)
  • Loading branch information
sanekyy authored Jan 12, 2021
1 parent 71a8317 commit a0e7937
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ Kazuki Yamaguchi <[email protected]>
Eitan Schwartz <[email protected]>
Chris Rutkowski <[email protected]>
Juan Alvarez <[email protected]>
Aleksandr Yurkovskiy <[email protected]>
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0

* Add support for holes in Polygons.

## 1.0.6

* Update Flutter SDK constraint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart' show listEquals, VoidCallback;
import 'package:flutter/material.dart' show Color, Colors;
import 'package:meta/meta.dart' show immutable, required;
Expand Down Expand Up @@ -46,6 +47,7 @@ class Polygon {
this.fillColor = Colors.black,
this.geodesic = false,
this.points = const <LatLng>[],
this.holes = const <List<LatLng>>[],
this.strokeColor = Colors.black,
this.strokeWidth = 10,
this.visible = true,
Expand Down Expand Up @@ -77,6 +79,14 @@ class Polygon {
/// default; to form a closed polygon, the start and end points must be the same.
final List<LatLng> points;

/// To create an empty area within a polygon, you need to use holes.
/// To create the hole, the coordinates defining the hole path must be inside the polygon.
///
/// The vertices of the holes to be cut out of polygon.
///
/// Line segments of each points of hole are drawn inside polygon between consecutive hole points.
final List<List<LatLng>> holes;

/// True if the marker is visible.
final bool visible;

Expand Down Expand Up @@ -106,6 +116,7 @@ class Polygon {
Color fillColorParam,
bool geodesicParam,
List<LatLng> pointsParam,
List<List<LatLng>> holesParam,
Color strokeColorParam,
int strokeWidthParam,
bool visibleParam,
Expand All @@ -118,6 +129,7 @@ class Polygon {
fillColor: fillColorParam ?? fillColor,
geodesic: geodesicParam ?? geodesic,
points: pointsParam ?? points,
holes: holesParam ?? holes,
strokeColor: strokeColorParam ?? strokeColor,
strokeWidth: strokeWidthParam ?? strokeWidth,
visible: visibleParam ?? visible,
Expand Down Expand Up @@ -154,6 +166,10 @@ class Polygon {
json['points'] = _pointsToJson();
}

if (holes != null) {
json['holes'] = _holesToJson();
}

return json;
}

Expand All @@ -167,6 +183,7 @@ class Polygon {
fillColor == typedOther.fillColor &&
geodesic == typedOther.geodesic &&
listEquals(points, typedOther.points) &&
DeepCollectionEquality().equals(holes, typedOther.holes) &&
visible == typedOther.visible &&
strokeColor == typedOther.strokeColor &&
strokeWidth == typedOther.strokeWidth &&
Expand All @@ -183,4 +200,16 @@ class Polygon {
}
return result;
}

List<List<dynamic>> _holesToJson() {
final List<List<dynamic>> result = <List<dynamic>>[];
for (final List<LatLng> hole in holes) {
final List<dynamic> jsonHole = <dynamic>[];
for (final LatLng point in hole) {
jsonHole.add(point.toJson());
}
result.add(jsonHole);
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ description: A common platform interface for the google_maps_flutter plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.0.6
version: 1.1.0

dependencies:
flutter:
sdk: flutter
meta: ^1.0.5
plugin_platform_interface: ^1.0.1
stream_transform: ^1.2.0
collection: ^1.14.13

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit a0e7937

Please sign in to comment.