Skip to content

Commit 4dccf56

Browse files
committed
feat: implement #44
1 parent 9299af1 commit 4dccf56

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

src/ui-mapbox/common.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,13 @@ export interface GeoJSONSource extends Source {
350350

351351
// ------------------------------------------------------------
352352

353-
export type UserLocationCameraMode = 'NONE' | 'NONE_COMPASS' | 'NONE_GPS' | 'TRACKING' | 'TRACK_COMPASS' | 'TRACKING_GPS' | 'TRACK_GPS_NORTH';
353+
export type UserLocationCameraMode = 'NONE' | 'NONE_COMPASS' | 'NONE_GPS' | 'TRACKING' | 'TRACKING_COMPASS' | 'TRACKING_GPS' | 'TRACKING_GPS_NORTH';
354354

355355
// ------------------------------------------------------------
356356

357357
export interface TrackUserOptions {
358-
mode: UserLocationCameraMode;
358+
cameraMode: UserLocationCameraMode;
359+
renderMode?: string;
359360
/**
360361
* iOS only, as Android is always animated. Default true (because of Android).
361362
*/
@@ -718,6 +719,7 @@ export abstract class MapboxCommon implements MapboxCommonApi {
718719
},
719720
zoomLevel: 0, // 0 (a big part of the world) to 20 (street level)
720721
showUserLocation: false, // true requires adding `NSLocationWhenInUseUsageDescription` or `NSLocationAlwaysUsageDescription` in the .plist
722+
locationComponentOptions: {},
721723
hideLogo: false, // required for the 'starter' plan
722724
hideAttribution: true,
723725
hideCompass: false,
@@ -1093,6 +1095,12 @@ export const showUserLocationProperty = new Property<MapboxViewCommonBase, boole
10931095
});
10941096
showUserLocationProperty.register(MapboxViewCommonBase);
10951097

1098+
export const locationComponentOptionsProperty = new Property<MapboxViewCommonBase, object>({
1099+
name: 'locationComponentOptions',
1100+
defaultValue: MapboxCommon.defaults.locationComponentOptions
1101+
});
1102+
locationComponentOptionsProperty.register(MapboxViewCommonBase);
1103+
10961104
export const hideLogoProperty = new Property<MapboxViewCommonBase, boolean>({
10971105
name: 'hideLogo',
10981106
defaultValue: MapboxCommon.defaults.hideLogo,
@@ -1210,6 +1218,10 @@ export abstract class MapboxViewBase extends MapboxViewCommonBase {
12101218
this.config.showUserLocation = value;
12111219
}
12121220

1221+
[locationComponentOptionsProperty.setNative](value: boolean) {
1222+
this.config.locationComponentOptions = value || {};
1223+
}
1224+
12131225
[hideLogoProperty.setNative](value: boolean) {
12141226
this.config.hideLogo = value;
12151227
}

src/ui-mapbox/index.android.ts

+35-19
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ export class MapboxView extends MapboxViewBase {
377377
}
378378

379379
[telemetryProperty.setNative](value: boolean) {
380-
com.mapbox.mapboxsdk.Mapbox.getTelemetry().setUserTelemetryRequestState(value);
380+
if (com.mapbox.mapboxsdk.Mapbox.getTelemetry()) {
381+
com.mapbox.mapboxsdk.Mapbox.getTelemetry().setUserTelemetryRequestState(value);
382+
}
381383
}
382384
}
383385

@@ -584,7 +586,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
584586
if (settings.showUserLocation) {
585587
this.requestFineLocationPermission()
586588
.then(() => {
587-
this.showUserLocationMarker({});
589+
this.showUserLocationMarker(settings.locationComponentOptions);
588590

589591
// if we have a callback defined, call it.
590592

@@ -2793,9 +2795,13 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
27932795

27942796
this.requestFineLocationPermission()
27952797
.then(() => {
2796-
this.showUserLocationMarker({
2797-
useDefaultLocationEngine: true
2798-
});
2798+
if (this._locationComponent) {
2799+
this.changeUserLocationMarkerMode(options.renderMode || 'COMPASS', options.cameraMode || 'TRACKING');
2800+
} else {
2801+
this.showUserLocationMarker({
2802+
useDefaultLocationEngine: true
2803+
});
2804+
}
27992805
})
28002806
.catch((err) => {
28012807
console.error('Location permission denied. error:', err);
@@ -2914,13 +2920,13 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
29142920
case 'TRACKING':
29152921
return modeRef.TRACKING;
29162922

2917-
case 'TRACK_COMPASS':
2923+
case 'TRACKING_COMPASS':
29182924
return modeRef.TRACKING_COMPASS;
29192925

29202926
case 'TRACKING_GPS':
29212927
return modeRef.TRACKING_GPS;
29222928

2923-
case 'TRACK_GPS_NORTH':
2929+
case 'TRACKING_GPS_NORTH':
29242930
return modeRef.TRACKING_GPS_NORTH;
29252931
}
29262932
}
@@ -3177,26 +3183,36 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
31773183
return;
31783184
}
31793185

3180-
if (Trace.isEnabled()) {
3181-
CLog(CLogTypes.info, 'changeUserLocationMarkerMode(): current render mode is:', this._locationComponent.getRenderMode());
3182-
}
3186+
if (cameraModeString) {
3187+
const cameraMode = this._stringToCameraMode(cameraModeString);
3188+
if (Trace.isEnabled()) {
3189+
CLog(CLogTypes.info, `Mapbox::changeUserLocationMarkerMode(): current camera mode is: ${this._locationComponent.getCameraMode()}`);
3190+
CLog(CLogTypes.info, `Mapbox::changeUserLocationMarkerMode(): changing camera mode to: ${cameraMode}`);
3191+
}
31833192

3184-
if (Trace.isEnabled()) {
3185-
CLog(CLogTypes.info, "Mapbox::changeUserLocationMarkerMode(): changing renderMode to '" + renderModeString + "' cameraMode '" + cameraModeString + "'");
3193+
this._locationComponent.setCameraMode(cameraMode);
3194+
3195+
if (Trace.isEnabled()) {
3196+
CLog(CLogTypes.info, `Mapbox::changeUserLocationMarkerMode(): new camera mode is: ${this._locationComponent.getCameraMode()}`);
3197+
}
31863198
}
31873199

3188-
const cameraMode = this._stringToCameraMode(cameraModeString);
3189-
const renderMode = this._stringToRenderMode(renderModeString);
3200+
if (renderModeString) {
3201+
const renderMode = this._stringToRenderMode(renderModeString);
3202+
if (Trace.isEnabled()) {
3203+
CLog(CLogTypes.info, `Mapbox::changeUserLocationMarkerMode(): current render mode is: ${this._locationComponent.getRenderMode()}`);
3204+
CLog(CLogTypes.info, `Mapbox::changeUserLocationMarkerMode(): changing render mode to: '${renderMode}'`);
3205+
}
31903206

3191-
this._locationComponent.setCameraMode(cameraMode);
3192-
this._locationComponent.setRenderMode(renderMode);
3207+
this._locationComponent.setRenderMode(renderMode);
31933208

3194-
if (Trace.isEnabled()) {
3195-
CLog(CLogTypes.info, 'changeUserLocationMarkerMode(): new render mode is:', this._locationComponent.getRenderMode());
3209+
if (Trace.isEnabled()) {
3210+
CLog(CLogTypes.info, 'changeUserLocationMarkerMode(): new render mode is:', this._locationComponent.getRenderMode());
3211+
}
31963212
}
31973213
} catch (ex) {
31983214
if (Trace.isEnabled()) {
3199-
CLog(CLogTypes.info, 'Error in mapbox.showUserLocationMarker: ' + ex);
3215+
CLog(CLogTypes.info, 'Error in mapbox.changeUserLocationMarkerMode: ' + ex);
32003216
}
32013217
reject(ex);
32023218
}

src/ui-mapbox/index.ios.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1794,14 +1794,14 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
17941794
case 'TRACKING':
17951795
return MGLUserTrackingMode.Follow;
17961796

1797-
case 'TRACK_COMPASS':
1797+
case 'TRACKING_COMPASS':
17981798
return MGLUserTrackingMode.FollowWithHeading;
17991799

18001800
case 'TRACKING_GPS':
18011801
// a reasonable approximation.
18021802
return MGLUserTrackingMode.Follow;
18031803

1804-
case 'TRACK_GPS_NORTH':
1804+
case 'TRACKING_GPS_NORTH':
18051805
return MGLUserTrackingMode.FollowWithCourse;
18061806
}
18071807
}
@@ -3080,7 +3080,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
30803080
return;
30813081
}
30823082

3083-
theMap.setUserTrackingModeAnimated(_getTrackingMode(options.mode), options.animated !== false);
3083+
theMap.setUserTrackingModeAnimated(_getTrackingMode(options.cameraMode), options.animated !== false);
30843084

30853085
resolve();
30863086
} catch (ex) {

0 commit comments

Comments
 (0)