Skip to content

Commit

Permalink
implement useCourseSymbolOnMovement
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianBissekkou committed Nov 27, 2023
1 parent e66d60f commit a5c6a29
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 32 deletions.
5 changes: 5 additions & 0 deletions arcgis_map_sdk/lib/src/arcgis_map_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class ArcgisLocationDisplay {
return ArcgisMapPlatform.instance
.setLocationDisplayPingAnimationSymbol(mapId, symbol);
}

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

class ArcgisMapController {
Expand Down
36 changes: 25 additions & 11 deletions arcgis_map_sdk_ios/ios/Classes/ArcgisMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
case "location_display_set_default_symbol": onSetLocationDisplayDefaultSymbol(call, result)
case "location_display_set_accuracy_symbol": onSetLocationDisplayAccuracySymbol(call, result)
case "location_display_set_ping_animation_symbol" : onSetLocationDisplayPingAnimationSymbol(call, result)
case "location_display_set_use_course_symbol_on_move" : onSetLocationDisplayUseCourseSymbolOnMove(call, result)
default:
result(FlutterError(code: "Unimplemented", message: "No method matching the name\(call.method)", details: nil))
}
Expand Down Expand Up @@ -320,28 +321,41 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
}

private func onSetLocationDisplayDefaultSymbol(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
operationWithSymbol(call, result) { mapView.locationDisplay.defaultSymbol = $0 }
}

private func onSetLocationDisplayAccuracySymbol(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
operationWithSymbol(call, result) { mapView.locationDisplay.accuracySymbol = $0 }
}

private func onSetLocationDisplayPingAnimationSymbol(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
operationWithSymbol(call, result) { mapView.locationDisplay.pingAnimationSymbol = $0 }
}


private func onSetLocationDisplayUseCourseSymbolOnMove(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
guard let active = call.arguments as? Bool else {
result(FlutterError(code: "missing_data", message: "Invalid arguments.", details: nil))
return
}

mapView.locationDisplay.useCourseSymbolOnMovement = active
result(true)
}

private func operationWithSymbol(_ call: FlutterMethodCall, _ result: @escaping FlutterResult, handler: (AGSSymbol) -> Void) {
do {
guard let args = call.arguments as? [String: Any] else {
result(FlutterError(code: "missing_data", message: "Invalid arguments", details: nil))
return
}
let symbol = try GraphicsParser().parseSymbol(args)
mapView.locationDisplay.defaultSymbol = symbol
handler(symbol)
result(true)
}
catch {
result(FlutterError(code: "unknown_error", message: "Error while adding graphic. \(error)", details: nil))
return
}
result(true)
}

private func onSetLocationDisplayAccuracySymbol(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
result(true)
}

private func onSetLocationDisplayPingAnimationSymbol(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
result(true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,12 @@ class MethodChannelArcgisMapPlugin extends ArcgisMapPlatform {
symbol.toJson(),
);
}

@override
Future<void> setUseCourseSymbolOnMovement(int mapId, bool useCourseSymbol) {
return _methodChannelBuilder(mapId).invokeMethod(
"location_display_set_use_course_symbol_on_move",
useCourseSymbol,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,10 @@ class ArcgisMapPlatform extends PlatformInterface {
'setLocationDisplayPingAnimationSymbol() has not been implemented.',
);
}

Future<void> setUseCourseSymbolOnMovement(int mapId, bool useCourseSymbol) {
throw UnimplementedError(
'setUseCourseSymbolOnMovement() has not been implemented.',
);
}
}
75 changes: 54 additions & 21 deletions example/lib/location_indicator_example_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class _LocationIndicatorExamplePageState
final _snackBarKey = GlobalKey<ScaffoldState>();
ArcgisMapController? _controller;
bool _isStarted = false;
bool _useCourseSymbolForMovement = false;

@override
Widget build(BuildContext context) {
Expand All @@ -41,17 +42,48 @@ class _LocationIndicatorExamplePageState
setState(() => _isStarted = !_isStarted);
},
),
body: ArcgisMap(
apiKey: arcGisApiKey,
initialCenter: const LatLng(51.16, 10.45),
zoom: 13,
basemap: BaseMap.arcgisNavigationNight,
mapStyle: MapStyle.twoD,
onMapCreated: (controller) {
_controller = controller;
_requestLocationPermission();
_configureLocationDisplay();
},
body: Column(
children: [
Expanded(
child: ArcgisMap(
apiKey: arcGisApiKey,
initialCenter: const LatLng(51.16, 10.45),
zoom: 13,
basemap: BaseMap.arcgisNavigationNight,
mapStyle: MapStyle.twoD,
onMapCreated: (controller) {
_controller = controller;
_requestLocationPermission();
_configureLocationDisplay(Colors.blue);
},
),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => _configureLocationDisplay(Colors.green),
child: Text("tint indicator green"),
),
const SizedBox(width: 8),
ElevatedButton(
onPressed: () => _configureLocationDisplay(Colors.red),
child: Text("tint indicator red"),
),
ElevatedButton(
onPressed: () {
setState(
() =>
_useCourseSymbolForMovement = !_useCourseSymbolForMovement,
);
_configureLocationDisplay(Colors.red);
},
child: Text(
_useCourseSymbolForMovement
? "Disable course indicator"
: "Enable course indicator",
),
),
SizedBox(height: MediaQuery.paddingOf(context).bottom),
],
),
);
}
Expand All @@ -63,28 +95,29 @@ class _LocationIndicatorExamplePageState

await _controller!.moveCamera(
point: LatLng(location.latitude, location.longitude),
zoomLevel: 12,
zoomLevel: 16,
);
}

Future<void> _configureLocationDisplay() async {
Future<void> _configureLocationDisplay(MaterialColor color) async {
await _controller!.locationDisplay.setUseCourseSymbolOnMovement(
_useCourseSymbolForMovement,
);
await _controller!.locationDisplay.setDefaultSymbol(
SimpleMarkerSymbol(
color: Colors.pink,
outlineColor: Colors.amberAccent,
color: color.shade100,
outlineColor: color.shade500,
radius: 24,
),
);
await _controller!.locationDisplay.setPingAnimationSymbol(
SimpleMarkerSymbol(
color: Colors.blueAccent,
outlineColor: Colors.blue.withOpacity(0.5),
color: color.shade50,
outlineColor: color.shade900,
),
);
await _controller!.locationDisplay.setAccuracySymbol(
SimpleMarkerSymbol(
color: Colors.deepPurple,
outlineColor: Colors.deepPurple,
),
SimpleLineSymbol(color: color.shade800, width: 3),
);
}
}

0 comments on commit a5c6a29

Please sign in to comment.