Skip to content

Commit abc918d

Browse files
committed
chore: working on mapViewDidUpdateUserLocation
1 parent 19a0b67 commit abc918d

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

src/mapbox.ios.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ function _getTrackingMode(input: UserLocationCameraMode): MGLUserTrackingMode {
112112
return MGLUserTrackingMode.None;
113113
}
114114

115+
function _getLocation (loc: MGLUserLocation) {
116+
if (loc === null) {
117+
return null;
118+
} else {
119+
return {
120+
location: {
121+
lat: loc.coordinate.latitude,
122+
lng: loc.coordinate.longitude,
123+
},
124+
speed: loc.location ? loc.location.speed : 0,
125+
} as UserLocation;
126+
}
127+
}
128+
115129
// ------------------------------------------------------------------------
116130

117131
/**
@@ -1249,13 +1263,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
12491263
if (loc === null) {
12501264
reject('Location not available');
12511265
} else {
1252-
resolve({
1253-
location: {
1254-
lat: loc.coordinate.latitude,
1255-
lng: loc.coordinate.longitude,
1256-
},
1257-
speed: loc.location ? loc.location.speed : 0,
1258-
});
1266+
resolve(_getLocation(loc));
12591267
}
12601268
} catch (ex) {
12611269
if (Trace.isEnabled()) {
@@ -3148,7 +3156,8 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
31483156

31493157
private mapboxApi: any;
31503158

3151-
private userLocationClickListener: any;
3159+
private userLocationClickListener: (annotation: MGLAnnotation)=>void;
3160+
private userLocationChangedListener: (location: UserLocation)=>void;
31523161
private userLocationRenderMode: any;
31533162
private userLocationAnnotationView: CustomUserLocationAnnotationView;
31543163

@@ -3186,6 +3195,13 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
31863195
setUserLocationClickListener(callback) {
31873196
this.userLocationClickListener = callback;
31883197
}
3198+
/**
3199+
* set the user location click listener callback
3200+
*/
3201+
3202+
setUserLocationChangedistener(callback) {
3203+
this.userLocationChangedListener = callback;
3204+
}
31893205

31903206
// -----------------------
31913207

@@ -3446,6 +3462,16 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
34463462

34473463
return null;
34483464
}
3465+
3466+
mapViewDidUpdateUserLocation(mapView: MGLMapView, userLocation: MGLUserLocation) {
3467+
if (Trace.isEnabled()) {
3468+
CLog(CLogTypes.info, 'MGLMapViewDelegateImpl::mapViewDidUpdateUserLocation() top');
3469+
}
3470+
if (this.userLocationChangedListener) {
3471+
this.userLocationChangedListener(_getLocation(userLocation));
3472+
}
3473+
3474+
}
34493475
} // end of MGLMapViewDelegateImpl
34503476

34513477
// --------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)