From b7a6cf2119969fd5daa304b69497cc9c5f9ca834 Mon Sep 17 00:00:00 2001 From: Benedict Strube Date: Thu, 3 Mar 2022 12:04:26 +0100 Subject: [PATCH] feat(access tracking mode): method to retrieve the current tracking mode Introduces the possibility to retrieve the current tracking mode that is of type `UserLocationCameraMode`. --- src/ui-mapbox/common.ts | 7 ++++++ src/ui-mapbox/index.android.ts | 42 ++++++++++++++++++++++++++++++++++ src/ui-mapbox/index.ios.ts | 23 +++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/src/ui-mapbox/common.ts b/src/ui-mapbox/common.ts index 1364741..3dff688 100755 --- a/src/ui-mapbox/common.ts +++ b/src/ui-mapbox/common.ts @@ -638,6 +638,8 @@ export interface MapboxApi { trackUser(options: TrackUserOptions, nativeMap?: any): Promise; + getUserLocationCameraMode(nativeMap?: any): UserLocationCameraMode; + addSource(id: string, options: AddSourceOptions, nativeMapView?: any): Promise; updateSource(id: string, options: UpdateSourceOptions, nativeMapView?: any): Promise; @@ -832,6 +834,8 @@ export interface MapboxViewApi { trackUser(options: TrackUserOptions): Promise; + getUserLocationCameraMode(nativeMap?: any): UserLocationCameraMode; + showUserLocationMarker(options): void; hideUserLocationMarker(options): void; @@ -1005,6 +1009,9 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox trackUser(options: TrackUserOptions): Promise { return this.mapbox.trackUser(options, this.getNativeMapView()); } + getUserLocationCameraMode(): UserLocationCameraMode { + return this.mapbox.getUserLocationCameraMode(this.getNativeMapView()); + } addSource(id: string, options: AddSourceOptions): Promise { return this.mapbox.addSource(id, options, this.getNativeMapView()); } diff --git a/src/ui-mapbox/index.android.ts b/src/ui-mapbox/index.android.ts index 01b230b..4451622 100755 --- a/src/ui-mapbox/index.android.ts +++ b/src/ui-mapbox/index.android.ts @@ -2970,6 +2970,36 @@ export class Mapbox extends MapboxCommon implements MapboxApi { return renderMode; } + _convertCameraMode( mode: any ): UserLocationCameraMode { + + const modeRef = com.mapbox.mapboxsdk.location.modes.CameraMode; + + switch (mode) { + case modeRef.NONE: + return "NONE"; + + case modeRef.NONE_COMPASS: + return "NONE_COMPASS"; + + case modeRef.NONE_GPS: + return "NONE_GPS"; + + case modeRef.TRACKING: + return "TRACKING"; + + case modeRef.TRACKING_COMPASS: + return "TRACKING_COMPASS"; + + case modeRef.TRACKING_GPS: + return "TRACKING_GPS"; + + case modeRef.TRACKING_GPS_NORTH: + return "TRACKING_GPS_NORTH"; + } + + return "NONE"; + } + _fineLocationPermissionGranted() { let hasPermission = android.os.Build.VERSION.SDK_INT < 23; // Android M. (6.0) @@ -3404,4 +3434,16 @@ export class Mapbox extends MapboxCommon implements MapboxApi { lng: coordinate.getLongitude() } } + + getUserLocationCameraMode(nativeMap?: any): UserLocationCameraMode { + if (!this._mapboxMapInstance) { + return "NONE"; + } + + if (!this._locationComponent) { + return "NONE"; + } + + return this._convertCameraMode(this._locationComponent.getCameraMode()); + } } diff --git a/src/ui-mapbox/index.ios.ts b/src/ui-mapbox/index.ios.ts index c977515..c961c73 100755 --- a/src/ui-mapbox/index.ios.ts +++ b/src/ui-mapbox/index.ios.ts @@ -1821,6 +1821,19 @@ export class Mapbox extends MapboxCommon implements MapboxApi { } } + _convertCameraMode(mode: MGLUserTrackingMode): UserLocationCameraMode { + switch (mode) { + case MGLUserTrackingMode.None: + return "NONE"; + case MGLUserTrackingMode.Follow: + return "TRACKING"; + case MGLUserTrackingMode.FollowWithHeading: + return "TRACKING_COMPASS"; + case MGLUserTrackingMode.FollowWithCourse: + return "TRACKING_GPS_NORTH"; + } + } + /** * show a user location marker * @@ -3174,6 +3187,16 @@ export class Mapbox extends MapboxCommon implements MapboxApi { lng: coordinate.longitude } } + + getUserLocationCameraMode(nativeMap?: any): UserLocationCameraMode { + let theMap: MGLMapView = nativeMap || this._mapboxViewInstance; + + if (!theMap) { + return "NONE"; + } + + return this._convertCameraMode(theMap.userTrackingMode); + } } const _addObserver = (eventName, callback) => NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(eventName, null, NSOperationQueue.mainQueue, callback);