Skip to content

Commit 50e4138

Browse files
[google_maps_flutter_android] Convert PlatformPolygon and PlatformPolyline to Pigeon (#7406)
Replace the old JSON-based encoding of polygons and polylines to use structured pigeon type. flutter/flutter#152926 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use `dart format`.) - [ ] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes]. - [x] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [pub versioning philosophy]: https://dart.dev/tools/pub/versioning [exempt from version changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version [following repository CHANGELOG style]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style [exempt from CHANGELOG changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog [test-exempt]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
1 parent 6dd3e4e commit 50e4138

File tree

11 files changed

+910
-220
lines changed

11 files changed

+910
-220
lines changed

packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.14.3
2+
3+
* Converts `PlatformPolygon` and `PlatformPolyline` to pigeon.
4+
15
## 2.14.2
26

37
* Bumps `com.android.tools.build:gradle` from 7.3.1 to 8.5.1.

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java

Lines changed: 33 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -690,103 +690,36 @@ private static void interpretInfoWindowOptions(
690690
infoWindowAnchor.getDx().floatValue(), infoWindowAnchor.getDy().floatValue());
691691
}
692692

693-
static String interpretPolygonOptions(Map<String, ?> data, PolygonOptionsSink sink) {
694-
final Object consumeTapEvents = data.get("consumeTapEvents");
695-
if (consumeTapEvents != null) {
696-
sink.setConsumeTapEvents(toBoolean(consumeTapEvents));
697-
}
698-
final Object geodesic = data.get("geodesic");
699-
if (geodesic != null) {
700-
sink.setGeodesic(toBoolean(geodesic));
701-
}
702-
final Object visible = data.get("visible");
703-
if (visible != null) {
704-
sink.setVisible(toBoolean(visible));
705-
}
706-
final Object fillColor = data.get("fillColor");
707-
if (fillColor != null) {
708-
sink.setFillColor(toInt(fillColor));
709-
}
710-
final Object strokeColor = data.get("strokeColor");
711-
if (strokeColor != null) {
712-
sink.setStrokeColor(toInt(strokeColor));
713-
}
714-
final Object strokeWidth = data.get("strokeWidth");
715-
if (strokeWidth != null) {
716-
sink.setStrokeWidth(toInt(strokeWidth));
717-
}
718-
final Object zIndex = data.get("zIndex");
719-
if (zIndex != null) {
720-
sink.setZIndex(toFloat(zIndex));
721-
}
722-
final Object points = data.get("points");
723-
if (points != null) {
724-
sink.setPoints(toPoints(points));
725-
}
726-
final Object holes = data.get("holes");
727-
if (holes != null) {
728-
sink.setHoles(toHoles(holes));
729-
}
730-
final String polygonId = (String) data.get("polygonId");
731-
if (polygonId == null) {
732-
throw new IllegalArgumentException("polygonId was null");
733-
} else {
734-
return polygonId;
735-
}
693+
static String interpretPolygonOptions(Messages.PlatformPolygon polygon, PolygonOptionsSink sink) {
694+
sink.setConsumeTapEvents(polygon.getConsumesTapEvents());
695+
sink.setGeodesic(polygon.getGeodesic());
696+
sink.setVisible(polygon.getVisible());
697+
sink.setFillColor(polygon.getFillColor().intValue());
698+
sink.setStrokeColor(polygon.getStrokeColor().intValue());
699+
sink.setStrokeWidth(polygon.getStrokeWidth());
700+
sink.setZIndex(polygon.getZIndex());
701+
sink.setPoints(pointsFromPigeon(polygon.getPoints()));
702+
sink.setHoles(toHoles(polygon.getHoles()));
703+
return polygon.getPolygonId();
736704
}
737705

738706
static String interpretPolylineOptions(
739-
Map<String, ?> data, PolylineOptionsSink sink, AssetManager assetManager, float density) {
740-
final Object consumeTapEvents = data.get("consumeTapEvents");
741-
if (consumeTapEvents != null) {
742-
sink.setConsumeTapEvents(toBoolean(consumeTapEvents));
743-
}
744-
final Object color = data.get("color");
745-
if (color != null) {
746-
sink.setColor(toInt(color));
747-
}
748-
final Object endCap = data.get("endCap");
749-
if (endCap != null) {
750-
sink.setEndCap(toCap(endCap, assetManager, density));
751-
}
752-
final Object geodesic = data.get("geodesic");
753-
if (geodesic != null) {
754-
sink.setGeodesic(toBoolean(geodesic));
755-
}
756-
final Object jointType = data.get("jointType");
757-
if (jointType != null) {
758-
sink.setJointType(toInt(jointType));
759-
}
760-
final Object startCap = data.get("startCap");
761-
if (startCap != null) {
762-
sink.setStartCap(toCap(startCap, assetManager, density));
763-
}
764-
final Object visible = data.get("visible");
765-
if (visible != null) {
766-
sink.setVisible(toBoolean(visible));
767-
}
768-
final Object width = data.get("width");
769-
if (width != null) {
770-
sink.setWidth(toInt(width));
771-
}
772-
final Object zIndex = data.get("zIndex");
773-
if (zIndex != null) {
774-
sink.setZIndex(toFloat(zIndex));
775-
}
776-
final Object points = data.get("points");
777-
if (points != null) {
778-
sink.setPoints(toPoints(points));
779-
}
780-
final Object pattern = data.get("pattern");
781-
if (pattern != null) {
782-
sink.setPattern(toPattern(pattern));
783-
}
784-
final String polylineId = (String) data.get("polylineId");
785-
if (polylineId == null) {
786-
throw new IllegalArgumentException("polylineId was null");
787-
} else {
788-
return polylineId;
789-
}
707+
Messages.PlatformPolyline polyline,
708+
PolylineOptionsSink sink,
709+
AssetManager assetManager,
710+
float density) {
711+
sink.setConsumeTapEvents(polyline.getConsumesTapEvents());
712+
sink.setColor(polyline.getColor().intValue());
713+
sink.setEndCap(toCap(polyline.getEndCap(), assetManager, density));
714+
sink.setStartCap(toCap(polyline.getStartCap(), assetManager, density));
715+
sink.setGeodesic(polyline.getGeodesic());
716+
sink.setJointType(polyline.getJointType().intValue());
717+
sink.setVisible(polyline.getVisible());
718+
sink.setWidth(polyline.getWidth());
719+
sink.setZIndex(polyline.getZIndex());
720+
sink.setPoints(pointsFromPigeon(polyline.getPoints()));
721+
sink.setPattern(toPattern(polyline.getPatterns()));
722+
return polyline.getPolylineId();
790723
}
791724

792725
static String interpretCircleOptions(Messages.PlatformCircle circle, CircleOptionsSink sink) {
@@ -850,14 +783,11 @@ static String interpretHeatmapOptions(Map<String, ?> data, HeatmapOptionsSink si
850783
}
851784
}
852785

853-
@VisibleForTesting
854-
static List<LatLng> toPoints(Object o) {
855-
final List<?> data = toList(o);
786+
static List<LatLng> pointsFromPigeon(List<Messages.PlatformLatLng> data) {
856787
final List<LatLng> points = new ArrayList<>(data.size());
857788

858-
for (Object rawPoint : data) {
859-
final List<?> point = toList(rawPoint);
860-
points.add(new LatLng(toDouble(point.get(0)), toDouble(point.get(1))));
789+
for (Messages.PlatformLatLng rawPoint : data) {
790+
points.add(new LatLng(rawPoint.getLatitude(), rawPoint.getLongitude()));
861791
}
862792
return points;
863793
}
@@ -918,12 +848,11 @@ static Gradient toGradient(Object o) {
918848
return new Gradient(colors, startPoints, colorMapSize);
919849
}
920850

921-
private static List<List<LatLng>> toHoles(Object o) {
922-
final List<?> data = toList(o);
851+
private static List<List<LatLng>> toHoles(List<List<Messages.PlatformLatLng>> data) {
923852
final List<List<LatLng>> holes = new ArrayList<>(data.size());
924853

925-
for (Object rawHole : data) {
926-
holes.add(toPoints(rawHole));
854+
for (List<Messages.PlatformLatLng> hole : data) {
855+
holes.add(pointsFromPigeon(hole));
927856
}
928857
return holes;
929858
}

0 commit comments

Comments
 (0)