Skip to content

Commit fa640cd

Browse files
committed
feat(ios): setOnCameraIdleListener && setOnCameraMoveListener
1 parent f719759 commit fa640cd

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

src/mapbox.ios.ts

+48-7
Original file line numberDiff line numberDiff line change
@@ -1803,16 +1803,26 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
18031803
return Promise.reject("'setOnFlingListener' is not supported on iOS");
18041804
}
18051805

1806-
setOnCameraMoveListener(listener: () => void, nativeMap?: any): Promise<void> {
1807-
return Promise.reject("'setOnCameraMoveListener' not currently supported on iOS");
1806+
async setOnCameraMoveListener(listener: () => void, nativeMap?: any): Promise<void> {
1807+
const theMap: MGLMapView = nativeMap || this._mapboxViewInstance;
1808+
if (theMap) {
1809+
(theMap.delegate as MGLMapViewDelegateImpl).setCameraChangedListener(listener);
1810+
} else {
1811+
return Promise.reject('No map has been loaded');
1812+
}
18081813
}
18091814

18101815
setOnCameraMoveCancelListener(listener: () => void, nativeMap?: any): Promise<void> {
18111816
return Promise.reject("'setOnCameraMoveCancelListener' not currently supported on iOS");
18121817
}
18131818

1814-
setOnCameraIdleListener(listener: () => void, nativeMap?: any): Promise<void> {
1815-
return Promise.reject("'setOnCameraIdleListener' not currently supported on iOS");
1819+
async setOnCameraIdleListener(listener: () => void, nativeMap?: any): Promise<void> {
1820+
const theMap: MGLMapView = nativeMap || this._mapboxViewInstance;
1821+
if (theMap) {
1822+
(theMap.delegate as MGLMapViewDelegateImpl).setCameraIdledListener(listener);
1823+
} else {
1824+
return Promise.reject('No map has been loaded');
1825+
}
18161826
}
18171827

18181828
getViewport(nativeMap?): Promise<Viewport> {
@@ -2517,10 +2527,11 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
25172527

25182528
private userLocationClickListener: (annotation: MGLAnnotation) => void;
25192529
private userLocationChangedListener: (location: UserLocation) => void;
2530+
private cameraChangedListener: () => void;
2531+
private cameraIdledListener: () => void;
25202532
private userLocationRenderMode: any;
25212533
private userLocationAnnotationView: CustomUserLocationAnnotationView;
25222534

2523-
25242535
/**
25252536
* initialize with the mapReady callback
25262537
*/
@@ -2533,7 +2544,6 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
25332544
return this;
25342545
}
25352546

2536-
25372547
/**
25382548
* set a reference to the mapboxAPI instance
25392549
*/
@@ -2562,6 +2572,20 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
25622572
this.userLocationAnnotationView.changeUserLocationRenderMode(userLocationRenderMode);
25632573
}
25642574

2575+
/**
2576+
* set the camera changd listener callback
2577+
*/
2578+
setCameraChangedListener(callback) {
2579+
this.cameraChangedListener = callback;
2580+
}
2581+
2582+
/**
2583+
* set the camera idled listener callback
2584+
*/
2585+
setCameraIdledListener(callback) {
2586+
this.cameraIdledListener = callback;
2587+
}
2588+
25652589
/**
25662590
* set style loaded callback.
25672591
*
@@ -2778,9 +2802,26 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
27782802
return null;
27792803
}
27802804

2805+
mapViewRegionIsChanging() {
2806+
if (Trace.isEnabled()) {
2807+
CLog(CLogTypes.info, 'MGLMapViewDelegateImpl::mapViewRegionIsChanging()');
2808+
}
2809+
if (this.cameraChangedListener) {
2810+
this.cameraChangedListener();
2811+
}
2812+
}
2813+
mapViewRegionDidChangeAnimated(animated) {
2814+
if (Trace.isEnabled()) {
2815+
CLog(CLogTypes.info, 'MGLMapViewDelegateImpl::mapViewRegionDidChangeAnimated()');
2816+
}
2817+
if (this.cameraIdledListener) {
2818+
this.cameraIdledListener();
2819+
}
2820+
}
2821+
27812822
mapViewDidUpdateUserLocation(mapView: MGLMapView, userLocation: MGLUserLocation) {
27822823
if (Trace.isEnabled()) {
2783-
CLog(CLogTypes.info, 'MGLMapViewDelegateImpl::mapViewDidUpdateUserLocation() top');
2824+
CLog(CLogTypes.info, 'MGLMapViewDelegateImpl::mapViewDidUpdateUserLocation()');
27842825
}
27852826
if (this.userLocationChangedListener) {
27862827
this.userLocationChangedListener(_getLocation(userLocation));

0 commit comments

Comments
 (0)