Skip to content

Commit 6dca8cd

Browse files
53-support-basic-current-location-indicator (#69)
* catch exceptions while parsing and fix poliline on mobile * add missing return * initial draft on iOS * add symbol methods to controller * parse symbol * implement useCourseSymbolOnMovement * implement new type of location display data source * finish iOS location indicator impl * implement android * fix bug for manual location source on android * add try catch * update docs --------- Co-authored-by: Julian Bissekkou <[email protected]> Co-authored-by: sbergmair <[email protected]>
1 parent 1686dae commit 6dca8cd

File tree

24 files changed

+951
-74
lines changed

24 files changed

+951
-74
lines changed

arcgis_map_sdk/lib/arcgis_map_sdk.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// ignore: unnecessary_library_directive
22
library arcgis_map;
33

4+
export 'package:arcgis_map_sdk/src/arcgis_location_display.dart';
45
export 'package:arcgis_map_sdk/src/arcgis_map_controller.dart';
56
export 'package:arcgis_map_sdk/src/arcgis_map_sdk.dart';
67
export 'package:arcgis_map_sdk/src/model/map_status.dart';
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import 'package:arcgis_map_sdk_platform_interface/arcgis_map_sdk_platform_interface.dart';
2+
3+
/// The use case for manual location displays is relevant when the application
4+
/// has its own location stream obtained from a different source, such as a geolocator,
5+
/// with specific settings.
6+
///
7+
/// Instead of relying on ArcGIS to create a location client that fetches the position
8+
/// again, this use case involves processing the locations retrieved by the application
9+
/// and displaying the exact location processed by the application.
10+
///
11+
/// This approach is beneficial when the application needs to manage its own location data
12+
/// independently, without relying on additional calls to fetch the location.
13+
class ArcgisManualLocationDisplay extends ArcgisLocationDisplay {
14+
@override
15+
String get type => "manual";
16+
17+
ArcgisManualLocationDisplay({super.mapId});
18+
19+
Future<void> updateLocation(UserPosition position) {
20+
_assertAttached();
21+
return ArcgisMapPlatform.instance
22+
.updateLocationDisplaySourcePositionManually(
23+
_mapId!,
24+
position,
25+
);
26+
}
27+
}
28+
29+
class ArcgisLocationDisplay {
30+
int? _mapId;
31+
final String type = "system";
32+
33+
ArcgisLocationDisplay({int? mapId}) : _mapId = mapId;
34+
35+
void attachToMap(int mapId) => _mapId = mapId;
36+
37+
void deattachFromMap() => _mapId = null;
38+
39+
Future<void> startSource() {
40+
_assertAttached();
41+
return ArcgisMapPlatform.instance.startLocationDisplayDataSource(_mapId!);
42+
}
43+
44+
Future<void> stopSource() {
45+
_assertAttached();
46+
return ArcgisMapPlatform.instance.stopLocationDisplayDataSource(_mapId!);
47+
}
48+
49+
Future<void> setDefaultSymbol(Symbol symbol) {
50+
_assertAttached();
51+
return ArcgisMapPlatform.instance
52+
.setLocationDisplayDefaultSymbol(_mapId!, symbol);
53+
}
54+
55+
Future<void> setAccuracySymbol(Symbol symbol) {
56+
_assertAttached();
57+
return ArcgisMapPlatform.instance
58+
.setLocationDisplayAccuracySymbol(_mapId!, symbol);
59+
}
60+
61+
Future<void> setPingAnimationSymbol(Symbol symbol) {
62+
_assertAttached();
63+
return ArcgisMapPlatform.instance
64+
.setLocationDisplayPingAnimationSymbol(_mapId!, symbol);
65+
}
66+
67+
Future<void> setUseCourseSymbolOnMovement(bool useCourseSymbol) {
68+
_assertAttached();
69+
return ArcgisMapPlatform.instance
70+
.setUseCourseSymbolOnMovement(_mapId!, useCourseSymbol);
71+
}
72+
73+
void _assertAttached() {
74+
assert(
75+
_mapId != null,
76+
"LocationDisplay has not been attached to any map. Make sure to call ArcgisMapController.setLocationDisplay.",
77+
);
78+
}
79+
}

arcgis_map_sdk/lib/src/arcgis_map_controller.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:arcgis_map_sdk/src/arcgis_location_display.dart';
12
import 'package:arcgis_map_sdk/src/model/map_status.dart';
23
import 'package:arcgis_map_sdk_platform_interface/arcgis_map_sdk_platform_interface.dart';
34
import 'package:flutter/services.dart';
@@ -7,7 +8,7 @@ typedef MapStatusListener = void Function(MapStatus status);
78
class ArcgisMapController {
89
ArcgisMapController._({
910
required this.mapId,
10-
}) {
11+
}) : _locationDisplay = ArcgisLocationDisplay(mapId: mapId) {
1112
ArcgisMapPlatform.instance.setMethodCallHandler(
1213
mapId: mapId,
1314
onCall: _onCall,
@@ -16,6 +17,10 @@ class ArcgisMapController {
1617

1718
final int mapId;
1819

20+
late ArcgisLocationDisplay _locationDisplay;
21+
22+
ArcgisLocationDisplay get locationDisplay => _locationDisplay;
23+
1924
final _listeners = <MapStatusListener>[];
2025
MapStatus _mapStatus = MapStatus.unknown;
2126

@@ -184,6 +189,7 @@ class ArcgisMapController {
184189
}
185190

186191
/// Adds a listener that gets notified if the map status changes.
192+
/// The listener can be removed by calling the [VoidCallback] returned by this function.
187193
VoidCallback addStatusChangeListener(MapStatusListener listener) {
188194
_listeners.add(listener);
189195
return () => _listeners.removeWhere((l) => l == listener);
@@ -303,4 +309,15 @@ class ArcgisMapController {
303309
List<String> getVisibleGraphicIds() {
304310
return ArcgisMapPlatform.instance.getVisibleGraphicIds(mapId);
305311
}
312+
313+
Future<void> setLocationDisplay(ArcgisLocationDisplay locationDisplay) {
314+
return ArcgisMapPlatform.instance
315+
.setLocationDisplay(mapId, locationDisplay.type)
316+
.whenComplete(
317+
() {
318+
_locationDisplay.deattachFromMap();
319+
_locationDisplay = locationDisplay..attachToMap(mapId);
320+
},
321+
);
322+
}
306323
}

0 commit comments

Comments
 (0)