Skip to content

Commit

Permalink
53-support-basic-current-location-indicator (#69)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Feb 7, 2024
1 parent 1686dae commit 6dca8cd
Show file tree
Hide file tree
Showing 24 changed files with 951 additions and 74 deletions.
1 change: 1 addition & 0 deletions arcgis_map_sdk/lib/arcgis_map_sdk.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore: unnecessary_library_directive
library arcgis_map;

export 'package:arcgis_map_sdk/src/arcgis_location_display.dart';
export 'package:arcgis_map_sdk/src/arcgis_map_controller.dart';
export 'package:arcgis_map_sdk/src/arcgis_map_sdk.dart';
export 'package:arcgis_map_sdk/src/model/map_status.dart';
Expand Down
79 changes: 79 additions & 0 deletions arcgis_map_sdk/lib/src/arcgis_location_display.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:arcgis_map_sdk_platform_interface/arcgis_map_sdk_platform_interface.dart';

/// The use case for manual location displays is relevant when the application
/// has its own location stream obtained from a different source, such as a geolocator,
/// with specific settings.
///
/// Instead of relying on ArcGIS to create a location client that fetches the position
/// again, this use case involves processing the locations retrieved by the application
/// and displaying the exact location processed by the application.
///
/// This approach is beneficial when the application needs to manage its own location data
/// independently, without relying on additional calls to fetch the location.
class ArcgisManualLocationDisplay extends ArcgisLocationDisplay {
@override
String get type => "manual";

ArcgisManualLocationDisplay({super.mapId});

Future<void> updateLocation(UserPosition position) {
_assertAttached();
return ArcgisMapPlatform.instance
.updateLocationDisplaySourcePositionManually(
_mapId!,
position,
);
}
}

class ArcgisLocationDisplay {
int? _mapId;
final String type = "system";

ArcgisLocationDisplay({int? mapId}) : _mapId = mapId;

void attachToMap(int mapId) => _mapId = mapId;

void deattachFromMap() => _mapId = null;

Future<void> startSource() {
_assertAttached();
return ArcgisMapPlatform.instance.startLocationDisplayDataSource(_mapId!);
}

Future<void> stopSource() {
_assertAttached();
return ArcgisMapPlatform.instance.stopLocationDisplayDataSource(_mapId!);
}

Future<void> setDefaultSymbol(Symbol symbol) {
_assertAttached();
return ArcgisMapPlatform.instance
.setLocationDisplayDefaultSymbol(_mapId!, symbol);
}

Future<void> setAccuracySymbol(Symbol symbol) {
_assertAttached();
return ArcgisMapPlatform.instance
.setLocationDisplayAccuracySymbol(_mapId!, symbol);
}

Future<void> setPingAnimationSymbol(Symbol symbol) {
_assertAttached();
return ArcgisMapPlatform.instance
.setLocationDisplayPingAnimationSymbol(_mapId!, symbol);
}

Future<void> setUseCourseSymbolOnMovement(bool useCourseSymbol) {
_assertAttached();
return ArcgisMapPlatform.instance
.setUseCourseSymbolOnMovement(_mapId!, useCourseSymbol);
}

void _assertAttached() {
assert(
_mapId != null,
"LocationDisplay has not been attached to any map. Make sure to call ArcgisMapController.setLocationDisplay.",
);
}
}
19 changes: 18 additions & 1 deletion arcgis_map_sdk/lib/src/arcgis_map_controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:arcgis_map_sdk/src/arcgis_location_display.dart';
import 'package:arcgis_map_sdk/src/model/map_status.dart';
import 'package:arcgis_map_sdk_platform_interface/arcgis_map_sdk_platform_interface.dart';
import 'package:flutter/services.dart';
Expand All @@ -7,7 +8,7 @@ typedef MapStatusListener = void Function(MapStatus status);
class ArcgisMapController {
ArcgisMapController._({
required this.mapId,
}) {
}) : _locationDisplay = ArcgisLocationDisplay(mapId: mapId) {
ArcgisMapPlatform.instance.setMethodCallHandler(
mapId: mapId,
onCall: _onCall,
Expand All @@ -16,6 +17,10 @@ class ArcgisMapController {

final int mapId;

late ArcgisLocationDisplay _locationDisplay;

ArcgisLocationDisplay get locationDisplay => _locationDisplay;

final _listeners = <MapStatusListener>[];
MapStatus _mapStatus = MapStatus.unknown;

Expand Down Expand Up @@ -184,6 +189,7 @@ class ArcgisMapController {
}

/// Adds a listener that gets notified if the map status changes.
/// The listener can be removed by calling the [VoidCallback] returned by this function.
VoidCallback addStatusChangeListener(MapStatusListener listener) {
_listeners.add(listener);
return () => _listeners.removeWhere((l) => l == listener);
Expand Down Expand Up @@ -303,4 +309,15 @@ class ArcgisMapController {
List<String> getVisibleGraphicIds() {
return ArcgisMapPlatform.instance.getVisibleGraphicIds(mapId);
}

Future<void> setLocationDisplay(ArcgisLocationDisplay locationDisplay) {
return ArcgisMapPlatform.instance
.setLocationDisplay(mapId, locationDisplay.type)
.whenComplete(
() {
_locationDisplay.deattachFromMap();
_locationDisplay = locationDisplay..attachToMap(mapId);
},
);
}
}
Loading

0 comments on commit 6dca8cd

Please sign in to comment.