Skip to content

Commit 28a0c43

Browse files
authored
Set AutoPanMode (#79)
* initial test * initial test * add set autopan mode * remove debug code * add android code * refactor code a bit * add mapoptions * debug json parsing * remove autoPanMode in init * expose wanderExtentFactor and getter of autoPanMode * fix double <-> float * remove autoPanMode from mapOptions * remove autoPanMode * add example * small changes from feedback * add readme * rollback autoformat
1 parent 1681884 commit 28a0c43

File tree

11 files changed

+300
-13
lines changed

11 files changed

+300
-13
lines changed

arcgis_map_sdk/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Checkout the example app `example/lib/main.dart` for more details.
109109
| toggleBaseMap ||||
110110
| moveCamera ||||
111111
| moveCameraToPoints | |||
112+
| use AutoPanMode | |||
112113
| exportImage | |||
113114
| zoomIn ||||
114115
| zoomOut ||||

arcgis_map_sdk/lib/src/arcgis_location_display.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ class ArcgisLocationDisplay {
4747
return ArcgisMapPlatform.instance.stopLocationDisplayDataSource(_mapId!);
4848
}
4949

50+
void setAutoPanMode(AutoPanMode autoPanMode) {
51+
_assertAttached();
52+
ArcgisMapPlatform.instance.setAutoPanMode(autoPanMode.name, _mapId!);
53+
}
54+
55+
Future<AutoPanMode> getAutoPanMode() {
56+
_assertAttached();
57+
return ArcgisMapPlatform.instance.getAutoPanMode(_mapId!);
58+
}
59+
60+
void setWanderExtentFactor(double factor) {
61+
_assertAttached();
62+
return ArcgisMapPlatform.instance.setWanderExtentFactor(factor, _mapId!);
63+
}
64+
65+
Future<double> getWanderExtentFactor() {
66+
_assertAttached();
67+
return ArcgisMapPlatform.instance.getWanderExtentFactor(_mapId!);
68+
}
69+
5070
Future<void> setDefaultSymbol(Symbol symbol) {
5171
_assertAttached();
5272
return ArcgisMapPlatform.instance

arcgis_map_sdk_android/android/src/main/kotlin/dev/fluttercommunity/arcgis_map_sdk_android/ArcgisMapView.kt

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.esri.arcgisruntime.mapping.Viewpoint
2626
import com.esri.arcgisruntime.mapping.view.AnimationCurve
2727
import com.esri.arcgisruntime.mapping.view.Graphic
2828
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay
29+
import com.esri.arcgisruntime.mapping.view.LocationDisplay.AutoPanMode
2930
import com.esri.arcgisruntime.mapping.view.MapView
3031
import com.esri.arcgisruntime.symbology.Symbol
3132
import com.google.gson.reflect.TypeToken
@@ -160,6 +161,10 @@ internal class ArcgisMapView(
160161
result
161162
)
162163

164+
"set_auto_pan_mode" -> onSetAutoPanMode(call = call, result = result)
165+
"get_auto_pan_mode" -> onGetAutoPanMode(call = call, result = result)
166+
"set_wander_extent_factor" -> onSetWanderExtentFactor(call = call, result = result)
167+
"get_wander_extent_factor" -> onGetWanderExtentFactor(call = call, result = result)
163168
"location_display_set_accuracy_symbol" -> onSetLocationDisplayAccuracySymbol(
164169
call,
165170
result
@@ -267,6 +272,75 @@ internal class ArcgisMapView(
267272
}
268273
}
269274

275+
private fun onSetAutoPanMode(
276+
call: MethodCall,
277+
result: MethodChannel.Result
278+
) {
279+
try {
280+
val mode = call.arguments as String?
281+
if (mode == null) {
282+
result.error(
283+
"missing_data",
284+
"Invalid argument, expected an autoPanMode as string",
285+
null,
286+
)
287+
return
288+
}
289+
val autoPanMode = mode.autoPanModeFromString()
290+
if (autoPanMode != null) {
291+
mapView.locationDisplay.autoPanMode = autoPanMode
292+
result.success(true)
293+
} else {
294+
result.error(
295+
"invalid_data",
296+
"Invalid argument, expected an AutoPanMode but got $mode",
297+
null,
298+
)
299+
}
300+
} catch (e: Throwable) {
301+
result.finishWithError(e, "Setting AutoPanMode failed.")
302+
}
303+
}
304+
305+
private fun onGetAutoPanMode(
306+
call: MethodCall,
307+
result: MethodChannel.Result
308+
) {
309+
try {
310+
return result.success(mapView.locationDisplay.autoPanMode.name)
311+
} catch (e: Throwable) {
312+
result.finishWithError(e, "Getting AutoPanMode failed.")
313+
}
314+
}
315+
316+
private fun onSetWanderExtentFactor(
317+
call: MethodCall,
318+
result: MethodChannel.Result
319+
) {
320+
try {
321+
val factor = call.arguments as Double?
322+
if (factor == null) {
323+
result.error(
324+
"missing_data",
325+
"Invalid argument, expected an WanderExtentFactor as Float",
326+
null,
327+
)
328+
return
329+
}
330+
mapView.locationDisplay.wanderExtentFactor = factor.toFloat()
331+
result.success(true)
332+
} catch (e: Throwable) {
333+
result.finishWithError(e, "Setting WanderExtentFactor failed.")
334+
}
335+
}
336+
337+
private fun onGetWanderExtentFactor(
338+
call: MethodCall,
339+
result: MethodChannel.Result
340+
) {
341+
return result.success(mapView.locationDisplay.wanderExtentFactor)
342+
}
343+
270344
private fun onSetLocationDisplayDataSourceType(call: MethodCall, result: MethodChannel.Result) {
271345
if (mapView.locationDisplay.locationDataSource.status == LocationDataSource.Status.STARTED) {
272346
result.error(
@@ -296,7 +370,11 @@ internal class ArcgisMapView(
296370
}
297371
}
298372

299-
else -> result.error("invalid_data", "Unknown data source type ${call.arguments}", null)
373+
else -> result.error(
374+
"invalid_data",
375+
"Unknown data source type ${call.arguments}",
376+
null,
377+
)
300378
}
301379

302380
}
@@ -640,3 +718,10 @@ private fun LoadStatusChangedEvent.jsonValue() = when (newLoadStatus) {
640718
else -> "unknown"
641719
}
642720

721+
private fun String.autoPanModeFromString() = when (this) {
722+
"compassNavigation" -> AutoPanMode.COMPASS_NAVIGATION
723+
"navigation" -> AutoPanMode.NAVIGATION
724+
"recenter" -> AutoPanMode.RECENTER
725+
"off" -> AutoPanMode.OFF
726+
else -> null
727+
}

arcgis_map_sdk_ios/ios/Classes/ArcgisMapView.swift

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
8888
}
8989
map.basemap = AGSBasemap(baseLayers: layers, referenceLayers: nil)
9090
}
91-
9291

9392
map.minScale = convertZoomLevelToMapScale(mapOptions.minZoom)
9493
map.maxScale = convertZoomLevelToMapScale(mapOptions.maxZoom)
@@ -160,6 +159,10 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
160159
case "location_display_set_data_source_type" : onSetLocationDisplayDataSourceType(call, result)
161160
case "update_is_attribution_text_visible": onUpdateIsAttributionTextVisible(call, result)
162161
case "export_image" : onExportImage(result)
162+
case "set_auto_pan_mode": onSetAutoPanMode(call, result)
163+
case "get_auto_pan_mode": onGetAutoPanMode(call, result)
164+
case "set_wander_extent_factor": onSetWanderExtentFactor( call, result)
165+
case "get_wander_extent_factor": onGetWanderExtentFactor( call, result)
163166
default:
164167
result(FlutterError(code: "Unimplemented", message: "No method matching the name \(call.method)", details: nil))
165168
}
@@ -459,7 +462,6 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
459462
operationWithSymbol(call, result) { mapView.locationDisplay.pingAnimationSymbol = $0 }
460463
}
461464

462-
463465
private func onSetLocationDisplayUseCourseSymbolOnMove(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
464466
guard let active = call.arguments as? Bool else {
465467
result(FlutterError(code: "missing_data", message: "Invalid arguments.", details: nil))
@@ -486,6 +488,45 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
486488
result(true)
487489
}
488490

491+
private func onSetAutoPanMode(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
492+
guard let mode = call.arguments as? String else {
493+
result(FlutterError(code: "missing_data", message: "Invalid argument, expected an AutoPanMode as string.", details: nil))
494+
return
495+
}
496+
497+
guard let autoPanMode = mode.autoPanModeFromString() else {
498+
result(FlutterError(code: "invalid_data", message: "Invalid argument, expected an AutoPanMode but got \(mode).", details: nil))
499+
return
500+
}
501+
502+
mapView.locationDisplay.autoPanMode = autoPanMode
503+
result(true)
504+
}
505+
506+
private func onGetAutoPanMode(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
507+
// autoPanMode.rawValue is any of [0; 3]:
508+
// https://developers.arcgis.com/ios/api-reference/_a_g_s_location_display_8h.html
509+
guard let stringName = mapView.locationDisplay.autoPanMode.toName() else {
510+
result(FlutterError(code: "invalid_data", message: "AutoPanMode has invalid state", details: nil))
511+
return
512+
}
513+
return result(stringName)
514+
}
515+
516+
private func onSetWanderExtentFactor(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
517+
guard let factor = call.arguments as? Double else {
518+
result(FlutterError(code: "missing_data", message: "Invalid argument, expected an WanderExtentFactor as Double.", details: nil))
519+
return
520+
}
521+
522+
mapView.locationDisplay.wanderExtentFactor = Float(factor)
523+
result(true)
524+
}
525+
526+
private func onGetWanderExtentFactor(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
527+
return result(mapView.locationDisplay.wanderExtentFactor)
528+
}
529+
489530
private func onSetLocationDisplayDataSourceType(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
490531
if(mapView.locationDisplay.dataSource.status == .started) {
491532
result(FlutterError(code: "invalid_state", message: "Current data source is running. Make sure to stop it before setting a new data source", details: nil))
@@ -518,14 +559,14 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
518559
mapView.isAttributionTextVisible = isVisible
519560
result(true)
520561
}
521-
562+
522563
private func onExportImage(_ result: @escaping FlutterResult) {
523564
mapView.exportImage { image, error in
524565
if let error = error {
525566
result(FlutterError(code: "export_error", message: error.localizedDescription, details: nil))
526567
return
527568
}
528-
569+
529570
if let image = image, let imageData = image.pngData() {
530571
result(FlutterStandardTypedData(bytes: imageData))
531572
} else {
@@ -727,3 +768,37 @@ extension AGSLoadStatus {
727768
}
728769
}
729770
}
771+
772+
extension String {
773+
func autoPanModeFromString() -> AGSLocationDisplayAutoPanMode? {
774+
switch self {
775+
case "compassNavigation":
776+
return .compassNavigation
777+
case "navigation":
778+
return .navigation
779+
case "recenter":
780+
return .recenter
781+
case "off":
782+
return .off
783+
default:
784+
return nil
785+
}
786+
}
787+
}
788+
789+
extension AGSLocationDisplayAutoPanMode {
790+
func toName() -> String? {
791+
switch self {
792+
case .off:
793+
return "off"
794+
case .recenter:
795+
return "recenter"
796+
case .navigation:
797+
return "navigation"
798+
case .compassNavigation:
799+
return "compassNavigation"
800+
@unknown default:
801+
return nil
802+
}
803+
}
804+
}

arcgis_map_sdk_ios/ios/Classes/Models/ArcgisMapOptions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ struct ArcgisMapOptions: Codable {
2525
let yMax: Int
2626
let isAttributionTextVisible: Bool?
2727
}
28+

arcgis_map_sdk_method_channel/lib/src/method_channel_arcgis_map_plugin.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,33 @@ class MethodChannelArcgisMapPlugin extends ArcgisMapPlatform {
4141
throw UnimplementedError('setMouseCursor() has not been implemented');
4242
}
4343

44+
@override
45+
void setAutoPanMode(String autoPanMode, int mapId) {
46+
_methodChannelBuilder(mapId).invokeMethod("set_auto_pan_mode", autoPanMode);
47+
}
48+
49+
@override
50+
Future<AutoPanMode> getAutoPanMode(int mapId) {
51+
return _methodChannelBuilder(mapId)
52+
.invokeMethod<String>("get_auto_pan_mode")
53+
.then((value) => AutoPanMode.values.byName(value!));
54+
}
55+
56+
@override
57+
void setWanderExtentFactor(double factor, int mapId) {
58+
_methodChannelBuilder(mapId).invokeMethod(
59+
"set_wander_extent_factor",
60+
factor,
61+
);
62+
}
63+
64+
@override
65+
Future<double> getWanderExtentFactor(int mapId) {
66+
return _methodChannelBuilder(mapId)
67+
.invokeMethod<double>("get_wander_extent_factor")
68+
.then((value) => value!);
69+
}
70+
4471
@override
4572
void updateGraphicSymbol({
4673
required int mapId,

arcgis_map_sdk_platform_interface/lib/arcgis_map_sdk_platform_interface.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export 'package:arcgis_map_sdk_platform_interface/src/models/user_position.dart'
1010
export 'package:arcgis_map_sdk_platform_interface/src/models/view_position.dart';
1111
export 'package:arcgis_map_sdk_platform_interface/src/types/arcgis_map_options.dart';
1212
export 'package:arcgis_map_sdk_platform_interface/src/types/attributes.dart';
13+
export 'package:arcgis_map_sdk_platform_interface/src/types/auto_pan_mode.dart';
1314
export 'package:arcgis_map_sdk_platform_interface/src/types/bounding_box.dart';
1415
export 'package:arcgis_map_sdk_platform_interface/src/types/default_widget.dart';
1516
export 'package:arcgis_map_sdk_platform_interface/src/types/elevation_mode.dart';

arcgis_map_sdk_platform_interface/lib/src/arcgis_map_sdk_platform_interface.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ class ArcgisMapPlatform extends PlatformInterface {
6868
throw UnimplementedError('setMouseCursor() has not been implemented');
6969
}
7070

71+
void setAutoPanMode(String autoPanMode, int mapId) {
72+
throw UnimplementedError('setAutoPanMode() has not been implemented');
73+
}
74+
75+
Future<AutoPanMode> getAutoPanMode(int mapId) {
76+
throw UnimplementedError('getAutoPanMode() has not been implemented');
77+
}
78+
79+
void setWanderExtentFactor(double factor, int mapId) {
80+
throw UnimplementedError(
81+
'setWanderExtentFactor() has not been implemented',
82+
);
83+
}
84+
85+
Future<double> getWanderExtentFactor(int mapId) {
86+
throw UnimplementedError(
87+
'getWanderExtentFactor() has not been implemented',
88+
);
89+
}
90+
7191
void updateGraphicSymbol({
7292
required int mapId,
7393
required String layerId,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enum AutoPanMode { off, compassNavigation, navigation, recenter }

0 commit comments

Comments
 (0)