Skip to content

Commit

Permalink
Add animation duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyokone committed Apr 19, 2020
1 parent 2cc5350 commit 1f2deaa
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
36 changes: 20 additions & 16 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,24 +459,28 @@ public void onCancel() {
}
case "camera#animate": {
final CameraUpdate cameraUpdate = Convert.toCameraUpdate(call.argument("cameraUpdate"), mapboxMap, density);
if (cameraUpdate != null) {
// camera transformation not handled yet
mapboxMap.animateCamera(cameraUpdate, new OnCameraMoveFinishedListener(){
@Override
public void onFinish() {
super.onFinish();
result.success(true);
}
final Integer durationMs = call.argument("durationMs");

@Override
public void onCancel() {
super.onCancel();
result.success(false);
}
});
final OnCameraMoveFinishedListener onCameraMoveFinishedListener = new OnCameraMoveFinishedListener(){
@Override
public void onFinish() {
super.onFinish();
result.success(true);
}

// animateCamera(cameraUpdate);
}else {
@Override
public void onCancel() {
super.onCancel();
result.success(false);
}
};
if (cameraUpdate != null && durationMs != null) {
// camera transformation not handled yet
mapboxMap.animateCamera(cameraUpdate, durationMs, onCameraMoveFinishedListener);
} else if (cameraUpdate != null) {
// camera transformation not handled yet
mapboxMap.animateCamera(cameraUpdate, onCameraMoveFinishedListener);
} else {
result.success(false);
}
break;
Expand Down
5 changes: 5 additions & 0 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
case "camera#animate":
guard let arguments = methodCall.arguments as? [String: Any] else { return }
guard let cameraUpdate = arguments["cameraUpdate"] as? [Any] else { return }
let durationMs = arguments["durationMs"] as? [Double]
if let camera = Convert.parseCameraUpdate(cameraUpdate: cameraUpdate, mapView: mapView) {
if (durationMs) {
mapView.setCamera(camera, animated: true, withDuration: durationMs / 1000)
result(nil)
}
mapView.setCamera(camera, animated: true)
}
result(nil)
Expand Down
29 changes: 16 additions & 13 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ class MapboxMapController extends ChangeNotifier {
/// platform side.
/// It returns true if the camera was successfully moved and false if the movement was canceled.
/// Note: this currently always returns immediately with a value of null on iOS
Future<bool> animateCamera(CameraUpdate cameraUpdate) async {
Future<bool> animateCamera(CameraUpdate cameraUpdate,
{int durationMs}) async {
return await _channel.invokeMethod('camera#animate', <String, dynamic>{
'cameraUpdate': cameraUpdate._toJson(),
'durationMs': durationMs
});
}

Expand All @@ -241,20 +243,20 @@ class MapboxMapController extends ChangeNotifier {
/// platform side.
Future<void> updateMyLocationTrackingMode(
MyLocationTrackingMode myLocationTrackingMode) async {
await _channel.invokeMethod(
'map#updateMyLocationTrackingMode', <String, dynamic>{
await _channel
.invokeMethod('map#updateMyLocationTrackingMode', <String, dynamic>{
'mode': myLocationTrackingMode.index,
});
}

/// Updates the language of the map labels to match the device's language.
///
/// The returned [Future] completes after the change has been made on the
/// platform side.
Future<void> matchMapLanguageWithDeviceDefault() async {
await _channel.invokeMethod('map#matchMapLanguageWithDeviceDefault');
}
}

/// Updates the distance from the edges of the map view’s frame to the edges
/// of the map view’s logical viewport, optionally animating the change.
///
Expand Down Expand Up @@ -289,7 +291,7 @@ class MapboxMapController extends ChangeNotifier {
'language': language,
});
}

/// Enables or disables the collection of anonymized telemetry data.
///
/// The returned [Future] completes after the change has been made on the
Expand Down Expand Up @@ -608,23 +610,23 @@ class MapboxMapController extends ChangeNotifier {
}
}


Future invalidateAmbientCache() async {
try {
await _channel.invokeMethod('map#invalidateAmbientCache');
return null;
} on PlatformException catch (e) {
} on PlatformException catch (e) {
return new Future.error(e);
}
}

/// Get last my location
///
/// Return last latlng, nullable
Future<LatLng> requestMyLocationLatLng() async {
try {
final Map<Object, Object> reply = await _channel.invokeMethod('locationComponent#getLastLocation', null);
final Map<Object, Object> reply = await _channel.invokeMethod(
'locationComponent#getLastLocation', null);
double latitude = 0.0, longitude = 0.0;
if (reply.containsKey("latitude") && reply["latitude"] != null) {
latitude = double.parse(reply["latitude"].toString());
Expand All @@ -639,9 +641,10 @@ class MapboxMapController extends ChangeNotifier {
}

///This method returns the boundaries of the region currently displayed in the map.
Future<LatLngBounds> getVisibleRegion() async{
Future<LatLngBounds> getVisibleRegion() async {
try {
final Map<Object, Object> reply = await _channel.invokeMethod('map#getVisibleRegion', null);
final Map<Object, Object> reply =
await _channel.invokeMethod('map#getVisibleRegion', null);
LatLng southwest, northeast;
if (reply.containsKey("sw")) {
List<dynamic> coordinates = reply["sw"];
Expand Down

0 comments on commit 1f2deaa

Please sign in to comment.