Skip to content

Commit 236e511

Browse files
authored
Merge pull request #84 from tappeddev/add-rotation-and-fix-smaller-issues
add-rotation-and-fix-smaller-issues
2 parents 7c43b4e + 8ae15e9 commit 236e511

File tree

10 files changed

+94
-41
lines changed

10 files changed

+94
-41
lines changed

arcgis_map_sdk/lib/src/arcgis_location_display.dart

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

50-
void setAutoPanMode(AutoPanMode autoPanMode) {
50+
Future<void> setAutoPanMode(AutoPanMode autoPanMode) {
5151
_assertAttached();
52-
ArcgisMapPlatform.instance.setAutoPanMode(autoPanMode.name, _mapId!);
52+
return ArcgisMapPlatform.instance.setAutoPanMode(autoPanMode.name, _mapId!);
5353
}
5454

5555
Future<AutoPanMode> getAutoPanMode() {

arcgis_map_sdk/lib/src/arcgis_map_controller.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ class ArcgisMapController {
242242
);
243243
}
244244

245+
Future<void> setRotation(double angleDegrees) {
246+
return ArcgisMapPlatform.instance.setRotation(angleDegrees, mapId);
247+
}
248+
245249
Future<void> addGraphic({required String layerId, required Graphic graphic}) {
246250
return ArcgisMapPlatform.instance.addGraphic(mapId, layerId, graphic);
247251
}

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +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
29+
import com.esri.arcgisruntime.mapping.view.LocationDisplay.AutoPanMode.*
3030
import com.esri.arcgisruntime.mapping.view.MapView
3131
import com.esri.arcgisruntime.symbology.Symbol
3232
import com.google.gson.reflect.TypeToken
@@ -101,7 +101,7 @@ internal class ArcgisMapView(
101101
mapView.graphicsOverlays.add(defaultGraphicsOverlay)
102102

103103
mapView.addMapScaleChangedListener {
104-
if(mapView.mapScale.isNaN()) return@addMapScaleChangedListener
104+
if (mapView.mapScale.isNaN()) return@addMapScaleChangedListener
105105

106106
val zoomLevel = getZoomLevel(mapView)
107107
zoomStreamHandler.addZoom(zoomLevel)
@@ -114,9 +114,11 @@ internal class ArcgisMapView(
114114
val center = mapView.visibleArea?.extent?.center ?: return@addViewpointChangedListener
115115
val wgs84Center = GeometryEngine.project(center, SpatialReferences.getWgs84()) as? Point
116116

117-
val latLng = wgs84Center?.let {
118-
LatLng(longitude = it.x,latitude = it.y)
119-
} ?: return@addViewpointChangedListener
117+
if (wgs84Center == null || wgs84Center.x.isNaN() || wgs84Center.y.isNaN()) {
118+
return@addViewpointChangedListener
119+
}
120+
121+
val latLng = LatLng(longitude = wgs84Center.x, latitude = wgs84Center.y)
120122

121123
centerPositionStreamHandler.add(latLng)
122124
}
@@ -150,6 +152,7 @@ internal class ArcgisMapView(
150152
when (call.method) {
151153
"zoom_in" -> onZoomIn(call = call, result = result)
152154
"zoom_out" -> onZoomOut(call = call, result = result)
155+
"rotate" -> onRotate(call = call, result = result)
153156
"add_view_padding" -> onAddViewPadding(call = call, result = result)
154157
"set_interaction" -> onSetInteraction(call = call, result = result)
155158
"move_camera" -> onMoveCamera(call = call, result = result)
@@ -311,7 +314,14 @@ internal class ArcgisMapView(
311314
result: MethodChannel.Result
312315
) {
313316
try {
314-
return result.success(mapView.locationDisplay.autoPanMode.name)
317+
return result.success(
318+
when (mapView.locationDisplay.autoPanMode) {
319+
OFF -> "off"
320+
RECENTER -> "recenter"
321+
NAVIGATION -> "navigation"
322+
COMPASS_NAVIGATION -> "compassNavigation"
323+
}
324+
)
315325
} catch (e: Throwable) {
316326
result.finishWithError(e, "Getting AutoPanMode failed.")
317327
}
@@ -446,6 +456,11 @@ internal class ArcgisMapView(
446456
}
447457
}
448458

459+
private fun onRotate(call: MethodCall, result: MethodChannel.Result) {
460+
val angleDegrees = call.arguments as Double
461+
result.finishWithFuture { mapView.setViewpointRotationAsync(angleDegrees) }
462+
}
463+
449464
private fun onAddViewPadding(call: MethodCall, result: MethodChannel.Result) {
450465
try {
451466
val optionParams = call.arguments as Map<String, Any>
@@ -723,9 +738,9 @@ private fun LoadStatusChangedEvent.jsonValue() = when (newLoadStatus) {
723738
}
724739

725740
private fun String.autoPanModeFromString() = when (this) {
726-
"compassNavigation" -> AutoPanMode.COMPASS_NAVIGATION
727-
"navigation" -> AutoPanMode.NAVIGATION
728-
"recenter" -> AutoPanMode.RECENTER
729-
"off" -> AutoPanMode.OFF
741+
"compassNavigation" -> COMPASS_NAVIGATION
742+
"navigation" -> NAVIGATION
743+
"recenter" -> RECENTER
744+
"off" -> OFF
730745
else -> null
731746
}

arcgis_map_sdk_ios/ios/Classes/ArcgisMapView.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
141141
switch (call.method) {
142142
case "zoom_in": onZoomIn(call, result)
143143
case "zoom_out": onZoomOut(call, result)
144+
case "rotate" : onRotate(call, result)
144145
case "add_view_padding": onAddViewPadding(call, result)
145146
case "set_interaction": onSetInteraction(call, result)
146147
case "move_camera": onMoveCamera(call, result)
@@ -160,7 +161,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
160161
case "update_is_attribution_text_visible": onUpdateIsAttributionTextVisible(call, result)
161162
case "export_image" : onExportImage(result)
162163
case "set_auto_pan_mode": onSetAutoPanMode(call, result)
163-
case "get_auto_pan_mode": onGetAutoPanMode(call, result)
164+
case "get_auto_pan_mode": onGetAutoPanMode(call, result)
164165
case "set_wander_extent_factor": onSetWanderExtentFactor( call, result)
165166
case "get_wander_extent_factor": onGetWanderExtentFactor( call, result)
166167
default:
@@ -222,6 +223,17 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
222223
result(success)
223224
}
224225
}
226+
227+
private func onRotate(_ call: FlutterMethodCall, _ result:@escaping FlutterResult) {
228+
guard let angleDouble = call.arguments as? Double else {
229+
result(FlutterError(code: "missing_data", message: "Invalid arguments", details: nil))
230+
return
231+
}
232+
233+
mapView.setViewpointRotation(angleDouble) { success in
234+
result(success)
235+
}
236+
}
225237

226238
private func onAddViewPadding(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
227239
guard let args = call.arguments as? [String: Any] else {

arcgis_map_sdk_method_channel/lib/src/method_channel_arcgis_map_plugin.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ class MethodChannelArcgisMapPlugin extends ArcgisMapPlatform {
4242
}
4343

4444
@override
45-
void setAutoPanMode(String autoPanMode, int mapId) {
46-
_methodChannelBuilder(mapId).invokeMethod("set_auto_pan_mode", autoPanMode);
45+
Future<void> setAutoPanMode(String autoPanMode, int mapId) {
46+
return _methodChannelBuilder(mapId).invokeMethod("set_auto_pan_mode", autoPanMode);
47+
}
48+
49+
@override
50+
Future<void> setRotation(double angleDegrees, int mapId) {
51+
return _methodChannelBuilder(mapId).invokeMethod("rotate", angleDegrees);
4752
}
4853

4954
@override

arcgis_map_sdk_platform_interface/lib/src/arcgis_map_sdk_platform_interface.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ class ArcgisMapPlatform extends PlatformInterface {
6868
throw UnimplementedError('setMouseCursor() has not been implemented');
6969
}
7070

71-
void setAutoPanMode(String autoPanMode, int mapId) {
71+
Future<void> setAutoPanMode(String autoPanMode, int mapId) {
7272
throw UnimplementedError('setAutoPanMode() has not been implemented');
7373
}
7474

75+
Future<void> setRotation(double angleDegrees, int mapId) {
76+
throw UnimplementedError('setRotation() has not been implemented');
77+
}
78+
7579
Future<AutoPanMode> getAutoPanMode(int mapId) {
7680
throw UnimplementedError('getAutoPanMode() has not been implemented');
7781
}

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ EXTERNAL SOURCES:
3030
SPEC CHECKSUMS:
3131
ArcGIS-Runtime-SDK-iOS: 6ab51d28f8831ac73c00d34998cff3a555fe304f
3232
ArcGIS-Runtime-Toolkit-iOS: e30bb45bd0bd0152bcb1ec73f9b99022a5c7d02d
33-
arcgis_map_sdk_ios: ee1d8dee42e0c11c95cd26afa2a8cb0e7a69cb23
33+
arcgis_map_sdk_ios: deb0d9d2dfedca86984c0aa81e6245eed03c8344
3434
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
35-
geolocator_apple: cc556e6844d508c95df1e87e3ea6fa4e58c50401
35+
geolocator_apple: d981750b9f47dbdb02427e1476d9a04397beb8d9
3636

3737
PODFILE CHECKSUM: cc1f88378b4bfcf93a6ce00d2c587857c6008d3b
3838

39-
COCOAPODS: 1.15.2
39+
COCOAPODS: 1.16.2

example/ios/Runner/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UIKit
22
import Flutter
33

4-
@UIApplicationMain
4+
@main
55
@objc class AppDelegate: FlutterAppDelegate {
66
override func application(
77
_ application: UIApplication,

example/lib/location_indicator_example_page.dart

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:math';
23

34
import 'package:arcgis_example/main.dart';
@@ -9,12 +10,10 @@ class LocationIndicatorExamplePage extends StatefulWidget {
910
const LocationIndicatorExamplePage({super.key});
1011

1112
@override
12-
State<LocationIndicatorExamplePage> createState() =>
13-
_LocationIndicatorExamplePageState();
13+
State<LocationIndicatorExamplePage> createState() => _LocationIndicatorExamplePageState();
1414
}
1515

16-
class _LocationIndicatorExamplePageState
17-
extends State<LocationIndicatorExamplePage> {
16+
class _LocationIndicatorExamplePageState extends State<LocationIndicatorExamplePage> {
1817
final _mockLocations = [
1918
LatLng(48.1234963, 11.5910182),
2019
LatLng(48.1239241, 11.45897063),
@@ -34,6 +33,8 @@ class _LocationIndicatorExamplePageState
3433
var _activeAutoPanMode = AutoPanMode.off;
3534
var _wanderExtentFactor = 0.5;
3635

36+
StreamSubscription? _panUpdateSubscription;
37+
3738
@override
3839
Widget build(BuildContext context) {
3940
return Scaffold(
@@ -48,8 +49,7 @@ class _LocationIndicatorExamplePageState
4849
: await _controller!.locationDisplay.startSource();
4950
} catch (e, stack) {
5051
if (!mounted) return;
51-
ScaffoldMessenger.of(_snackBarKey.currentContext!)
52-
.showSnackBar(SnackBar(content: Text("$e")));
52+
ScaffoldMessenger.of(_snackBarKey.currentContext!).showSnackBar(SnackBar(content: Text("$e")));
5353
debugPrint("$e");
5454
debugPrintStack(stackTrace: stack);
5555
}
@@ -71,16 +71,18 @@ class _LocationIndicatorExamplePageState
7171
_controller = controller;
7272
_requestLocationPermission();
7373
_configureLocationDisplay(Colors.blue);
74+
75+
_panUpdateSubscription?.cancel();
76+
_panUpdateSubscription = controller.centerPosition().listen((_) => _refreshAutoPanMode());
7477
},
7578
),
7679
),
7780
const SizedBox(height: 16),
81+
Text("Current auto pan mode: ${_activeAutoPanMode.name}"),
7882
ElevatedButton(
7983
onPressed: _switchLocationSource,
8084
child: Text(
81-
_isManualLocationSource
82-
? "Use auto location source"
83-
: "Use manual location source",
85+
_isManualLocationSource ? "Use auto location source" : "Use manual location source",
8486
),
8587
),
8688
if (_isManualLocationSource) ...[
@@ -101,15 +103,12 @@ class _LocationIndicatorExamplePageState
101103
ElevatedButton(
102104
onPressed: () {
103105
setState(
104-
() =>
105-
_useCourseSymbolForMovement = !_useCourseSymbolForMovement,
106+
() => _useCourseSymbolForMovement = !_useCourseSymbolForMovement,
106107
);
107108
_configureLocationDisplay(Colors.red);
108109
},
109110
child: Text(
110-
_useCourseSymbolForMovement
111-
? "Disable course indicator"
112-
: "Enable course indicator",
111+
_useCourseSymbolForMovement ? "Disable course indicator" : "Enable course indicator",
113112
),
114113
),
115114
ElevatedButton(
@@ -158,9 +157,7 @@ class _LocationIndicatorExamplePageState
158157
Future<void> _switchLocationSource() async {
159158
await _controller!.locationDisplay.stopSource();
160159
await _controller!.setLocationDisplay(
161-
_isManualLocationSource
162-
? ArcgisLocationDisplay()
163-
: ArcgisManualLocationDisplay(),
160+
_isManualLocationSource ? ArcgisLocationDisplay() : ArcgisManualLocationDisplay(),
164161
);
165162
setState(() => _isManualLocationSource = !_isManualLocationSource);
166163

@@ -237,13 +234,30 @@ class _LocationIndicatorExamplePageState
237234
);
238235

239236
if (newSetAutoPanMode != null) {
240-
// No need to use setState
241-
_activeAutoPanMode = newSetAutoPanMode;
237+
setState(() => _activeAutoPanMode = newSetAutoPanMode);
242238
_controller?.locationDisplay.setAutoPanMode(newSetAutoPanMode);
243239
}
244240
if (_activeAutoPanMode == AutoPanMode.recenter) {
245241
_wanderExtentFactor = newSetWanderExtentFactor;
246242
_controller?.locationDisplay.setWanderExtentFactor(_wanderExtentFactor);
247243
}
248244
}
245+
246+
@override
247+
void dispose() {
248+
_panUpdateSubscription?.cancel();
249+
_refreshAutoPanModeTimer?.cancel();
250+
super.dispose();
251+
}
252+
253+
Timer? _refreshAutoPanModeTimer;
254+
255+
Future<void> _refreshAutoPanMode() async {
256+
_refreshAutoPanModeTimer?.cancel();
257+
_refreshAutoPanModeTimer = Timer(const Duration(milliseconds: 50), () async {
258+
final panMode = await _controller!.locationDisplay.getAutoPanMode();
259+
if (!mounted) return;
260+
setState(() => _activeAutoPanMode = panMode);
261+
});
262+
}
249263
}

example/pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ environment:
1111

1212
dependencies:
1313
arcgis_map_sdk: ^0.8.0
14-
1514
cupertino_icons: ^1.0.0
1615
geolocator: ^10.1.0
1716
flutter:
@@ -42,4 +41,4 @@ dependency_overrides:
4241
arcgis_map_sdk_platform_interface:
4342
path: ../arcgis_map_sdk_platform_interface
4443
arcgis_map_sdk_web:
45-
path: ../arcgis_map_sdk_web
44+
path: ../arcgis_map_sdk_web

0 commit comments

Comments
 (0)