Skip to content

Commit bc0d0e1

Browse files
Merge pull request #10 from OpenFlutter/master
add setViewpointScale
2 parents 5f49e25 + df659c1 commit bc0d0e1

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

android/src/main/java/com/valentingrigorean/arcgis_maps_flutter/map/ArcgisMapController.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.ArrayList;
4242
import java.util.List;
4343
import java.util.Map;
44+
import java.util.concurrent.ExecutionException;
4445

4546
import io.flutter.plugin.common.BinaryMessenger;
4647
import io.flutter.plugin.common.MethodCall;
@@ -439,6 +440,25 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
439440
result.success(null);
440441
break;
441442
}
443+
case "map#setViewpointScaleAsync": {
444+
final Map<?, ?> data = call.arguments();
445+
if (mapView != null && data != null) {
446+
double scale = (double) data.get("scale");
447+
ListenableFuture<Boolean> future = mapView.setViewpointScaleAsync(scale);
448+
future.addDoneListener(() -> {
449+
boolean scaled = false;
450+
try {
451+
scaled = future.get();
452+
result.success(scaled);
453+
} catch (ExecutionException | InterruptedException e) {
454+
result.success(false);
455+
}
456+
});
457+
} else {
458+
result.success(false);
459+
}
460+
break;
461+
}
442462
default:
443463
result.notImplemented();
444464
break;

ios/Classes/Map/ArcgisMapController.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,16 @@ public class ArcgisMapController: NSObject, FlutterPlatformView {
336336
layersController.setTimeOffset(arguments: call.arguments)
337337
result(nil)
338338
break
339+
case "map#setViewpointScaleAsync":
340+
if let data = call.arguments as? Dictionary<String, Any> {
341+
let scale = data["scale"] as! Double
342+
mapView.setViewpointScale(scale, completion: { finished in
343+
result(finished)
344+
})
345+
} else {
346+
result(false)
347+
}
348+
break
339349
default:
340350
result(FlutterMethodNotImplemented)
341351
break

lib/src/mapping/view/map/arcgis_map_controller.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ class ArcgisMapController {
131131
.setViewpointRotation(mapId, angleDegrees);
132132
}
133133

134+
/// Asynchronously zooms the map, with animation, to the given scale.
135+
/// The map center point does not change.
136+
/// The map scale is the number of map units per unit of physical device size.
137+
/// It expresses the relationship between a distance in the MapView and the corresponding distance on the ground.
138+
/// A smaller value will zoom the map in and produce a larger map display area (features appear larger).
139+
/// A larger value will zoom the map out and produce a smaller map display area (features appear smaller).
140+
Future<bool> setViewpointScale(double scale) async {
141+
assert(scale >= 0);
142+
return await ArcgisMapsFlutterPlatform.instance
143+
.setViewpointScale(mapId, scale);
144+
}
145+
134146
Future<Viewpoint?> getCurrentViewpoint(ViewpointType type) {
135147
return ArcgisMapsFlutterPlatform.instance.getCurrentViewpoint(mapId, type);
136148
}

lib/src/method_channel/map/arcgis_maps_flutter_platform.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ abstract class ArcgisMapsFlutterPlatform extends PlatformInterface {
135135
'onViewpointChangedListener() has not been implemented.');
136136
}
137137

138+
Future<bool> setViewpointScale(int mapId, double scale) {
139+
throw UnimplementedError(
140+
'setViewpointScale() has not been implemented.');
141+
}
142+
138143
Future<Offset?> locationToScreen(int mapId, AGSPoint mapPoint) {
139144
throw UnimplementedError('locationToScreen() has not been implemented.');
140145
}

lib/src/method_channel/map/method_channel_arcgis_maps_flutter.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,16 @@ class MethodChannelArcgisMapsFlutter extends ArcgisMapsFlutterPlatform {
297297
.invokeMethod<void>("map#setViewpointRotation", angleDegrees);
298298
}
299299

300+
@override
301+
Future<bool> setViewpointScale(int mapId, double scale) async{
302+
final result = await channel(mapId).invokeMethod<bool>(
303+
'map#setViewpointScaleAsync',
304+
{
305+
'scale': scale,
306+
},
307+
);
308+
return result ?? false;
309+
}
300310
@override
301311
Future<Offset?> locationToScreen(int mapId, AGSPoint mapPoint) async {
302312
final result = await channel(mapId)

0 commit comments

Comments
 (0)