Skip to content

Commit b7a6cf2

Browse files
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`.
1 parent f339929 commit b7a6cf2

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

src/ui-mapbox/common.ts

+7
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,8 @@ export interface MapboxApi {
638638

639639
trackUser(options: TrackUserOptions, nativeMap?: any): Promise<void>;
640640

641+
getUserLocationCameraMode(nativeMap?: any): UserLocationCameraMode;
642+
641643
addSource(id: string, options: AddSourceOptions, nativeMapView?: any): Promise<any>;
642644

643645
updateSource(id: string, options: UpdateSourceOptions, nativeMapView?: any): Promise<any>;
@@ -832,6 +834,8 @@ export interface MapboxViewApi {
832834

833835
trackUser(options: TrackUserOptions): Promise<any>;
834836

837+
getUserLocationCameraMode(nativeMap?: any): UserLocationCameraMode;
838+
835839
showUserLocationMarker(options): void;
836840

837841
hideUserLocationMarker(options): void;
@@ -1005,6 +1009,9 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox
10051009
trackUser(options: TrackUserOptions): Promise<any> {
10061010
return this.mapbox.trackUser(options, this.getNativeMapView());
10071011
}
1012+
getUserLocationCameraMode(): UserLocationCameraMode {
1013+
return this.mapbox.getUserLocationCameraMode(this.getNativeMapView());
1014+
}
10081015
addSource(id: string, options: AddSourceOptions): Promise<any> {
10091016
return this.mapbox.addSource(id, options, this.getNativeMapView());
10101017
}

src/ui-mapbox/index.android.ts

+42
Original file line numberDiff line numberDiff line change
@@ -2970,6 +2970,36 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
29702970
return renderMode;
29712971
}
29722972

2973+
_convertCameraMode( mode: any ): UserLocationCameraMode {
2974+
2975+
const modeRef = com.mapbox.mapboxsdk.location.modes.CameraMode;
2976+
2977+
switch (mode) {
2978+
case modeRef.NONE:
2979+
return "NONE";
2980+
2981+
case modeRef.NONE_COMPASS:
2982+
return "NONE_COMPASS";
2983+
2984+
case modeRef.NONE_GPS:
2985+
return "NONE_GPS";
2986+
2987+
case modeRef.TRACKING:
2988+
return "TRACKING";
2989+
2990+
case modeRef.TRACKING_COMPASS:
2991+
return "TRACKING_COMPASS";
2992+
2993+
case modeRef.TRACKING_GPS:
2994+
return "TRACKING_GPS";
2995+
2996+
case modeRef.TRACKING_GPS_NORTH:
2997+
return "TRACKING_GPS_NORTH";
2998+
}
2999+
3000+
return "NONE";
3001+
}
3002+
29733003
_fineLocationPermissionGranted() {
29743004
let hasPermission = android.os.Build.VERSION.SDK_INT < 23; // Android M. (6.0)
29753005

@@ -3404,4 +3434,16 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
34043434
lng: coordinate.getLongitude()
34053435
}
34063436
}
3437+
3438+
getUserLocationCameraMode(nativeMap?: any): UserLocationCameraMode {
3439+
if (!this._mapboxMapInstance) {
3440+
return "NONE";
3441+
}
3442+
3443+
if (!this._locationComponent) {
3444+
return "NONE";
3445+
}
3446+
3447+
return this._convertCameraMode(this._locationComponent.getCameraMode());
3448+
}
34073449
}

src/ui-mapbox/index.ios.ts

+23
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,19 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
18211821
}
18221822
}
18231823

1824+
_convertCameraMode(mode: MGLUserTrackingMode): UserLocationCameraMode {
1825+
switch (mode) {
1826+
case MGLUserTrackingMode.None:
1827+
return "NONE";
1828+
case MGLUserTrackingMode.Follow:
1829+
return "TRACKING";
1830+
case MGLUserTrackingMode.FollowWithHeading:
1831+
return "TRACKING_COMPASS";
1832+
case MGLUserTrackingMode.FollowWithCourse:
1833+
return "TRACKING_GPS_NORTH";
1834+
}
1835+
}
1836+
18241837
/**
18251838
* show a user location marker
18261839
*
@@ -3174,6 +3187,16 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
31743187
lng: coordinate.longitude
31753188
}
31763189
}
3190+
3191+
getUserLocationCameraMode(nativeMap?: any): UserLocationCameraMode {
3192+
let theMap: MGLMapView = nativeMap || this._mapboxViewInstance;
3193+
3194+
if (!theMap) {
3195+
return "NONE";
3196+
}
3197+
3198+
return this._convertCameraMode(theMap.userTrackingMode);
3199+
}
31773200
}
31783201

31793202
const _addObserver = (eventName, callback) => NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(eventName, null, NSOperationQueue.mainQueue, callback);

0 commit comments

Comments
 (0)