Skip to content

[google_maps_flutter_android] Convert PlatformPolygon and PlatformPolyline to Pigeon #7406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Aug 21, 2024
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
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