Skip to content

Commit

Permalink
[google_maps_flutter_android] Convert PlatformPolygon and `Platform…
Browse files Browse the repository at this point in the history
…Polyline` to Pigeon (flutter#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
  • Loading branch information
yaakovschectman authored Aug 21, 2024
1 parent 6dd3e4e commit 50e4138
Show file tree
Hide file tree
Showing 11 changed files with 910 additions and 220 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.14.3

* Converts `PlatformPolygon` and `PlatformPolyline` to pigeon.

## 2.14.2

* Bumps `com.android.tools.build:gradle` from 7.3.1 to 8.5.1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,103 +690,36 @@ private static void interpretInfoWindowOptions(
infoWindowAnchor.getDx().floatValue(), infoWindowAnchor.getDy().floatValue());
}

static String interpretPolygonOptions(Map<String, ?> data, PolygonOptionsSink sink) {
final Object consumeTapEvents = data.get("consumeTapEvents");
if (consumeTapEvents != null) {
sink.setConsumeTapEvents(toBoolean(consumeTapEvents));
}
final Object geodesic = data.get("geodesic");
if (geodesic != null) {
sink.setGeodesic(toBoolean(geodesic));
}
final Object visible = data.get("visible");
if (visible != null) {
sink.setVisible(toBoolean(visible));
}
final Object fillColor = data.get("fillColor");
if (fillColor != null) {
sink.setFillColor(toInt(fillColor));
}
final Object strokeColor = data.get("strokeColor");
if (strokeColor != null) {
sink.setStrokeColor(toInt(strokeColor));
}
final Object strokeWidth = data.get("strokeWidth");
if (strokeWidth != null) {
sink.setStrokeWidth(toInt(strokeWidth));
}
final Object zIndex = data.get("zIndex");
if (zIndex != null) {
sink.setZIndex(toFloat(zIndex));
}
final Object points = data.get("points");
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");
} else {
return polygonId;
}
static String interpretPolygonOptions(Messages.PlatformPolygon polygon, PolygonOptionsSink sink) {
sink.setConsumeTapEvents(polygon.getConsumesTapEvents());
sink.setGeodesic(polygon.getGeodesic());
sink.setVisible(polygon.getVisible());
sink.setFillColor(polygon.getFillColor().intValue());
sink.setStrokeColor(polygon.getStrokeColor().intValue());
sink.setStrokeWidth(polygon.getStrokeWidth());
sink.setZIndex(polygon.getZIndex());
sink.setPoints(pointsFromPigeon(polygon.getPoints()));
sink.setHoles(toHoles(polygon.getHoles()));
return polygon.getPolygonId();
}

static String interpretPolylineOptions(
Map<String, ?> data, PolylineOptionsSink sink, AssetManager assetManager, float density) {
final Object consumeTapEvents = data.get("consumeTapEvents");
if (consumeTapEvents != null) {
sink.setConsumeTapEvents(toBoolean(consumeTapEvents));
}
final Object color = data.get("color");
if (color != null) {
sink.setColor(toInt(color));
}
final Object endCap = data.get("endCap");
if (endCap != null) {
sink.setEndCap(toCap(endCap, assetManager, density));
}
final Object geodesic = data.get("geodesic");
if (geodesic != null) {
sink.setGeodesic(toBoolean(geodesic));
}
final Object jointType = data.get("jointType");
if (jointType != null) {
sink.setJointType(toInt(jointType));
}
final Object startCap = data.get("startCap");
if (startCap != null) {
sink.setStartCap(toCap(startCap, assetManager, density));
}
final Object visible = data.get("visible");
if (visible != null) {
sink.setVisible(toBoolean(visible));
}
final Object width = data.get("width");
if (width != null) {
sink.setWidth(toInt(width));
}
final Object zIndex = data.get("zIndex");
if (zIndex != null) {
sink.setZIndex(toFloat(zIndex));
}
final Object points = data.get("points");
if (points != null) {
sink.setPoints(toPoints(points));
}
final Object pattern = data.get("pattern");
if (pattern != null) {
sink.setPattern(toPattern(pattern));
}
final String polylineId = (String) data.get("polylineId");
if (polylineId == null) {
throw new IllegalArgumentException("polylineId was null");
} else {
return polylineId;
}
Messages.PlatformPolyline polyline,
PolylineOptionsSink sink,
AssetManager assetManager,
float density) {
sink.setConsumeTapEvents(polyline.getConsumesTapEvents());
sink.setColor(polyline.getColor().intValue());
sink.setEndCap(toCap(polyline.getEndCap(), assetManager, density));
sink.setStartCap(toCap(polyline.getStartCap(), assetManager, density));
sink.setGeodesic(polyline.getGeodesic());
sink.setJointType(polyline.getJointType().intValue());
sink.setVisible(polyline.getVisible());
sink.setWidth(polyline.getWidth());
sink.setZIndex(polyline.getZIndex());
sink.setPoints(pointsFromPigeon(polyline.getPoints()));
sink.setPattern(toPattern(polyline.getPatterns()));
return polyline.getPolylineId();
}

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

@VisibleForTesting
static List<LatLng> toPoints(Object o) {
final List<?> data = toList(o);
static List<LatLng> pointsFromPigeon(List<Messages.PlatformLatLng> data) {
final List<LatLng> points = new ArrayList<>(data.size());

for (Object rawPoint : data) {
final List<?> point = toList(rawPoint);
points.add(new LatLng(toDouble(point.get(0)), toDouble(point.get(1))));
for (Messages.PlatformLatLng rawPoint : data) {
points.add(new LatLng(rawPoint.getLatitude(), rawPoint.getLongitude()));
}
return points;
}
Expand Down Expand Up @@ -918,12 +848,11 @@ static Gradient toGradient(Object o) {
return new Gradient(colors, startPoints, colorMapSize);
}

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

for (Object rawHole : data) {
holes.add(toPoints(rawHole));
for (List<Messages.PlatformLatLng> hole : data) {
holes.add(pointsFromPigeon(hole));
}
return holes;
}
Expand Down
Loading

0 comments on commit 50e4138

Please sign in to comment.