-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[google_maps_flutter] Moves Java->Dart calls to Pigeon #7040
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
Changes from all commits
ae2f470
7f310ee
a3ad521
c678de4
bbda7da
da6da68
5f0aaae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 2.12.0 | ||
|
||
* Converts Java->Dart calls to Pigeon. | ||
|
||
## 2.11.1 | ||
|
||
* Fixes handling of Circle updates. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -373,16 +373,14 @@ private static int toInt(Object o) { | |
return null; | ||
} | ||
|
||
static Object cameraPositionToJson(CameraPosition position) { | ||
if (position == null) { | ||
return null; | ||
} | ||
final Map<String, Object> data = new HashMap<>(); | ||
data.put("bearing", position.bearing); | ||
data.put("target", latLngToJson(position.target)); | ||
data.put("tilt", position.tilt); | ||
data.put("zoom", position.zoom); | ||
return data; | ||
static @NonNull Messages.PlatformCameraPosition cameraPositionToPigeon( | ||
@NonNull CameraPosition position) { | ||
return new Messages.PlatformCameraPosition.Builder() | ||
.setBearing((double) position.bearing) | ||
.setTarget(latLngToPigeon(position.target)) | ||
.setTilt((double) position.tilt) | ||
.setZoom((double) position.zoom) | ||
.build(); | ||
} | ||
|
||
static Object latLngBoundsToJson(LatLngBounds latLngBounds) { | ||
|
@@ -426,29 +424,6 @@ static Object polylineIdToJson(String polylineId) { | |
return data; | ||
} | ||
|
||
static Object circleIdToJson(String circleId) { | ||
if (circleId == null) { | ||
return null; | ||
} | ||
final Map<String, Object> data = new HashMap<>(1); | ||
data.put("circleId", circleId); | ||
return data; | ||
} | ||
|
||
static Map<String, Object> tileOverlayArgumentsToJson( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can change this to stay here and do a Pigeon build if you prefer, but since we have to pass all the arguments individually anyway (vs passing a single object to convert) it seemed easier to just inline it. |
||
String tileOverlayId, int x, int y, int zoom) { | ||
|
||
if (tileOverlayId == null) { | ||
return null; | ||
} | ||
final Map<String, Object> data = new HashMap<>(4); | ||
data.put("tileOverlayId", tileOverlayId); | ||
data.put("x", x); | ||
data.put("y", y); | ||
data.put("zoom", zoom); | ||
return data; | ||
} | ||
|
||
static Object latLngToJson(LatLng latLng) { | ||
return Arrays.asList(latLng.latitude, latLng.longitude); | ||
} | ||
|
@@ -464,36 +439,6 @@ static LatLng latLngFromPigeon(Messages.PlatformLatLng latLng) { | |
return new LatLng(latLng.getLatitude(), latLng.getLongitude()); | ||
} | ||
|
||
static Object clusterToJson(String clusterManagerId, Cluster<MarkerBuilder> cluster) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is pure removal because the Pigeon version (just below) was added in a previous PR. |
||
int clusterSize = cluster.getSize(); | ||
LatLngBounds.Builder latLngBoundsBuilder = LatLngBounds.builder(); | ||
|
||
String[] markerIds = new String[clusterSize]; | ||
MarkerBuilder[] markerBuilders = cluster.getItems().toArray(new MarkerBuilder[clusterSize]); | ||
|
||
// Loops though cluster items and reads markers position for the LatLngBounds | ||
// builder | ||
// and also builds list of marker ids on the cluster. | ||
for (int i = 0; i < clusterSize; i++) { | ||
MarkerBuilder markerBuilder = markerBuilders[i]; | ||
latLngBoundsBuilder.include(markerBuilder.getPosition()); | ||
markerIds[i] = markerBuilder.markerId(); | ||
} | ||
|
||
Object position = latLngToJson(cluster.getPosition()); | ||
Object bounds = latLngBoundsToJson(latLngBoundsBuilder.build()); | ||
|
||
final Map<String, Object> data = new HashMap<>(4); | ||
|
||
// For dart side implementation see parseCluster method at | ||
// packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart | ||
data.put("clusterManagerId", clusterManagerId); | ||
data.put("position", position); | ||
data.put("bounds", bounds); | ||
data.put("markerIds", Arrays.asList(markerIds)); | ||
return data; | ||
} | ||
|
||
static Messages.PlatformCluster clusterToPigeon( | ||
String clusterManagerId, Cluster<MarkerBuilder> cluster) { | ||
int clusterSize = cluster.getSize(); | ||
|
@@ -994,14 +939,8 @@ static String interpretTileOverlayOptions(Map<String, ?> data, TileOverlaySink s | |
} | ||
} | ||
|
||
static Tile interpretTile(Map<String, ?> data) { | ||
int width = toInt(data.get("width")); | ||
int height = toInt(data.get("height")); | ||
byte[] dataArray = null; | ||
if (data.get("data") != null) { | ||
dataArray = (byte[]) data.get("data"); | ||
} | ||
return new Tile(width, height, dataArray); | ||
static Tile tileFromPigeon(Messages.PlatformTile tile) { | ||
return new Tile(tile.getWidth().intValue(), tile.getHeight().intValue(), tile.getData()); | ||
} | ||
|
||
@VisibleForTesting | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ | |
import com.google.android.gms.maps.GoogleMapOptions; | ||
import com.google.android.gms.maps.MapView; | ||
import com.google.android.gms.maps.OnMapReadyCallback; | ||
import com.google.android.gms.maps.model.CameraPosition; | ||
import com.google.android.gms.maps.model.Circle; | ||
import com.google.android.gms.maps.model.LatLng; | ||
import com.google.android.gms.maps.model.LatLngBounds; | ||
|
@@ -44,15 +43,13 @@ | |
import com.google.maps.android.collections.MarkerManager; | ||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; | ||
import io.flutter.plugin.common.BinaryMessenger; | ||
import io.flutter.plugin.common.MethodChannel; | ||
import io.flutter.plugin.platform.PlatformView; | ||
import io.flutter.plugins.googlemaps.Messages.FlutterError; | ||
import io.flutter.plugins.googlemaps.Messages.MapsApi; | ||
import io.flutter.plugins.googlemaps.Messages.MapsCallbackApi; | ||
import io.flutter.plugins.googlemaps.Messages.MapsInspectorApi; | ||
import java.io.ByteArrayOutputStream; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
@@ -73,7 +70,7 @@ class GoogleMapController | |
|
||
private static final String TAG = "GoogleMapController"; | ||
private final int id; | ||
private final MethodChannel methodChannel; | ||
private final MapsCallbackApi flutterApi; | ||
private final BinaryMessenger binaryMessenger; | ||
private final GoogleMapOptions options; | ||
@Nullable private MapView mapView; | ||
|
@@ -121,19 +118,18 @@ class GoogleMapController | |
this.mapView = new MapView(context, options); | ||
this.density = context.getResources().getDisplayMetrics().density; | ||
this.binaryMessenger = binaryMessenger; | ||
methodChannel = | ||
new MethodChannel(binaryMessenger, "plugins.flutter.dev/google_maps_android_" + id); | ||
flutterApi = new MapsCallbackApi(binaryMessenger, Integer.toString(id)); | ||
MapsApi.setUp(binaryMessenger, Integer.toString(id), this); | ||
MapsInspectorApi.setUp(binaryMessenger, Integer.toString(id), this); | ||
AssetManager assetManager = context.getAssets(); | ||
this.lifecycleProvider = lifecycleProvider; | ||
this.clusterManagersController = new ClusterManagersController(methodChannel, context); | ||
this.clusterManagersController = new ClusterManagersController(flutterApi, context); | ||
this.markersController = | ||
new MarkersController(methodChannel, clusterManagersController, assetManager, density); | ||
this.polygonsController = new PolygonsController(methodChannel, density); | ||
this.polylinesController = new PolylinesController(methodChannel, assetManager, density); | ||
this.circlesController = new CirclesController(methodChannel, density); | ||
this.tileOverlaysController = new TileOverlaysController(methodChannel); | ||
new MarkersController(flutterApi, clusterManagersController, assetManager, density); | ||
this.polygonsController = new PolygonsController(flutterApi, density); | ||
this.polylinesController = new PolylinesController(flutterApi, assetManager, density); | ||
this.circlesController = new CirclesController(flutterApi, density); | ||
this.tileOverlaysController = new TileOverlaysController(flutterApi); | ||
} | ||
|
||
// Constructor for testing purposes only | ||
|
@@ -142,7 +138,7 @@ class GoogleMapController | |
int id, | ||
Context context, | ||
BinaryMessenger binaryMessenger, | ||
MethodChannel methodChannel, | ||
MapsCallbackApi flutterApi, | ||
LifecycleProvider lifecycleProvider, | ||
GoogleMapOptions options, | ||
ClusterManagersController clusterManagersController, | ||
|
@@ -154,7 +150,7 @@ class GoogleMapController | |
this.id = id; | ||
this.context = context; | ||
this.binaryMessenger = binaryMessenger; | ||
this.methodChannel = methodChannel; | ||
this.flutterApi = flutterApi; | ||
this.options = options; | ||
this.mapView = new MapView(context, options); | ||
this.density = context.getResources().getDisplayMetrics().density; | ||
|
@@ -182,10 +178,6 @@ void init() { | |
mapView.getMapAsync(this); | ||
} | ||
|
||
private CameraPosition getCameraPosition() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opportunistic cleanup; the IDE flagged that this was unused. |
||
return trackCameraPosition ? googleMap.getCameraPosition() : null; | ||
} | ||
|
||
@Override | ||
public void onMapReady(@NonNull GoogleMap googleMap) { | ||
this.googleMap = googleMap; | ||
|
@@ -298,24 +290,17 @@ public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) { | |
|
||
@Override | ||
public void onMapClick(@NonNull LatLng latLng) { | ||
final Map<String, Object> arguments = new HashMap<>(2); | ||
arguments.put("position", Convert.latLngToJson(latLng)); | ||
methodChannel.invokeMethod("map#onTap", arguments); | ||
flutterApi.onTap(Convert.latLngToPigeon(latLng), new NoOpVoidResult()); | ||
} | ||
|
||
@Override | ||
public void onMapLongClick(@NonNull LatLng latLng) { | ||
final Map<String, Object> arguments = new HashMap<>(2); | ||
arguments.put("position", Convert.latLngToJson(latLng)); | ||
methodChannel.invokeMethod("map#onLongPress", arguments); | ||
flutterApi.onLongPress(Convert.latLngToPigeon(latLng), new NoOpVoidResult()); | ||
} | ||
|
||
@Override | ||
public void onCameraMoveStarted(int reason) { | ||
final Map<String, Object> arguments = new HashMap<>(2); | ||
boolean isGesture = reason == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE; | ||
arguments.put("isGesture", isGesture); | ||
methodChannel.invokeMethod("camera#onMoveStarted", arguments); | ||
flutterApi.onCameraMoveStarted(new NoOpVoidResult()); | ||
} | ||
|
||
@Override | ||
|
@@ -328,15 +313,14 @@ public void onCameraMove() { | |
if (!trackCameraPosition) { | ||
return; | ||
} | ||
final Map<String, Object> arguments = new HashMap<>(2); | ||
arguments.put("position", Convert.cameraPositionToJson(googleMap.getCameraPosition())); | ||
methodChannel.invokeMethod("camera#onMove", arguments); | ||
flutterApi.onCameraMove( | ||
Convert.cameraPositionToPigeon(googleMap.getCameraPosition()), new NoOpVoidResult()); | ||
} | ||
|
||
@Override | ||
public void onCameraIdle() { | ||
clusterManagersController.onCameraIdle(); | ||
methodChannel.invokeMethod("camera#onIdle", Collections.singletonMap("map", id)); | ||
flutterApi.onCameraIdle(new NoOpVoidResult()); | ||
} | ||
|
||
@Override | ||
|
Uh oh!
There was an error while loading. Please reload this page.