Skip to content

Commit 1965f4b

Browse files
committed
feat: mapClick event available the N way
1 parent d669d7c commit 1965f4b

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

src/mapbox.android.ts

+11-14
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class MapboxView extends MapboxViewBase {
259259
}
260260

261261
if (!this.nativeMapView && ((this.config && this.config.accessToken) || (this.settings && this.settings.accessToken))) {
262-
this.mapbox = new Mapbox();
262+
this.mapbox = new Mapbox(this);
263263
// the NativeScript contentview class extends from Observable to provide the notify method
264264
// which is the glue that joins this code with whatever callbacks are set in the Mapbox XML
265265
// tag describing the map.
@@ -429,8 +429,8 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
429429

430430
_markerIconDownloadCache = [];
431431

432-
constructor() {
433-
super();
432+
constructor(view) {
433+
super(view);
434434

435435
if (Trace.isEnabled()) {
436436
CLog(CLogTypes.info, 'constructor(): building new Mapbox object.');
@@ -448,11 +448,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
448448
*/
449449
setMapboxViewInstance(mapboxViewInstance: any): void {}
450450

451-
/**
452-
* not used
453-
*/
454-
setMapboxMapInstance(mapboxMapInstance: any): void {}
455-
456451
/**
457452
* show the map programmatically.
458453
*
@@ -981,13 +976,15 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
981976
CLog(CLogTypes.info, 'Mapbox:checkForClickEvent(): got click event with point:', JSON.stringify(point));
982977
}
983978

984-
this.eventCallbacks['click'].forEach((eventListener) => {
985-
this.queryRenderedFeatures({ point, layers: [eventListener.id] }).then((response) => {
986-
if (response.length > 0) {
987-
eventListener.callback(response);
988-
}
979+
this.eventCallbacks['click'] &&
980+
this.eventCallbacks['click'].forEach((eventListener) => {
981+
this.queryRenderedFeatures({ point, layers: [eventListener.id] }).then((response) => {
982+
if (response.length > 0) {
983+
eventListener.callback(response);
984+
}
985+
});
989986
});
990-
});
987+
this.view && this.view.notify({ eventName: 'mapClick', object: this.view, point });
991988

992989
return false;
993990
}

src/mapbox.common.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,6 @@ export interface MapboxCommonApi {
550550
export interface MapboxApi {
551551
setMapboxViewInstance(mapboxNativeViewInstance: any): void;
552552

553-
setMapboxMapInstance(mapboxNativeMapInstance: any): void;
554-
555553
initEventHandlerShim(settings: any, mapboxNativeViewInstance: any): void;
556554

557555
onMapEvent(eventName, id, callback, nativeMapView?): void;
@@ -690,6 +688,7 @@ export interface MapboxApi {
690688
// ------------------------------------------------------------
691689

692690
export abstract class MapboxCommon implements MapboxCommonApi {
691+
constructor(public view?: MapboxViewCommonBase) {}
693692
public static defaults = {
694693
style: MapStyle.STREETS.toString(),
695694
mapStyle: MapStyle.STREETS.toString(),

src/mapbox.ios.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ export class MapboxView extends MapboxViewBase {
308308
}
309309

310310
if (!this.nativeMapView) {
311-
this.mapbox = new Mapbox();
311+
this.mapbox = new Mapbox(this);
312312

313313
if (Trace.isEnabled()) {
314314
CLog(CLogTypes.info, 'initMap(): after new Mapbox()');
@@ -690,22 +690,12 @@ export class CustomUserLocationAnnotationView extends MGLUserLocationAnnotationV
690690
export class Mapbox extends MapboxCommon implements MapboxApi {
691691
// reference to the native mapbox API
692692

693-
private _mapboxMapInstance: any;
694693
private _mapboxViewInstance: any;
695694

696695
private eventCallbacks: { [key: string]: any[] } = {};
697696

698697
private userLocationRenderMode: string;
699698

700-
/**
701-
* set the mapboxMapInstance
702-
*
703-
* @see MapboxView::initMap()
704-
*/
705-
setMapboxMapInstance(mapboxMapInstance: any) {
706-
this._mapboxMapInstance = mapboxMapInstance;
707-
}
708-
709699
/**
710700
* set the mapboxViewInstance
711701
*
@@ -773,6 +763,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
773763
console.error('click error ', eventListener.id, err);
774764
});
775765
});
766+
this.view && this.view.notify({ eventName: 'mapClick', object: this.view, point });
776767

777768
return false;
778769
}

0 commit comments

Comments
 (0)