Skip to content

Commit 8d5a0e2

Browse files
committed
fix(ios): prevent crash when ‘click’ mapEvent not set
1 parent 5c3f70d commit 8d5a0e2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/mapbox.ios.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function _getLocation(loc: MGLUserLocation) {
131131
*/
132132
export class MapboxView extends MapboxViewBase {
133133
private nativeMapView: MGLMapView = null;
134-
private delegate: MGLMapViewDelegate = null;
134+
private delegate: MGLMapViewDelegateImpl = null;
135135

136136
private settings: any = null;
137137

@@ -328,6 +328,11 @@ export class MapboxView extends MapboxViewBase {
328328
ios: this.nativeMapView,
329329
});
330330
});
331+
// this.delegate.setStyleLoadedCallback((map, style)=>{
332+
// this.delegate.setStyleLoadedCallback(null);
333+
334+
// });
335+
331336

332337
_setMapboxMapOptions(this.nativeMapView, this.settings);
333338
_markers = [];
@@ -734,8 +739,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
734739
if (Trace.isEnabled()) {
735740
CLog(CLogTypes.info, 'Mapbox:checkForClickEvent(): got click event with point:', point);
736741
}
737-
738-
this.eventCallbacks['click'].forEach((eventListener) => {
742+
this.eventCallbacks['click'] && this.eventCallbacks['click'].forEach((eventListener) => {
739743
this.queryRenderedFeatures({ point, layers: [eventListener.id] }, nativeMap).then((response) => {
740744
if (response.length > 0) {
741745
eventListener.callback(response);
@@ -2608,7 +2612,7 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
26082612
}
26092613

26102614
private mapLoadedCallback: (mapView: MGLMapView) => void;
2611-
private styleLoadedCallback: (mapView: MGLMapView) => void;
2615+
private styleLoadedCallback: (mapView: MGLMapView, style:MGLStyle) => void;
26122616

26132617
private mapboxApi: any;
26142618

@@ -2683,7 +2687,7 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
26832687
*
26842688
* @see Mapbox:setMapStyle()
26852689
*/
2686-
setStyleLoadedCallback(callback) {
2690+
setStyleLoadedCallback(callback: (mapView: MGLMapView, style:MGLStyle) => void) {
26872691
this.styleLoadedCallback = callback;
26882692
}
26892693

@@ -2719,13 +2723,13 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
27192723
*
27202724
* @link https://mapbox.github.io/mapbox-gl-native/macos/0.3.0/Protocols/MGLMapViewDelegate.html#/c:objc(pl)MGLMapViewDelegate(im)mapView:didFinishLoadingStyle:
27212725
*/
2722-
mapViewDidFinishLoadingStyle(mapView: MGLMapView): void {
2726+
mapViewDidFinishLoadingStyle(mapView: MGLMapView, style:MGLStyle): void {
27232727
if (Trace.isEnabled()) {
27242728
CLog(CLogTypes.info, 'MGLMapViewDelegateImpl:mapViewDidFinishLoadingStyle(): callback called.');
27252729
}
27262730

27272731
if (this.styleLoadedCallback !== undefined) {
2728-
this.styleLoadedCallback(mapView);
2732+
this.styleLoadedCallback(mapView, style);
27292733

27302734
// to avoid multiple calls. This is only invoked from setMapStyle().
27312735

0 commit comments

Comments
 (0)