Skip to content
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,7 +1,11 @@
## 2.16.0

* Adds support for animating the camera with a duration.

## 2.15.0

* Adds support for ground overlay.

## 2.14.14

* Updates compileSdk 34 to flutter.compileSdkVersion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.MapView;
Expand Down Expand Up @@ -976,12 +977,18 @@ public void moveCamera(@NonNull Messages.PlatformCameraUpdate cameraUpdate) {
}

@Override
public void animateCamera(@NonNull Messages.PlatformCameraUpdate cameraUpdate) {
public void animateCamera(
@NonNull Messages.PlatformCameraUpdate cameraUpdate, @Nullable Long durationMilliseconds) {
if (googleMap == null) {
throw new FlutterError(
"GoogleMap uninitialized", "animateCamera called prior to map initialization", null);
}
googleMap.animateCamera(Convert.cameraUpdateFromPigeon(cameraUpdate, density));
CameraUpdate update = Convert.cameraUpdateFromPigeon(cameraUpdate, density);
if (durationMilliseconds != null) {
googleMap.animateCamera(update, durationMilliseconds.intValue(), null);
} else {
googleMap.animateCamera(update);
}
}

@Override
Expand Down Expand Up @@ -1100,6 +1107,11 @@ public Boolean isLiteModeEnabled() {
return Objects.requireNonNull(googleMap).isTrafficEnabled();
}

@Override
public @NonNull Messages.PlatformCameraPosition getCameraPosition() {
return Convert.cameraPositionToPigeon(Objects.requireNonNull(googleMap).getCameraPosition());
}

@Override
public @Nullable Messages.PlatformTileLayer getTileOverlayInfo(@NonNull String tileOverlayId) {
TileOverlay tileOverlay = tileOverlaysController.getTileOverlay(tileOverlayId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v22.7.3), do not edit directly.
// Autogenerated from Pigeon (v22.7.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package io.flutter.plugins.googlemaps;
Expand Down Expand Up @@ -6567,8 +6567,12 @@ void updateGroundOverlays(
PlatformLatLngBounds getVisibleRegion();
/** Moves the camera according to [cameraUpdate] immediately, with no animation. */
void moveCamera(@NonNull PlatformCameraUpdate cameraUpdate);
/** Moves the camera according to [cameraUpdate], animating the update. */
void animateCamera(@NonNull PlatformCameraUpdate cameraUpdate);
/**
* Moves the camera according to [cameraUpdate], animating the update using a duration in
* milliseconds if provided.
*/
void animateCamera(
@NonNull PlatformCameraUpdate cameraUpdate, @Nullable Long durationMilliseconds);
/** Gets the current map zoom level. */
@NonNull
Double getZoomLevel();
Expand Down Expand Up @@ -6996,8 +7000,9 @@ public void error(Throwable error) {
ArrayList<Object> wrapped = new ArrayList<>();
ArrayList<Object> args = (ArrayList<Object>) message;
PlatformCameraUpdate cameraUpdateArg = (PlatformCameraUpdate) args.get(0);
Long durationMillisecondsArg = (Long) args.get(1);
try {
api.animateCamera(cameraUpdateArg);
api.animateCamera(cameraUpdateArg, durationMillisecondsArg);
wrapped.add(0, null);
} catch (Throwable exception) {
wrapped = wrapError(exception);
Expand Down Expand Up @@ -7809,6 +7814,9 @@ public interface MapsInspectorApi {
@NonNull
List<PlatformCluster> getClusters(@NonNull String clusterManagerId);

@NonNull
PlatformCameraPosition getCameraPosition();

/** The codec used by MapsInspectorApi. */
static @NonNull MessageCodec<Object> getCodec() {
return PigeonCodec.INSTANCE;
Expand Down Expand Up @@ -8176,6 +8184,29 @@ static void setUp(
channel.setMessageHandler(null);
}
}
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.google_maps_flutter_android.MapsInspectorApi.getCameraPosition"
+ messageChannelSuffix,
getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<>();
try {
PlatformCameraPosition output = api.getCameraPosition();
wrapped.add(0, output);
} catch (Throwable exception) {
wrapped = wrapError(exception);
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.os.Build;
import androidx.activity.ComponentActivity;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.maps.android.clustering.ClusterManager;
import io.flutter.plugin.common.BinaryMessenger;
Expand All @@ -28,6 +37,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
Expand Down Expand Up @@ -250,4 +260,64 @@ public void UpdateHeatmaps() {
verify(mockHeatmapsController, times(1)).changeHeatmaps(toChange);
verify(mockHeatmapsController, times(1)).removeHeatmaps(idsToRemove);
}

@Test
public void AnimateCamera() {
GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies();
googleMapController.onMapReady(mockGoogleMap);

Messages.PlatformCameraUpdateZoomBy newCameraPosition =
new Messages.PlatformCameraUpdateZoomBy.Builder().setAmount(1.0).build();
Messages.PlatformCameraUpdate cameraUpdate =
new Messages.PlatformCameraUpdate.Builder().setCameraUpdate(newCameraPosition).build();

try (MockedStatic<CameraUpdateFactory> mockedFactory = mockStatic(CameraUpdateFactory.class)) {
mockedFactory
.when(() -> CameraUpdateFactory.zoomBy(anyFloat()))
.thenReturn(mock(CameraUpdate.class));
googleMapController.animateCamera(cameraUpdate, null);
}

verify(mockGoogleMap, times(1)).animateCamera(any(CameraUpdate.class));
}

@Test
public void AnimateCameraWithDuration() {
GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies();
googleMapController.onMapReady(mockGoogleMap);

Messages.PlatformCameraUpdateZoomBy newCameraPosition =
new Messages.PlatformCameraUpdateZoomBy.Builder().setAmount(1.0).build();
Messages.PlatformCameraUpdate cameraUpdate =
new Messages.PlatformCameraUpdate.Builder().setCameraUpdate(newCameraPosition).build();

Long durationMilliseconds = 1000L;

try (MockedStatic<CameraUpdateFactory> mockedFactory = mockStatic(CameraUpdateFactory.class)) {
mockedFactory
.when(() -> CameraUpdateFactory.zoomBy(anyFloat()))
.thenReturn(mock(CameraUpdate.class));
googleMapController.animateCamera(cameraUpdate, durationMilliseconds);
}

verify(mockGoogleMap, times(1))
.animateCamera(any(CameraUpdate.class), eq(durationMilliseconds.intValue()), isNull());
}

@Test
public void getCameraPositionReturnsCorrectData() {
GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies();
googleMapController.onMapReady(mockGoogleMap);

CameraPosition cameraPosition = new CameraPosition(new LatLng(10.0, 20.0), 15.0f, 30.0f, 45.0f);
when(mockGoogleMap.getCameraPosition()).thenReturn(cameraPosition);

Messages.PlatformCameraPosition result = googleMapController.getCameraPosition();

Assert.assertEquals(cameraPosition.target.latitude, result.getTarget().getLatitude(), 1e-15);
Assert.assertEquals(cameraPosition.target.longitude, result.getTarget().getLongitude(), 1e-15);
Assert.assertEquals(cameraPosition.zoom, result.getZoom(), 1e-15);
Assert.assertEquals(cameraPosition.tilt, result.getTilt(), 1e-15);
Assert.assertEquals(cameraPosition.bearing, result.getBearing(), 1e-15);
}
}
Loading