Skip to content

Commit 9182871

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 78803e4 commit 9182871

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
@@ -2971,6 +2971,36 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
29712971
return renderMode;
29722972
}
29732973

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

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

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
*
@@ -3175,6 +3188,16 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
31753188
lng: coordinate.longitude
31763189
}
31773190
}
3191+
3192+
getUserLocationCameraMode(nativeMap?: any): UserLocationCameraMode {
3193+
let theMap: MGLMapView = nativeMap || this._mapboxViewInstance;
3194+
3195+
if (!theMap) {
3196+
return "NONE";
3197+
}
3198+
3199+
return this._convertCameraMode(theMap.userTrackingMode);
3200+
}
31783201
}
31793202

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

0 commit comments

Comments
 (0)