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

[google_maps_flutter] Adds support for holes in polygon overlays to the Google Maps plugin #1721

Merged
merged 62 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
76d56ca
Adds support for holes in polygon overlays to the Google Maps plugin
sanekyy Jun 10, 2019
8826721
Add name and contact info to the AUTHORS file
sanekyy Jun 10, 2019
9252dc4
fix holes generating in example
sanekyy Jun 17, 2019
a4eeab5
Merge branch 'master' into polygon_holes
sanekyy Jun 17, 2019
1b26908
merge with upstream/master
sanekyy Jun 17, 2019
01bd55c
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Jun 20, 2019
69d3889
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Jun 20, 2019
18137c2
change version to 0.5.19
sanekyy Jun 20, 2019
a86e25f
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Jun 21, 2019
e866736
change version to 0.5.20
sanekyy Jun 21, 2019
0d404b4
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Jun 25, 2019
32ee443
fix format
sanekyy Jun 27, 2019
71c45b5
Merge remote-tracking branch 'upstream/master'
sanekyy Jun 27, 2019
4f24a58
Merge branch 'polygon_holes'
sanekyy Jun 27, 2019
5233c0d
fix format
sanekyy Jun 27, 2019
a952a34
Merge remote-tracking branch 'upstream/master'
sanekyy Jul 5, 2019
1faf0d4
Merge branch 'master' into polygon_holes
sanekyy Jul 5, 2019
b4ae7bf
Merge remote-tracking branch 'upstream/master'
sanekyy Jul 11, 2019
49d08b3
Merge branch 'master' into polygon_holes
sanekyy Jul 11, 2019
b526132
Merge remote-tracking branch 'upstream/master'
sanekyy Jul 20, 2019
2d55631
Merge branch 'master' into polygon_holes
sanekyy Jul 20, 2019
7871f33
Merge remote-tracking branch 'upstream/master'
sanekyy Jul 26, 2019
185f67b
Merge branch 'master' into polygon_holes
sanekyy Jul 26, 2019
14136d5
Merge remote-tracking branch 'upstream/master'
sanekyy Sep 4, 2019
4283ce0
Merge branch 'master' into polygon_holes
sanekyy Sep 4, 2019
af1c9b0
add additional documentation about what is a hole
sanekyy Sep 4, 2019
0461f32
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Sep 10, 2019
13dd5cf
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Dec 21, 2019
c563086
fix polygon compare
sanekyy Dec 23, 2019
2516df5
apply format
sanekyy Dec 23, 2019
38ca9e9
add collection package to dependencies
sanekyy Dec 23, 2019
df66101
fix version
sanekyy Dec 23, 2019
c515201
fix collection dependency version
sanekyy Dec 23, 2019
47e5f60
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Jan 14, 2020
6b970c8
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Jan 24, 2020
1b2c8ef
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Feb 1, 2020
cfd96b6
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Feb 17, 2020
d2c06dc
Update packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md
sanekyy Feb 21, 2020
d377276
renaming
sanekyy Feb 21, 2020
17b0e6f
add comment
sanekyy Feb 21, 2020
9f83f73
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Feb 21, 2020
dd9e6e5
Merge remote-tracking branch 'origin/polygon_holes' into polygon_holes
sanekyy Feb 21, 2020
8d3d94f
use explicit return type List<dynamic> instead of dynamic
sanekyy Feb 21, 2020
c69d178
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Mar 18, 2020
0d2a84c
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Mar 31, 2020
aa140a0
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy May 2, 2020
a603d00
fix issues after merge upstream
sanekyy May 2, 2020
1496272
fix serializing, add tests
sanekyy May 2, 2020
63cbca9
workaround for success build checks in PR
sanekyy May 2, 2020
2a8837d
cleanup
sanekyy May 3, 2020
fedafd7
bump google_maps_flutter_platform_interface version
sanekyy May 3, 2020
33e926e
fix collection package version
sanekyy May 3, 2020
4553a61
Merge branch 'master' into polygon_holes
sanekyy Jul 23, 2020
6ef0253
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Aug 13, 2020
f4673a3
Merge remote-tracking branch 'origin/polygon_holes' into polygon_holes
sanekyy Aug 13, 2020
b082a41
fix merge issues
sanekyy Aug 13, 2020
9dea297
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Oct 5, 2020
9802260
remove empty line
sanekyy Oct 5, 2020
7a9b266
1.0.3 -> 1.1.0
sanekyy Oct 5, 2020
febcd31
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Jan 13, 2021
a5e6a5c
bump google_maps_flutter_platform_interface version
sanekyy Jan 13, 2021
d1480e1
Fix deprecated `FlatButton`
Jan 13, 2021
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
6 changes: 3 additions & 3 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ Lukasz Piliszczuk <lukasz@intheloup.io>
SoundReply Solutions GmbH <ch@soundreply.com>
Rafal Wachol <rwachol@gmail.com>
Pau Picas <pau.picas@gmail.com>
Christian Weder <chrstian.weder@yapeal.ch>
Alexandru Tuca <salexandru.tuca@outlook.com>
Christian Weder <chrstian.weder@yapeal.ch>Alexandru Tuca <salexandru.tuca@outlook.com>
Christian Weder <chrstian.weder@yapeal.ch>
Rhodes Davis Jr. <rody.davis.jr@gmail.com>
Luigi Agosti <luigi@tengio.com>
Expand All @@ -56,4 +55,5 @@ Giancarlo Rocha <giancarloiff@gmail.com>
Ryo Miyake <ryo@miyake.id>
Théo Champion <contact.theochampion@gmail.com>
Kazuki Yamaguchi <y.kazuki0614n@gmail.com>
Eitan Schwartz <eshvartz@gmail.com>
Eitan Schwartz <eshvartz@gmail.com>
Aleksandr Yurkovskiy <sanekyy@gmail.com>
4 changes: 4 additions & 0 deletions packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.28

* Add support for holes in Polygons.

## 0.5.27

* Migrate the core plugin to use `google_maps_flutter_platform_interface` APIs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ static String interpretPolygonOptions(Object o, PolygonOptionsSink sink) {
if (points != null) {
sink.setPoints(toPoints(points));
}
final Object holes = data.get("holes");
if (holes != null) {
sink.setHoles(toHoles(holes));
}
final String polygonId = (String) data.get("polygonId");
if (polygonId == null) {
throw new IllegalArgumentException("polygonId was null");
Expand Down Expand Up @@ -556,13 +560,23 @@ private static List<LatLng> toPoints(Object o) {
final List<?> data = toList(o);
final List<LatLng> points = new ArrayList<>(data.size());

for (Object ob : data) {
final List<?> point = toList(ob);
for (Object rawPoint : data) {
final List<?> point = toList(rawPoint);
points.add(new LatLng(toFloat(point.get(0)), toFloat(point.get(1))));
}
return points;
}

private static List<List<LatLng>> toHoles(Object o) {
final List<?> data = toList(o);
final List<List<LatLng>> holes = new ArrayList<>(data.size());

for (Object rawHole : data) {
holes.add(toPoints(rawHole));
}
return holes;
}

private static List<PatternItem> toPattern(Object o) {
final List<?> data = toList(o);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public void setPoints(List<LatLng> points) {
polygonOptions.addAll(points);
}

@Override
public void setHoles(List<List<LatLng>> holes) {
for (List<LatLng> hole : holes) {
polygonOptions.addHole(hole);
}
}

@Override
public void setConsumeTapEvents(boolean consumeTapEvents) {
this.consumeTapEvents = consumeTapEvents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public void setPoints(List<LatLng> points) {
polygon.setPoints(points);
}

public void setHoles(List<List<LatLng>> holes) {
polygon.setHoles(holes);
}

@Override
public void setVisible(boolean visible) {
polygon.setVisible(visible);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface PolygonOptionsSink {

void setPoints(List<LatLng> points);

void setHoles(List<List<LatLng>> holes);

void setVisible(boolean visible);

void setStrokeWidth(float width);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class PlacePolygonBodyState extends State<PlacePolygonBody> {

GoogleMapController controller;
Map<PolygonId, Polygon> polygons = <PolygonId, Polygon>{};
int _polygonIdCounter = 1;
Map<PolygonId, double> polygonOffsets = <PolygonId, double>{};
int _polygonIdCounter = 0;
PolygonId selectedPolygon;

// Values when toggling polygon color
Expand Down Expand Up @@ -79,7 +80,6 @@ class PlacePolygonBodyState extends State<PlacePolygonBody> {
}

final String polygonIdVal = 'polygon_id_$_polygonIdCounter';
_polygonIdCounter++;
final PolygonId polygonId = PolygonId(polygonIdVal);

final Polygon polygon = Polygon(
Expand All @@ -96,6 +96,9 @@ class PlacePolygonBodyState extends State<PlacePolygonBody> {

setState(() {
polygons[polygonId] = polygon;
polygonOffsets[polygonId] = _polygonIdCounter.ceilToDouble();
// increment _polygonIdCounter to have unique polygon id each time
_polygonIdCounter++;
});
}

Expand Down Expand Up @@ -144,6 +147,22 @@ class PlacePolygonBodyState extends State<PlacePolygonBody> {
});
}

void _addHoles() {
final Polygon polygon = polygons[selectedPolygon];
setState(() {
polygons[selectedPolygon] = polygon.copyWith(holesParam: _createHoles());
});
}

void _removeHoles() {
final Polygon polygon = polygons[selectedPolygon];
setState(() {
polygons[selectedPolygon] = polygon.copyWith(
holesParam: <List<LatLng>>[],
);
});
}

@override
Widget build(BuildContext context) {
return Column(
Expand Down Expand Up @@ -196,6 +215,22 @@ class PlacePolygonBodyState extends State<PlacePolygonBody> {
),
Column(
children: <Widget>[
FlatButton(
child: const Text('add holes'),
onPressed: (selectedPolygon == null)
? null
: ((polygons[selectedPolygon].holes.isNotEmpty)
? null
: _addHoles),
),
FlatButton(
child: const Text('remove holes'),
onPressed: (selectedPolygon == null)
? null
: ((polygons[selectedPolygon].holes.isEmpty)
? null
: _removeHoles),
),
FlatButton(
child: const Text('change stroke width'),
onPressed:
Expand Down Expand Up @@ -235,6 +270,27 @@ class PlacePolygonBodyState extends State<PlacePolygonBody> {
return points;
}

List<List<LatLng>> _createHoles() {
final List<List<LatLng>> holes = <List<LatLng>>[];
final double offset = polygonOffsets[selectedPolygon];

final List<LatLng> hole1 = <LatLng>[];
hole1.add(_createLatLng(51.8395 + offset, -3.8814));
hole1.add(_createLatLng(52.0234 + offset, -3.9914));
hole1.add(_createLatLng(52.1351 + offset, -4.4435));
hole1.add(_createLatLng(52.0231 + offset, -4.5829));
holes.add(hole1);

final List<LatLng> hole2 = <LatLng>[];
hole2.add(_createLatLng(52.2395 + offset, -3.6814));
hole2.add(_createLatLng(52.4234 + offset, -3.7914));
hole2.add(_createLatLng(52.5351 + offset, -4.2435));
hole2.add(_createLatLng(52.4231 + offset, -4.3829));
holes.add(hole2);

return holes;
}

LatLng _createLatLng(double lat, double lng) {
return LatLng(lat, lng);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- (void)setStrokeColor:(UIColor*)color;
- (void)setStrokeWidth:(CGFloat)width;
- (void)setPoints:(NSArray<CLLocation*>*)points;
- (void)setHoles:(NSArray<NSArray<CLLocation*>*>*)holes;
- (void)setZIndex:(int)zIndex;
@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ - (void)setPoints:(NSArray<CLLocation*>*)points {
}
_polygon.path = path;
}
- (void)setHoles:(NSArray<NSArray<CLLocation*>*>*)rawHoles {
NSMutableArray<GMSMutablePath*>* holes = [[NSMutableArray<GMSMutablePath*> alloc] init];

for (NSArray<CLLocation*>* points in rawHoles) {
GMSMutablePath* path = [GMSMutablePath path];
for (CLLocation* location in points) {
[path addCoordinate:location.coordinate];
}
[holes addObject:path];
}

_polygon.holes = holes;
}

- (void)setFillColor:(UIColor*)color {
_polygon.fillColor = color;
Expand All @@ -65,6 +78,10 @@ - (void)setStrokeWidth:(CGFloat)width {
return [FLTGoogleMapJsonConversions toPoints:data];
}

static NSArray<NSArray<CLLocation*>*>* ToHoles(NSArray<NSArray*>* data) {
return [FLTGoogleMapJsonConversions toHoles:data];
}

static UIColor* ToColor(NSNumber* data) { return [FLTGoogleMapJsonConversions toColor:data]; }

static void InterpretPolygonOptions(NSDictionary* data, id<FLTGoogleMapPolygonOptionsSink> sink,
Expand All @@ -89,6 +106,11 @@ static void InterpretPolygonOptions(NSDictionary* data, id<FLTGoogleMapPolygonOp
[sink setPoints:ToPoints(points)];
}

NSArray* holes = data[@"holes"];
if (holes) {
[sink setHoles:ToHoles(holes)];
}

NSNumber* fillColor = data[@"fillColor"];
if (fillColor != nil) {
[sink setFillColor:ToColor(fillColor)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
+ (NSArray*)positionToJson:(CLLocationCoordinate2D)position;
+ (UIColor*)toColor:(NSNumber*)data;
+ (NSArray<CLLocation*>*)toPoints:(NSArray*)data;
+ (NSArray<NSArray<CLLocation*>*>*)toHoles:(NSArray*)data;
@end
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ + (UIColor*)toColor:(NSNumber*)numberColor {
return points;
}

+ (NSArray<NSArray<CLLocation*>*>*)toHoles:(NSArray*)data {
NSMutableArray<NSArray<CLLocation*>*>* holes = [[[NSMutableArray alloc] init] init];
for (unsigned i = 0; i < [data count]; i++) {
NSArray<CLLocation*>* points = [FLTGoogleMapJsonConversions toPoints:data[i]];
[holes addObject:points];
}

return holes;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:google_maps_flutter_platform_interface/src/method_channel/method_channel_google_maps_flutter.dart';

Expand Down Expand Up @@ -45,4 +44,5 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
ScreenCoordinate;

part 'src/controller.dart';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

part 'src/google_map.dart';
11 changes: 9 additions & 2 deletions packages/google_maps_flutter/google_maps_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
name: google_maps_flutter
description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter
version: 0.5.27
version: 0.5.28

dependencies:
flutter:
sdk: flutter
flutter_plugin_android_lifecycle: ^1.0.0
google_maps_flutter_platform_interface: ^1.0.1
google_maps_flutter_platform_interface: #^1.0.2
# workaround for success build checks in PR
git:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this workaround be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. But now build checks will failed.

url: git://github.com/sanekyy/plugins.git
ref: polygon_holes
path: packages/google_maps_flutter/google_maps_flutter_platform_interface



dev_dependencies:
flutter_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,14 @@ class FakePlatformGoogleMap {
final bool visible = polygonData['visible'];
final bool geodesic = polygonData['geodesic'];
final List<LatLng> points = _deserializePoints(polygonData['points']);
final List<List<LatLng>> holes = _deserializeHoles(polygonData['holes']);

result.add(Polygon(
polygonId: PolygonId(polygonId),
visible: visible,
geodesic: geodesic,
points: points,
holes: holes,
));
}

Expand All @@ -218,6 +220,14 @@ class FakePlatformGoogleMap {
}).toList();
}

List<List<LatLng>> _deserializeHoles(List<dynamic> holes) {
return holes.map<List<LatLng>>((dynamic hole) {
return hole.map<LatLng>((dynamic list) {
return LatLng(list[0], list[1]);
}).toList();
}).toList();
}

void updatePolylines(Map<dynamic, dynamic> polylineUpdates) {
if (polylineUpdates == null) {
return;
Expand Down
Loading