@nativescript-community/ui-mapbox 6.2.15 → 6.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,102 @@
1
+ /**
2
+ * Android Implementation
3
+ *
4
+ * @todo FIXME: The gcFix() implementation currently assumes only one map visible at a time.
5
+ */
1
6
  import { ImageSource } from '@nativescript/core';
2
7
  import { AddExtrusionOptions, AddGeoJsonClusteredOptions, AddPolygonOptions, AddPolylineOptions, AddSourceOptions, AnimateCameraOptions, DeleteOfflineRegionOptions, DownloadOfflineRegionOptions, Feature, LatLng, LayerCommon, ListOfflineRegionsOptions, MapStyle, MapboxApi, MapboxCommon, MapboxMarker, MapboxViewBase, OfflineRegion, QueryRenderedFeaturesOptions, QuerySourceFeaturesOptions, SetCenterOptions, SetTiltOptions, SetViewportOptions, SetZoomLevelOptions, ShowOptions, TrackUserOptions, UpdateSourceOptions, UserLocation, UserLocationCameraMode, Viewport } from './common';
3
8
  export * from './common';
4
9
  export declare function setLogLevel(level: 'none' | 'info' | 'debug' | 'error' | 'fault' | 'verbose'): void;
10
+ /**
11
+ * A map view created in XML.
12
+ *
13
+ * This is the class that is created when the Mapbox XML tag
14
+ * is encountered while parsing a view.
15
+ *
16
+ * Angular components need to register the Mapbox tag as follows:
17
+ *
18
+ * import { registerElement } from "nativescript-angular/element-registry";
19
+ * registerElement( "Mapbox", () => require("nativescript-mapbox").MapboxView);
20
+ *
21
+ * The registerElement call is what binds the XML tag to the class that creates it.
22
+ *
23
+ * @see MapboxViewBase
24
+ */
5
25
  export declare class MapboxView extends MapboxViewBase {
6
26
  private nativeMapView;
7
27
  private settings;
8
28
  private initialized;
9
29
  constructor();
30
+ /**
31
+ * programmatically include settings
32
+ */
10
33
  setConfig(settings: any): void;
11
34
  getNativeMapView(): any;
35
+ /**
36
+ * Return the Mapbox() API Shim instance
37
+ *
38
+ * This returns a reference to the Mapbox API shim class instance.
39
+ * See class Mapbox below.
40
+ *
41
+ * @see Mapbox
42
+ */
12
43
  getMapboxApi(): any;
44
+ /**
45
+ * Creates the native view.
46
+ *
47
+ * This method is supposed to create the native view. NativeScript caches
48
+ * and re-uses views to save on memory and increase performance. Unfortunately,
49
+ * the inner details of exactly how this is done is challenging to tease apart.
50
+ *
51
+ * The problem is that in order to create the Mapbox view we need the access token from
52
+ * the XML, but in the case of a pure NativeScript app with property binding
53
+ * (see the demo), the properties don't seem to be available until the page is loaded.
54
+ *
55
+ * As a workaround, I wait until the page is loaded to configure the map. See initNativeView.
56
+ *
57
+ * It seems to me there should be a better way.
58
+ *
59
+ * @link https://docs.nativescript.org/core-concepts/properties#views-lifecycle-and-recycling
60
+ *
61
+ * @todo check this.
62
+ */
13
63
  createNativeView(): Object;
14
64
  onLoaded(): void;
15
65
  initNativeView(): void;
66
+ /**
67
+ * when the view is destroyed.
68
+ *
69
+ * This is called by the framework when the view is actually destroyed.
70
+ * NativeScript, by design, tries to cache native views because
71
+ * creating native views is expensive.
72
+ *
73
+ * @link https://docs.nativescript.org/plugins/ui-plugin-custom
74
+ */
16
75
  disposeNativeView(): void;
76
+ /**
77
+ * initialize the map
78
+ *
79
+ * This method creates a new mapbox API instance and, through the show() method of the Mapbox API,
80
+ * creates a Mapbox native map view.
81
+ *
82
+ * @see show()
83
+ *
84
+ * @link https://docs.nativescript.org/core-concepts/events
85
+ *
86
+ * @todo FIXME: this.nativeMapView is unused and never actually set to anything.
87
+ */
17
88
  private initMap;
18
89
  }
90
+ /**
91
+ * A NativeScript shim for the Mapbox API.
92
+ *
93
+ * This implements a Typescript shim over the Native Mapbox GL Android API.
94
+ *
95
+ * It is created in one of two ways:
96
+ *
97
+ * - directly via let mapbox = new Mapbox(); mapbox.show( ... )
98
+ * - via the Mapbox XML tag in which case a MapboxView object is created which hosts a reference to this class. (See MapboxView::getMapboxAPI())
99
+ */
19
100
  export declare class Mapbox extends MapboxCommon implements MapboxApi {
20
101
  private _mapboxMapInstance;
21
102
  private _mapboxViewInstance;
@@ -49,11 +130,49 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi {
49
130
  private eventCallbacks;
50
131
  _markerIconDownloadCache: any[];
51
132
  constructor(view: any);
133
+ /**
134
+ * not used
135
+ */
52
136
  setMapboxViewInstance(mapboxViewInstance: any): void;
137
+ /**
138
+ * show the map programmatically.
139
+ *
140
+ * This method is used to programmatically display a map. It is also called
141
+ * by the MapboxView::init() method which initializes the map when the Mapbox
142
+ * XML tags is encountered
143
+ *
144
+ * options may additionally include:
145
+ *
146
+ * - context
147
+ * - parentView
148
+ * - onLocationPermissionGranted
149
+ * - onLocationPermissionDenied
150
+ * - onMapReady
151
+ *
152
+ * @see MapboxView::init()
153
+ *
154
+ * @todo FIXME: the timeout delay before showing the map works around some race condition. The source error needs to be figured out.
155
+ */
53
156
  show(options: ShowOptions): Promise<any>;
157
+ /**
158
+ * hide the map
159
+ */
54
160
  hide(): Promise<void>;
55
161
  unhide(): Promise<void>;
162
+ /**
163
+ * destroy the map programmatically
164
+ *
165
+ * Destroy the map instance.
166
+ */
56
167
  destroy(nativeMap?: any): Promise<void>;
168
+ /**
169
+ * Clear Event Listeners
170
+ *
171
+ * Explicitly clear all registered event listeners. It's not clear to me whether or not this
172
+ * is strictly necessary as I imagine these should all get cleaned up when the map is destroyed
173
+ * but given the complication of NativeScript's garbage collection scheme it seems like a good
174
+ * idea to remove these handlers explicitly.
175
+ */
57
176
  private clearEventListeners;
58
177
  onStart(nativeMap?: any): Promise<void>;
59
178
  onResume(nativeMapViewInstance?: any): Promise<void>;
@@ -61,13 +180,73 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi {
61
180
  onStop(nativeMap?: any): Promise<void>;
62
181
  onLowMemory(nativeMap?: any): Promise<void>;
63
182
  onDestroy(nativeMap?: any): Promise<void>;
183
+ /**
184
+ * event handler shim
185
+ *
186
+ * Initialize our event handler shim so that we can intercept events here.
187
+ *
188
+ * @param { any } settings
189
+ * @param { MapboxView } mapboxView
190
+ */
64
191
  initEventHandlerShim(settings: any, mapboxNativeViewInstance: any): void;
192
+ /**
193
+ * register on click handlers.
194
+ *
195
+ * The native mapbox API does not, apparently, support click handlers
196
+ * on circles, but it does for markers and polylines. WTF?
197
+ *
198
+ * Here we attempt to replicate the mapbox-gl-js behaviour of being
199
+ * able to assign an onClick handler to a layer by it's layer id.
200
+ *
201
+ * @param {string} event - the event to subscribe to. i.e. 'click'.
202
+ * @param {string} id - the id of the layer
203
+ * @param {function} callback - the callback to invoke when the layer is clicked on.
204
+ * @param {object] nativeMapView - reference to the native Map view.
205
+ *
206
+ * @link https://github.com/mapbox/mapbox-android-demo/issues/540
207
+ */
65
208
  onMapEvent(eventName: any, id: any, callback: any, nativeMapView?: any): void;
209
+ /**
210
+ * remove an event handler for a layer
211
+ *
212
+ * This will remove all event handlers (that we manage here) for
213
+ * the given layer id and event.
214
+ */
66
215
  offMapEvent(eventName: any, id: any, nativeMapView?: any): void;
216
+ /**
217
+ * If click events registered and a feature found for the event, then fire listener.
218
+ */
67
219
  private checkForClickEvent;
220
+ /**
221
+ * handles a line click event
222
+ *
223
+ * Given a click on a line overlay, find the id of the underlying line layer
224
+ * an invoke any registered callbacks.
225
+ */
68
226
  private handleLineClickEvent;
69
227
  hasFineLocationPermission(): Promise<boolean>;
70
- requestFineLocationPermission(): Promise<[import("@nativescript-community/perms").Status, boolean]>;
228
+ /**
229
+ * Request fine locaion permission
230
+ *
231
+ * @link https://docs.mapbox.com/android/core/overview/#permissionsmanager
232
+ */
233
+ requestFineLocationPermission(): Promise<import("@nativescript-community/perms").Result>;
234
+ /**
235
+ * set the map style
236
+ *
237
+ * The 7.X version of the SDK uses a builder class for forming
238
+ * URLs.
239
+ *
240
+ * NOTE: The style must be explicitly set using this method in the onMapReady() handler.
241
+ *
242
+ * @param {string | MapStyle } style - a style following the Mapbox style specification or a URL to a style.
243
+ * @param {any} nativeMapViewInstance - native map view (com.mapbox.mapboxsdk.maps.MapView)
244
+ *
245
+ * @see MapboxViewCommonBase:setMapStyle()
246
+ *
247
+ * @link https://docs.mapbox.com/android/api/map-sdk/7.1.2/com/mapbox/mapboxsdk/maps/Style.Builder.html
248
+ * @link https://docs.mapbox.com/android/api/map-sdk/7.1.2/com/mapbox/mapboxsdk/maps/MapboxMap.html#setStyle-java.lang.String-com.mapbox.mapboxsdk.maps.Style.OnStyleLoaded-
249
+ */
71
250
  setMapStyle(style: string | MapStyle, nativeMapViewInstance?: any): Promise<void>;
72
251
  getImage(imageId: string, nativeMap?: any): Promise<ImageSource>;
73
252
  addImage(imageId: string, image: string, nativeMap?: any): Promise<void>;
@@ -77,7 +256,16 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi {
77
256
  iconCache: {
78
257
  [k: string]: com.mapbox.mapboxsdk.annotations.Icon;
79
258
  };
259
+ /**
260
+ *
261
+ * @deprecated
262
+ * @link https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation
263
+ */
80
264
  _addMarkers(markers: MapboxMarker[], nativeMap?: any): void;
265
+ /**
266
+ *
267
+ * @deprecated
268
+ */
81
269
  _removeMarkers(ids?: any, nativeMap?: any): void;
82
270
  setCenter(options: SetCenterOptions, nativeMap?: any): Promise<void>;
83
271
  getCenter(nativeMap?: any): Promise<LatLng>;
@@ -85,14 +273,38 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi {
85
273
  getZoomLevel(nativeMap?: any): Promise<number>;
86
274
  setTilt(options: SetTiltOptions, nativeMap?: any): Promise<void>;
87
275
  getTilt(nativeMap?: any): Promise<number>;
276
+ /**
277
+ * get users current location
278
+ *
279
+ * @link https://docs.mapbox.com/android/api/map-sdk/9.0.0/com/mapbox/mapboxsdk/location/LocationComponent.html#getLastKnownLocation--
280
+ */
88
281
  getUserLocation(): Promise<UserLocation>;
282
+ /**
283
+ * @link https://www.mapbox.com/android-docs/api/mapbox-java/libjava-geojson/3.4.1/com/mapbox/geojson/Feature.html
284
+ */
89
285
  queryRenderedFeatures(options: QueryRenderedFeaturesOptions): Promise<Feature[]>;
90
286
  querySourceFeatures(sourceId: string, options?: QuerySourceFeaturesOptions): Promise<Feature[]>;
287
+ /**
288
+ *
289
+ * @deprecated
290
+ */
91
291
  addPolygon(options: AddPolygonOptions, nativeMap?: any): Promise<void>;
292
+ /**
293
+ *
294
+ * @deprecated
295
+ */
92
296
  addPolyline(options: AddPolylineOptions, nativeMap?: any): Promise<void>;
93
297
  removePolygons(ids?: any[], nativeMap?: any): Promise<void>;
94
298
  removePolylines(ids?: any[], nativeMap?: any): Promise<void>;
95
299
  animateCamera(options: AnimateCameraOptions, nativeMap?: any): Promise<void>;
300
+ /**
301
+ * set an on map click listener.
302
+ *
303
+ * The new Mapbox Native SDK allows for multiple listeners on an event and follows the standard
304
+ * pattern of returning 'true' when a handler has handled the event and others shouldn't.
305
+ *
306
+ * Not returning a boolean from the listener function will cause a crash.
307
+ */
96
308
  setOnMapClickListener(listener: (data: LatLng) => boolean, nativeMap?: MapboxView): Promise<void>;
97
309
  setOnMapLongClickListener(listener: (data: LatLng) => boolean, nativeMap?: any): Promise<void>;
98
310
  setOnMoveBeginListener(listener: (data?: LatLng) => void, nativeMap?: any): Promise<void>;
@@ -109,26 +321,145 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi {
109
321
  deleteOfflineRegion(options: DeleteOfflineRegionOptions): Promise<void>;
110
322
  _getOfflineManager(): any;
111
323
  addExtrusion(options: AddExtrusionOptions, nativeMap?: any): Promise<void>;
324
+ /**
325
+ * update a geojson source
326
+ *
327
+ */
112
328
  updateSource(id: string, options: UpdateSourceOptions, nativeMap?: any): Promise<void>;
329
+ /**
330
+ * add a geojson or vector source
331
+ *
332
+ * Add a source that can then be referenced in the style specification
333
+ * passed to addLayer().
334
+ *
335
+ * @link https://docs.mapbox.com/mapbox-gl-js/api/#map#addsource
336
+ */
113
337
  addSource(id: string, options: AddSourceOptions, nativeMap?: any): Promise<void>;
338
+ /**
339
+ * remove source by id
340
+ */
114
341
  removeSource(id: string, nativeMap?: any): Promise<void>;
342
+ /**
343
+ * a rough analogue to the mapbox-gl-js addLayer() method
344
+ *
345
+ * It would be nice if this {N} API matched the mapbox-gl-js API which
346
+ * would make it much easier to share mapping applications between the web
347
+ * and {N} apps.
348
+ *
349
+ * This method accepts a Mapbox-GL-JS style specification JSON object with some
350
+ * limitations:
351
+ *
352
+ * - the source: must be a GeoJSON object, vector source definition, or an id of a source added via addSource()
353
+ * - only a subset of paint properties are available.
354
+ *
355
+ * @param {object} style - a style following the Mapbox style specification.
356
+ * @param {any} nativeMapView - native map view (com.mapbox.mapboxsdk.maps.MapView)
357
+ *
358
+ * @link https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers
359
+ */
115
360
  addLayer(style: any, belowLayerId?: string, nativeMap?: any): Promise<void>;
361
+ /**
362
+ * remove layer by ID
363
+ *
364
+ * Removes a layer given a layer id
365
+ *
366
+ * @param {string} id
367
+ */
116
368
  removeLayer(id: string, nativeMap?: any): Promise<void>;
369
+ /**
370
+ * @deprecated
371
+ * Add a point to a line
372
+ *
373
+ * This method appends a point to a line and is useful for drawing a users track.
374
+ *
375
+ * @param {id} id - id of line to add a point to.
376
+ * @param {array} lnglat - [lng,lat] to append to the line.
377
+ *
378
+ * @link https://github.com/mapbox/mapbox-gl-native/issues/13983
379
+ * @link https://docs.mapbox.com/android/api/mapbox-java/libjava-geojson/3.0.1/com/mapbox/geojson/Feature.html#Feature--
380
+ * @link https://docs.oracle.com/javase/8/docs/api/java/util/List.html
381
+ */
117
382
  addLinePoint(id: string, lnglat: any, sourceId?: string, nativeMapView?: any): Promise<void>;
118
383
  addGeoJsonClustered(options: AddGeoJsonClusteredOptions, nativeMap?: any): Promise<void>;
384
+ /**
385
+ * constantly center the map on the users location.
386
+ */
119
387
  trackUser(options: TrackUserOptions, nativeMap?: any): Promise<void>;
120
388
  private static getAndroidColor;
121
389
  _getMapStyle(input: any): any;
390
+ /**
391
+ * Mapbox Map Options
392
+ *
393
+ * @link https://github.com/mapbox/mapbox-gl-native/wiki/Android-6.x-to-7.x-migration-guide
394
+ * @link https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
395
+ * @link https://docs.mapbox.com/android/api/map-sdk/7.1.2/com/mapbox/mapboxsdk/maps/MapboxMapOptions.html
396
+ */
122
397
  _getMapboxMapOptions(settings: any): com.mapbox.mapboxsdk.maps.MapboxMapOptions;
398
+ /**
399
+ * convert string to camera mode constant.
400
+ *
401
+ * @link https://docs.mapbox.com/android/api/map-sdk/8.1.0/com/mapbox/mapboxsdk/location/modes/CameraMode.html
402
+ */
123
403
  _stringToCameraMode(mode: UserLocationCameraMode): any;
404
+ /**
405
+ * convert string to render mode
406
+ */
124
407
  _stringToRenderMode(mode: any): any;
125
408
  _convertCameraMode(mode: any): UserLocationCameraMode;
126
409
  _fineLocationPermissionGranted(): boolean;
127
410
  _getRegionName(offlineRegion: com.mapbox.mapboxsdk.offline.OfflineRegion): string;
128
411
  _getRegionMetadata(offlineRegion: com.mapbox.mapboxsdk.offline.OfflineRegion): any;
412
+ /**
413
+ * show a user location marker
414
+ *
415
+ * This method must not be called before location permissions have been granted.
416
+ *
417
+ * Supported options are:
418
+ *
419
+ * - foregroundTintColor
420
+ * - foregroundStaleTintColor
421
+ * - backgroundTintColor
422
+ * - bearingTintColor
423
+ * - elevation
424
+ * - accuracyColor
425
+ * - accuracyAlpha
426
+ * - useDefaultLocationEngine
427
+ * - renderMode
428
+ * - cameraMode
429
+ * - clickListener
430
+ * - cameraTrackingChangeListener
431
+ *
432
+ * @param {object} options
433
+ *
434
+ * @link https://github.com/mapbox/mapbox-android-demo/blob/master/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/location/LocationComponentOptionsActivity.java
435
+ * @link https://developer.android.com/reference/android/graphics/Color
436
+ *
437
+ * @todo at least with simulated data, the location is only updated once hence adding support for forceLocation method.
438
+ */
129
439
  showUserLocationMarker(options: any, nativeMap?: any): Promise<void>;
440
+ /**
441
+ * hide (destroy) the user location marker
442
+ *
443
+ * This method destroys the user location marker.
444
+ */
130
445
  hideUserLocationMarker(nativeMap?: any): Promise<void>;
446
+ /**
447
+ * Change the mode of the user location marker
448
+ *
449
+ * Used to change the camera tracking and render modes of an existing
450
+ * marker.
451
+ *
452
+ * The marker must be configured using showUserLocationMarker before this method
453
+ * can called.
454
+ */
131
455
  changeUserLocationMarkerMode(renderModeString: any, cameraModeString: UserLocationCameraMode, nativeMap?: any): Promise<void>;
456
+ /**
457
+ * force updating of user location
458
+ *
459
+ * This method forces the user location marker, if displayed, to move to a new location
460
+ *
461
+ * @todo figure out why the user location marker is not updating.
462
+ */
132
463
  forceUserLocationUpdate(location: any, nativeMap?: any): Promise<void>;
133
464
  getLayer(name: string, nativeMap?: any): Promise<LayerCommon>;
134
465
  getLayers(nativeMap?: any): Promise<LayerCommon[]>;