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

[google_maps_flutter_platform_interface] Adds support for holes in polygon overlays to the Google Maps plugin #3135

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <y.kazuki0614n@gmail.com>
Eitan Schwartz <eshvartz@gmail.com>
Chris Rutkowski <chrisrutkowski89@gmail.com>
Juan Alvarez <juan.alvarez@resideo.com>
Aleksandr Yurkovskiy <sanekyy@gmail.com>
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