diff --git a/android/src/main/java/com/valentingrigorean/arcgis_maps_flutter/map/ArcgisMapController.java b/android/src/main/java/com/valentingrigorean/arcgis_maps_flutter/map/ArcgisMapController.java index 690bfe8d..815503b1 100755 --- a/android/src/main/java/com/valentingrigorean/arcgis_maps_flutter/map/ArcgisMapController.java +++ b/android/src/main/java/com/valentingrigorean/arcgis_maps_flutter/map/ArcgisMapController.java @@ -41,6 +41,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutionException; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodCall; @@ -439,6 +440,25 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result.success(null); break; } + case "map#setViewpointScaleAsync": { + final Map data = call.arguments(); + if (mapView != null && data != null) { + double scale = (double) data.get("scale"); + ListenableFuture future = mapView.setViewpointScaleAsync(scale); + future.addDoneListener(() -> { + boolean scaled = false; + try { + scaled = future.get(); + result.success(scaled); + } catch (ExecutionException | InterruptedException e) { + result.success(false); + } + }); + } else { + result.success(false); + } + break; + } default: result.notImplemented(); break; diff --git a/ios/Classes/Map/ArcgisMapController.swift b/ios/Classes/Map/ArcgisMapController.swift index 9b2c30c0..46e3e98d 100755 --- a/ios/Classes/Map/ArcgisMapController.swift +++ b/ios/Classes/Map/ArcgisMapController.swift @@ -336,6 +336,16 @@ public class ArcgisMapController: NSObject, FlutterPlatformView { layersController.setTimeOffset(arguments: call.arguments) result(nil) break + case "map#setViewpointScaleAsync": + if let data = call.arguments as? Dictionary { + let scale = data["scale"] as! Double + mapView.setViewpointScale(scale, completion: { finished in + result(finished) + }) + } else { + result(false) + } + break default: result(FlutterMethodNotImplemented) break diff --git a/lib/src/mapping/view/map/arcgis_map_controller.dart b/lib/src/mapping/view/map/arcgis_map_controller.dart index 467b9acc..587fab28 100755 --- a/lib/src/mapping/view/map/arcgis_map_controller.dart +++ b/lib/src/mapping/view/map/arcgis_map_controller.dart @@ -131,6 +131,18 @@ class ArcgisMapController { .setViewpointRotation(mapId, angleDegrees); } + /// Asynchronously zooms the map, with animation, to the given scale. + /// The map center point does not change. + /// The map scale is the number of map units per unit of physical device size. + /// It expresses the relationship between a distance in the MapView and the corresponding distance on the ground. + /// A smaller value will zoom the map in and produce a larger map display area (features appear larger). + /// A larger value will zoom the map out and produce a smaller map display area (features appear smaller). + Future setViewpointScale(double scale) async { + assert(scale >= 0); + return await ArcgisMapsFlutterPlatform.instance + .setViewpointScale(mapId, scale); + } + Future getCurrentViewpoint(ViewpointType type) { return ArcgisMapsFlutterPlatform.instance.getCurrentViewpoint(mapId, type); } diff --git a/lib/src/method_channel/map/arcgis_maps_flutter_platform.dart b/lib/src/method_channel/map/arcgis_maps_flutter_platform.dart index d9ec85d9..855c6a7d 100755 --- a/lib/src/method_channel/map/arcgis_maps_flutter_platform.dart +++ b/lib/src/method_channel/map/arcgis_maps_flutter_platform.dart @@ -135,6 +135,11 @@ abstract class ArcgisMapsFlutterPlatform extends PlatformInterface { 'onViewpointChangedListener() has not been implemented.'); } + Future setViewpointScale(int mapId, double scale) { + throw UnimplementedError( + 'setViewpointScale() has not been implemented.'); + } + Future locationToScreen(int mapId, AGSPoint mapPoint) { throw UnimplementedError('locationToScreen() has not been implemented.'); } diff --git a/lib/src/method_channel/map/method_channel_arcgis_maps_flutter.dart b/lib/src/method_channel/map/method_channel_arcgis_maps_flutter.dart index 4adce259..46fae88d 100755 --- a/lib/src/method_channel/map/method_channel_arcgis_maps_flutter.dart +++ b/lib/src/method_channel/map/method_channel_arcgis_maps_flutter.dart @@ -297,6 +297,16 @@ class MethodChannelArcgisMapsFlutter extends ArcgisMapsFlutterPlatform { .invokeMethod("map#setViewpointRotation", angleDegrees); } + @override + Future setViewpointScale(int mapId, double scale) async{ + final result = await channel(mapId).invokeMethod( + 'map#setViewpointScaleAsync', + { + 'scale': scale, + }, + ); + return result ?? false; + } @override Future locationToScreen(int mapId, AGSPoint mapPoint) async { final result = await channel(mapId)