Skip to content
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

[google_maps_flutter] Move Android inspector to Pigeon #6958

Merged
merged 3 commits into from
Jun 20, 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.9.1

* Converts inspector interface platform calls to Pigeon.

## 2.9.0

* Adds support for BitmapDescriptor classes `AssetMapBitmap` and `BytesMapBitmap`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,16 @@ private static String getClusterManagerId(Object clusterManagerData) {
* Requests all current clusters from the algorithm of the requested ClusterManager and converts
* them to result response.
*/
public void getClustersWithClusterManagerId(
String clusterManagerId, MethodChannel.Result result) {
public @NonNull Set<? extends Cluster<MarkerBuilder>> getClustersWithClusterManagerId(
String clusterManagerId) {
ClusterManager<MarkerBuilder> clusterManager = clusterManagerIdToManager.get(clusterManagerId);
if (clusterManager == null) {
result.error(
throw new Messages.FlutterError(
"Invalid clusterManagerId",
"getClusters called with invalid clusterManagerId:" + clusterManagerId,
null);
return;
}

final Set<? extends Cluster<MarkerBuilder>> clusters =
clusterManager.getAlgorithm().getClusters(googleMap.getCameraPosition().zoom);
result.success(Convert.clustersToJson(clusterManagerId, clusters));
return clusterManager.getAlgorithm().getClusters(googleMap.getCameraPosition().zoom);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/** Conversions between JSON-like values and GoogleMaps data types. */
class Convert {
Expand Down Expand Up @@ -377,6 +376,13 @@ static Object latLngBoundsToJson(LatLngBounds latLngBounds) {
return arguments;
}

static Messages.PlatformLatLngBounds latLngBoundsToPigeon(LatLngBounds latLngBounds) {
return new Messages.PlatformLatLngBounds.Builder()
.setNortheast(latLngToPigeon(latLngBounds.northeast))
.setSouthwest(latLngToPigeon(latLngBounds.southwest))
.build();
}

static Object markerIdToJson(String markerId) {
if (markerId == null) {
return null;
Expand Down Expand Up @@ -431,13 +437,11 @@ static Object latLngToJson(LatLng latLng) {
return Arrays.asList(latLng.latitude, latLng.longitude);
}

static Object clustersToJson(
String clusterManagerId, Set<? extends Cluster<MarkerBuilder>> clusters) {
List<Object> data = new ArrayList<>(clusters.size());
for (Cluster<MarkerBuilder> cluster : clusters) {
data.add(clusterToJson(clusterManagerId, cluster));
}
return data;
static Messages.PlatformLatLng latLngToPigeon(LatLng latLng) {
return new Messages.PlatformLatLng.Builder()
.setLat(latLng.latitude)
.setLng(latLng.longitude)
.build();
}

static Object clusterToJson(String clusterManagerId, Cluster<MarkerBuilder> cluster) {
Expand Down Expand Up @@ -470,6 +474,27 @@ static Object clusterToJson(String clusterManagerId, Cluster<MarkerBuilder> clus
return data;
}

static Messages.PlatformCluster clusterToPigeon(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason these methods are mostly new instead of edits (e.g., this is a modified copy of clusterToJson which still exists just above) is that the JSON methods are still used by the parts of the API that haven't been converted to Pigeon yet. Over time, they will be eliminated as more APIs are moved to Pigeon.

String clusterManagerId, Cluster<MarkerBuilder> cluster) {
int clusterSize = cluster.getSize();
String[] markerIds = new String[clusterSize];
MarkerBuilder[] markerBuilders = cluster.getItems().toArray(new MarkerBuilder[clusterSize]);

LatLngBounds.Builder latLngBoundsBuilder = LatLngBounds.builder();
for (int i = 0; i < clusterSize; i++) {
MarkerBuilder markerBuilder = markerBuilders[i];
latLngBoundsBuilder.include(markerBuilder.getPosition());
markerIds[i] = markerBuilder.markerId();
}

return new Messages.PlatformCluster.Builder()
.setClusterManagerId(clusterManagerId)
.setPosition(latLngToPigeon(cluster.getPosition()))
.setBounds(latLngBoundsToPigeon(latLngBoundsBuilder.build()))
.setMarkerIds(Arrays.asList(markerIds))
.build();
}

static LatLng toLatLng(Object o) {
final List<?> data = toList(o);
return new LatLng(toDouble(data.get(0)), toDouble(data.get(1)));
Expand Down
Loading