Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ui-mapbox/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ export interface MapboxApi {

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

getUserLocationCameraMode(nativeMap?: any): UserLocationCameraMode;

addSource(id: string, options: AddSourceOptions, nativeMapView?: any): Promise<any>;

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

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

getUserLocationCameraMode(nativeMap?: any): UserLocationCameraMode;

showUserLocationMarker(options): void;

hideUserLocationMarker(options): void;
Expand Down Expand Up @@ -1005,6 +1009,9 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox
trackUser(options: TrackUserOptions): Promise<any> {
return this.mapbox.trackUser(options, this.getNativeMapView());
}
getUserLocationCameraMode(): UserLocationCameraMode {
return this.mapbox.getUserLocationCameraMode(this.getNativeMapView());
}
addSource(id: string, options: AddSourceOptions): Promise<any> {
return this.mapbox.addSource(id, options, this.getNativeMapView());
}
Expand Down
42 changes: 42 additions & 0 deletions src/ui-mapbox/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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());
}
}
23 changes: 23 additions & 0 deletions src/ui-mapbox/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Expand Down