@nativescript-community/ui-mapbox 6.2.30 → 7.0.0-alpha.14.3191a7b
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.
- package/CHANGELOG.md +4 -0
- package/common.d.ts +38 -24
- package/common.js +35 -26
- package/expression/expression-parser.android.d.ts +2 -2
- package/expression/expression-parser.android.js +4 -3
- package/index.android.d.ts +59 -59
- package/index.android.js +1389 -1222
- package/index.d.ts +36 -5
- package/index.ios.d.ts +6 -4
- package/index.ios.js +8 -9
- package/layers/layer-factory.android.d.ts +7 -5
- package/layers/layer-factory.android.js +71 -41
- package/layers/layer-factory.d.ts +2 -1
- package/layers/layer-factory.ios.d.ts +1 -1
- package/layers/layer-factory.ios.js +9 -9
- package/layers/parser/property-parser.android.d.ts +3 -1
- package/layers/parser/property-parser.android.js +25 -24
- package/layers/parser/property-parser.ios.js +1 -1
- package/markers/Marker.android.d.ts +35 -0
- package/markers/Marker.android.js +128 -0
- package/markers/MarkerManager.android.d.ts +28 -0
- package/markers/MarkerManager.android.js +154 -0
- package/package.json +6 -5
- package/platforms/android/include.gradle +31 -27
- package/platforms/android/ui_mapbox.aar +0 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/typings/geojson.android.d.ts +689 -0
- package/typings/index.android.d.ts +46 -0
- package/typings/mapbox.android.d.ts +39968 -12560
package/index.android.js
CHANGED
|
@@ -4,35 +4,50 @@
|
|
|
4
4
|
* @todo FIXME: The gcFix() implementation currently assumes only one map visible at a time.
|
|
5
5
|
*/
|
|
6
6
|
import { request } from '@nativescript-community/perms';
|
|
7
|
-
import {
|
|
7
|
+
import { Application, Color, File, Http, ImageSource, Trace, Utils, knownFolders, path } from '@nativescript/core';
|
|
8
8
|
import { ExpressionParser } from './expression/expression-parser';
|
|
9
9
|
import { Layer, LayerFactory } from './layers/layer-factory';
|
|
10
10
|
import { CLog, CLogTypes, ControlPosition, MapStyle, MapboxCommon, MapboxViewBase, telemetryProperty } from './common';
|
|
11
|
+
import { MarkerManager } from './markers/MarkerManager.android';
|
|
12
|
+
import { AndroidMarker } from './markers/Marker.android';
|
|
11
13
|
// Export the enums for devs not using TS
|
|
12
14
|
export * from './common';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
console.error(error);
|
|
15
|
+
function bitmapFromDrawableResource(resourceId) {
|
|
16
|
+
// 1. Get the Drawable
|
|
17
|
+
const context = Utils.android.getApplicationContext();
|
|
18
|
+
const identifier = context.getResources().getIdentifier(resourceId, 'drawable', Utils.android.getApplication().getPackageName());
|
|
19
|
+
// if (identifier !== 0) {
|
|
20
|
+
if (0 < identifier) {
|
|
21
|
+
const drawable = androidx.core.content.ContextCompat.getDrawable(context, identifier);
|
|
22
|
+
// 2. Create a Bitmap with the same dimensions
|
|
23
|
+
const width = drawable.getIntrinsicWidth();
|
|
24
|
+
const height = drawable.getIntrinsicHeight();
|
|
25
|
+
const bitmap = android.graphics.Bitmap.createBitmap(width, height, android.graphics.Bitmap.Config.ARGB_8888);
|
|
26
|
+
// 3. Create a Canvas to draw onto the Bitmap
|
|
27
|
+
const canvas = new android.graphics.Canvas(bitmap);
|
|
28
|
+
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
|
29
|
+
drawable.draw(canvas);
|
|
30
|
+
return bitmap;
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
|
-
|
|
33
|
+
// let libraryLoadedOverloaded = false;
|
|
34
|
+
// function overrideLibraryLoader() {
|
|
35
|
+
// try {
|
|
36
|
+
// if (true && !libraryLoadedOverloaded) {
|
|
37
|
+
// @NativeClass
|
|
38
|
+
// class LibraryLoader extends com.mapbox.maps.LibraryLoader {
|
|
39
|
+
// load(name) {
|
|
40
|
+
// java.lang.System.loadLibrary(name);
|
|
41
|
+
// }
|
|
42
|
+
// }
|
|
43
|
+
// com.mapbox.maps.LibraryLoader.setLibraryLoader(new LibraryLoader());
|
|
44
|
+
// libraryLoadedOverloaded = true;
|
|
45
|
+
// }
|
|
46
|
+
// } catch (error) {
|
|
47
|
+
// console.error(error);
|
|
48
|
+
// }
|
|
49
|
+
// }
|
|
50
|
+
// overrideLibraryLoader();
|
|
36
51
|
function _getLocation(loc) {
|
|
37
52
|
if (loc === null) {
|
|
38
53
|
return null;
|
|
@@ -48,27 +63,28 @@ function _getLocation(loc) {
|
|
|
48
63
|
}
|
|
49
64
|
}
|
|
50
65
|
export function setLogLevel(level) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
//TODO: Logger
|
|
67
|
+
// const Logger = com.mapbox.maps.log.Logger;
|
|
68
|
+
// let loggingLevel: number;
|
|
69
|
+
// switch (level) {
|
|
70
|
+
// case 'none':
|
|
71
|
+
// loggingLevel = Logger.NONE;
|
|
72
|
+
// break;
|
|
73
|
+
// case 'info':
|
|
74
|
+
// loggingLevel = Logger.INFO;
|
|
75
|
+
// break;
|
|
76
|
+
// case 'debug':
|
|
77
|
+
// loggingLevel = Logger.DEBUG;
|
|
78
|
+
// break;
|
|
79
|
+
// case 'verbose':
|
|
80
|
+
// loggingLevel = Logger.VERBOSE;
|
|
81
|
+
// break;
|
|
82
|
+
// case 'fault':
|
|
83
|
+
// case 'error':
|
|
84
|
+
// loggingLevel = Logger.ERROR;
|
|
85
|
+
// break;
|
|
86
|
+
// }
|
|
87
|
+
// Logger.setVerbosity(loggingLevel);
|
|
72
88
|
}
|
|
73
89
|
/**
|
|
74
90
|
* A map view created in XML.
|
|
@@ -169,8 +185,8 @@ export class MapboxView extends MapboxViewBase {
|
|
|
169
185
|
}
|
|
170
186
|
this.nativeView.owner = this;
|
|
171
187
|
// Application.android.on(AndroidApplication.activityStartedEvent, this.onStart, this);
|
|
172
|
-
Application.android.on(
|
|
173
|
-
Application.android.on(
|
|
188
|
+
// Application.android.on(Application.android.activityPausedEvent, this.onPause, this);
|
|
189
|
+
// Application.android.on(Application.android.activityResumedEvent, this.onResume, this);
|
|
174
190
|
// Application.android.on(AndroidApplication.activityStartedEvent, this.onStop, this);
|
|
175
191
|
super.initNativeView();
|
|
176
192
|
}
|
|
@@ -188,13 +204,8 @@ export class MapboxView extends MapboxViewBase {
|
|
|
188
204
|
CLog(CLogTypes.info, 'disposeNativeView(): top');
|
|
189
205
|
}
|
|
190
206
|
this.nativeView.owner = null;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
Application.android.off(AndroidApplication.activityResumedEvent, this.onResume, this);
|
|
194
|
-
// Application.android.off(AndroidApplication.activityStartedEvent, this.onStop, this);
|
|
195
|
-
if (this.mapbox) {
|
|
196
|
-
this.mapbox.destroy();
|
|
197
|
-
}
|
|
207
|
+
this.mapbox?.destroy();
|
|
208
|
+
this.mapbox = null;
|
|
198
209
|
super.disposeNativeView();
|
|
199
210
|
}
|
|
200
211
|
/**
|
|
@@ -209,10 +220,13 @@ export class MapboxView extends MapboxViewBase {
|
|
|
209
220
|
*
|
|
210
221
|
* @todo FIXME: this.nativeMapView is unused and never actually set to anything.
|
|
211
222
|
*/
|
|
212
|
-
initMap() {
|
|
223
|
+
async initMap() {
|
|
213
224
|
if (Trace.isEnabled()) {
|
|
214
225
|
CLog(CLogTypes.info, "MapboxView:initMap(): top - accessToken is '" + this.config.accessToken + "'", this.config);
|
|
215
226
|
}
|
|
227
|
+
if (!this.config.accessToken) {
|
|
228
|
+
throw new Error('missing accessToken');
|
|
229
|
+
}
|
|
216
230
|
if (!this.nativeMapView && ((this.config && this.config.accessToken) || (this.settings && this.settings.accessToken))) {
|
|
217
231
|
this.mapbox = new Mapbox(this);
|
|
218
232
|
// the NativeScript contentview class extends from Observable to provide the notify method
|
|
@@ -237,14 +251,10 @@ export class MapboxView extends MapboxViewBase {
|
|
|
237
251
|
android: this.nativeMapView
|
|
238
252
|
});
|
|
239
253
|
},
|
|
240
|
-
onMapReady: (map) => {
|
|
254
|
+
onMapReady: (map, view) => {
|
|
255
|
+
this.nativeMapView = view;
|
|
241
256
|
if (this.telemetry === false) {
|
|
242
|
-
|
|
243
|
-
com.mapbox.mapboxsdk.Mapbox.getTelemetry().setUserTelemetryRequestState(false);
|
|
244
|
-
}
|
|
245
|
-
catch (err) {
|
|
246
|
-
console.error('telemtry', err);
|
|
247
|
-
}
|
|
257
|
+
com.nativescript.mapbox.Telemetry.setUserTelemetryRequestState(this.nativeMapView, false);
|
|
248
258
|
}
|
|
249
259
|
if (Trace.isEnabled()) {
|
|
250
260
|
CLog(CLogTypes.info, 'initMap(): onMapReady event - calling notify with the MapboxViewBase.mapReadyEvent');
|
|
@@ -268,7 +278,7 @@ export class MapboxView extends MapboxViewBase {
|
|
|
268
278
|
},
|
|
269
279
|
onScrollEvent: (event) => {
|
|
270
280
|
if (Trace.isEnabled()) {
|
|
271
|
-
CLog(CLogTypes.info, 'initMap(): onScrollEvent event');
|
|
281
|
+
CLog(CLogTypes.info, 'initMap(): onScrollEvent event:' + JSON.stringify(event));
|
|
272
282
|
}
|
|
273
283
|
this.notify({
|
|
274
284
|
eventName: MapboxViewBase.scrollEvent,
|
|
@@ -316,16 +326,14 @@ export class MapboxView extends MapboxViewBase {
|
|
|
316
326
|
if (Trace.isEnabled()) {
|
|
317
327
|
CLog(CLogTypes.info, 'initMap(): before show.');
|
|
318
328
|
}
|
|
319
|
-
this.mapbox.show(this.settings);
|
|
329
|
+
await this.mapbox.show(this.settings);
|
|
320
330
|
if (Trace.isEnabled()) {
|
|
321
331
|
CLog(CLogTypes.info, 'initMap(): bottom.');
|
|
322
332
|
}
|
|
323
333
|
}
|
|
324
334
|
}
|
|
325
335
|
[telemetryProperty.setNative](value) {
|
|
326
|
-
|
|
327
|
-
com.mapbox.mapboxsdk.Mapbox.getTelemetry().setUserTelemetryRequestState(value);
|
|
328
|
-
}
|
|
336
|
+
com.nativescript.mapbox.Telemetry.setUserTelemetryRequestState(this.nativeMapView, false);
|
|
329
337
|
}
|
|
330
338
|
}
|
|
331
339
|
/**
|
|
@@ -341,19 +349,23 @@ export class MapboxView extends MapboxViewBase {
|
|
|
341
349
|
export class Mapbox extends MapboxCommon {
|
|
342
350
|
constructor(view) {
|
|
343
351
|
super(view);
|
|
352
|
+
// private _locationComponent: com.mapbox.maps.plugin.locationcomponent.LocationComponent;
|
|
344
353
|
this._accessToken = '';
|
|
345
|
-
|
|
354
|
+
// private circleManager: any = null;
|
|
346
355
|
this.lineManager = null;
|
|
347
|
-
this.
|
|
356
|
+
this.polygonManager = null;
|
|
357
|
+
this.customMarker = null;
|
|
358
|
+
// private iconFactory;
|
|
348
359
|
this._markers = [];
|
|
349
|
-
this._polylines =
|
|
350
|
-
this._polygons =
|
|
360
|
+
this._polylines = {};
|
|
361
|
+
this._polygons = {};
|
|
351
362
|
// list of polylines
|
|
352
363
|
this.lines = [];
|
|
353
364
|
// registered callbacks.
|
|
354
365
|
this.eventCallbacks = {};
|
|
355
|
-
this._markerIconDownloadCache =
|
|
366
|
+
this._markerIconDownloadCache = {};
|
|
356
367
|
this.iconCache = {};
|
|
368
|
+
this._plugins = {};
|
|
357
369
|
if (Trace.isEnabled()) {
|
|
358
370
|
CLog(CLogTypes.info, 'constructor(): building new Mapbox object.');
|
|
359
371
|
}
|
|
@@ -385,148 +397,178 @@ export class Mapbox extends MapboxCommon {
|
|
|
385
397
|
*
|
|
386
398
|
* @todo FIXME: the timeout delay before showing the map works around some race condition. The source error needs to be figured out.
|
|
387
399
|
*/
|
|
388
|
-
show(options) {
|
|
400
|
+
async show(options) {
|
|
389
401
|
return new Promise((resolve, reject) => {
|
|
390
402
|
try {
|
|
391
403
|
const settings = Mapbox.merge(options, Mapbox.defaults);
|
|
392
|
-
const showIt = () => {
|
|
404
|
+
// const showIt = () => {
|
|
405
|
+
if (Trace.isEnabled()) {
|
|
406
|
+
CLog(CLogTypes.info, 'show(): ' + JSON.stringify(settings.center));
|
|
407
|
+
}
|
|
408
|
+
// if no accessToken was set the app may crash.
|
|
409
|
+
//
|
|
410
|
+
// FIXME: Even if using a local server add some string.
|
|
411
|
+
if (settings.accessToken === undefined) {
|
|
412
|
+
throw new Error('mapbox_accesstoken_missing');
|
|
413
|
+
}
|
|
414
|
+
// if already added, make sure it's removed first
|
|
415
|
+
if (this._mapboxViewInstance) {
|
|
393
416
|
if (Trace.isEnabled()) {
|
|
394
|
-
CLog(CLogTypes.info, 'show()');
|
|
395
|
-
}
|
|
396
|
-
// if no accessToken was set the app may crash.
|
|
397
|
-
//
|
|
398
|
-
// FIXME: Even if using a local server add some string.
|
|
399
|
-
if (settings.accessToken === undefined) {
|
|
400
|
-
reject('mapbox_accesstoken_missing');
|
|
401
|
-
return;
|
|
417
|
+
CLog(CLogTypes.info, 'show(): view already created. Removing it.');
|
|
402
418
|
}
|
|
403
|
-
|
|
404
|
-
if (
|
|
419
|
+
const viewGroup = this._mapboxViewInstance.getParent();
|
|
420
|
+
if (viewGroup !== null) {
|
|
405
421
|
if (Trace.isEnabled()) {
|
|
406
|
-
CLog(CLogTypes.info, 'show(): view already created. Removing
|
|
407
|
-
}
|
|
408
|
-
const viewGroup = this._mapboxViewInstance.getParent();
|
|
409
|
-
if (viewGroup !== null) {
|
|
410
|
-
if (Trace.isEnabled()) {
|
|
411
|
-
CLog(CLogTypes.info, 'show(): view already created. Removing _mapboxViewInstance child of view parent.');
|
|
412
|
-
}
|
|
413
|
-
viewGroup.removeView(this._mapboxViewInstance);
|
|
422
|
+
CLog(CLogTypes.info, 'show(): view already created. Removing _mapboxViewInstance child of view parent.');
|
|
414
423
|
}
|
|
424
|
+
viewGroup.removeView(this._mapboxViewInstance);
|
|
415
425
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
426
|
+
}
|
|
427
|
+
this._accessToken = settings.accessToken;
|
|
428
|
+
let context = Utils.android.getApplicationContext();
|
|
429
|
+
if (settings.context) {
|
|
430
|
+
context = settings.context;
|
|
431
|
+
}
|
|
432
|
+
const mapboxMapOptions = this._getMapboxMapOptions(context, settings);
|
|
433
|
+
// unlike the Mapbox Android Native samples, we are not laying the map out
|
|
434
|
+
// using the Android XML layout features. Instead, we are creating the map
|
|
435
|
+
// programmatically.
|
|
436
|
+
this._mapboxViewInstance = new com.mapbox.maps.MapView(context, mapboxMapOptions);
|
|
437
|
+
// define some listeners to inform in case the map does not
|
|
438
|
+
// load.
|
|
439
|
+
this._mapboxMapInstance = this._mapboxViewInstance.getMapboxMap();
|
|
440
|
+
const gesturePlugin = this._getGesturesPlugin();
|
|
441
|
+
gesturePlugin.setPitchEnabled(!settings.disableTilt);
|
|
442
|
+
gesturePlugin.setScrollEnabled(!settings.disableScroll);
|
|
443
|
+
gesturePlugin.setRotateEnabled(!settings.disableRotation);
|
|
444
|
+
gesturePlugin.setPinchToZoomDecelerationEnabled(!settings.disableZoom);
|
|
445
|
+
const attributionPlugin = this._getPlugin('MAPBOX_ATTRIBUTION_PLUGIN_ID');
|
|
446
|
+
attributionPlugin.setEnabled(!settings.hideAttribution);
|
|
447
|
+
attributionPlugin.setPosition(Mapbox.mapPositionToGravity(settings.attributionPosition));
|
|
448
|
+
const compassPlugin = this._getPlugin('MAPBOX_COMPASS_PLUGIN_ID');
|
|
449
|
+
compassPlugin.setEnabled(!settings.hideCompass);
|
|
450
|
+
compassPlugin.setPosition(Mapbox.mapPositionToGravity(settings.compassPosition));
|
|
451
|
+
const logoPlugin = this._getPlugin('MAPBOX_LOGO_PLUGIN_ID');
|
|
452
|
+
logoPlugin.setEnabled(!settings.hideLogo);
|
|
453
|
+
logoPlugin.setPosition(Mapbox.mapPositionToGravity(settings.logoPosition));
|
|
454
|
+
if (Trace.isEnabled()) {
|
|
455
|
+
CLog(CLogTypes.info, 'show(): onMapReady() with instance:', this._mapboxMapInstance);
|
|
456
|
+
}
|
|
457
|
+
// Android SDK 7.0.0 and on requires that the style be set separately after the map
|
|
458
|
+
// is initialized. We do not consider the map ready until the style has successfully
|
|
459
|
+
// loaded.
|
|
460
|
+
const mapStyle = this._getMapStyle(settings.style);
|
|
461
|
+
if (Trace.isEnabled()) {
|
|
462
|
+
CLog(CLogTypes.info, 'show(): loadStyleUri:', mapStyle);
|
|
463
|
+
}
|
|
464
|
+
this._mapboxMapInstance.loadStyle(mapStyle, new com.mapbox.maps.Style.OnStyleLoaded({
|
|
465
|
+
onStyleLoaded: (param0) => {
|
|
466
|
+
try {
|
|
450
467
|
if (Trace.isEnabled()) {
|
|
451
|
-
CLog(CLogTypes.info, 'show():
|
|
468
|
+
CLog(CLogTypes.info, 'show(): style loaded.');
|
|
452
469
|
}
|
|
453
|
-
//
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
470
|
+
// initialize the event handlers now that we have a constructed view.
|
|
471
|
+
this.markerManager = new MarkerManager(this._mapboxMapInstance, this._mapboxViewInstance, (marker) => {
|
|
472
|
+
const cachedMarker = this._getClickedMarkerDetails(marker);
|
|
473
|
+
if (cachedMarker?.onTap) {
|
|
474
|
+
const result = cachedMarker.onTap(cachedMarker);
|
|
475
|
+
return !!result;
|
|
459
476
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
this.
|
|
463
|
-
if (
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
this.showUserLocationMarker(settings.locationComponentOptions);
|
|
467
|
-
// if we have a callback defined, call it.
|
|
468
|
-
if (settings.onLocationPermissionGranted) {
|
|
469
|
-
settings.onLocationPermissionGranted(this._mapboxMapInstance);
|
|
470
|
-
}
|
|
471
|
-
})
|
|
472
|
-
.catch((err) => {
|
|
473
|
-
if (settings.onLocationPermissionDenied) {
|
|
474
|
-
settings.onLocationPermissionDenied(this._mapboxMapInstance);
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
+
return false;
|
|
478
|
+
}, (marker) => {
|
|
479
|
+
const cachedMarker = this._getClickedMarkerDetails(marker);
|
|
480
|
+
if (cachedMarker?.onCalloutTap) {
|
|
481
|
+
const result = cachedMarker.onCalloutTap(cachedMarker);
|
|
482
|
+
return !!result;
|
|
477
483
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
484
|
+
return false;
|
|
485
|
+
});
|
|
486
|
+
this._addMarkers(settings.markers, this._mapboxViewInstance);
|
|
487
|
+
this.initEventHandlerShim(settings, this._mapboxViewInstance);
|
|
488
|
+
const annotationPlugin = this._getPlugin('MAPBOX_ANNOTATION_PLUGIN_ID');
|
|
489
|
+
this.lineManager = annotationPlugin.createAnnotationManager(com.mapbox.maps.plugin.annotation.AnnotationType.PolylineAnnotation, new com.mapbox.maps.plugin.annotation.AnnotationConfig());
|
|
490
|
+
this.onAnnotationClickListener = new com.mapbox.maps.plugin.annotation.generated.OnPolylineAnnotationClickListener({
|
|
491
|
+
onAnnotationClick: (line) => {
|
|
492
|
+
if (Trace.isEnabled()) {
|
|
493
|
+
CLog(CLogTypes.info, 'Mapbox:setMapStyle(): click on line:', line);
|
|
494
|
+
}
|
|
495
|
+
this.handleLineClickEvent(line);
|
|
496
|
+
return true;
|
|
481
497
|
}
|
|
482
|
-
resolve({
|
|
483
|
-
android: this._mapboxViewInstance
|
|
484
|
-
});
|
|
485
498
|
});
|
|
499
|
+
this.lineManager.addClickListener(this.onAnnotationClickListener);
|
|
500
|
+
if (settings.showUserLocation) {
|
|
501
|
+
this.requestFineLocationPermission()
|
|
502
|
+
.then(() => {
|
|
503
|
+
this.showUserLocationMarker(settings.locationComponentOptions);
|
|
504
|
+
// if we have a callback defined, call it.
|
|
505
|
+
if (settings.onLocationPermissionGranted) {
|
|
506
|
+
settings.onLocationPermissionGranted(this._mapboxMapInstance);
|
|
507
|
+
}
|
|
508
|
+
})
|
|
509
|
+
.catch((err) => {
|
|
510
|
+
if (settings.onLocationPermissionDenied) {
|
|
511
|
+
settings.onLocationPermissionDenied(this._mapboxMapInstance);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
// if we have an onMapReady callback fire it.
|
|
516
|
+
if (settings.onMapReady) {
|
|
517
|
+
settings.onMapReady(this._mapboxMapInstance, this._mapboxViewInstance);
|
|
518
|
+
}
|
|
519
|
+
resolve({ android: this._mapboxMapInstance, ios: null });
|
|
486
520
|
}
|
|
487
|
-
|
|
488
|
-
|
|
521
|
+
catch (ex) {
|
|
522
|
+
if (Trace.isEnabled()) {
|
|
523
|
+
CLog(CLogTypes.error, 'Error in mapbox.show.loadStyle: ' + ex);
|
|
524
|
+
}
|
|
525
|
+
console.error(ex, ex.stack);
|
|
526
|
+
reject(ex);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}));
|
|
530
|
+
if (Trace.isEnabled()) {
|
|
531
|
+
CLog(CLogTypes.info, 'show(): after getMapAsync()');
|
|
532
|
+
}
|
|
533
|
+
// we either have been given a view to add the map to or we
|
|
534
|
+
// add it to the top making it full screen.
|
|
535
|
+
if (settings.parentView) {
|
|
489
536
|
if (Trace.isEnabled()) {
|
|
490
|
-
CLog(CLogTypes.info, 'show():
|
|
537
|
+
CLog(CLogTypes.info, 'show(): adding map to passed in view');
|
|
491
538
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
settings.parentView.addView(this._mapboxViewInstance);
|
|
539
|
+
settings.parentView.addView(this._mapboxViewInstance);
|
|
540
|
+
}
|
|
541
|
+
else if (settings.container) {
|
|
542
|
+
if (Trace.isEnabled()) {
|
|
543
|
+
CLog(CLogTypes.info, 'show(): adding map to passed in container');
|
|
499
544
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
// Application.android.currentContext has been removed.
|
|
505
|
-
context = Application.android.foregroundActivity;
|
|
506
|
-
if (!context) {
|
|
507
|
-
context = Application.android.startActivity;
|
|
508
|
-
}
|
|
509
|
-
const mapViewLayout = new android.widget.FrameLayout(context);
|
|
510
|
-
if (Trace.isEnabled()) {
|
|
511
|
-
CLog(CLogTypes.info, 'show(): before adding mapboxViewInstance to FrameLayout');
|
|
512
|
-
}
|
|
513
|
-
mapViewLayout.addView(this._mapboxViewInstance);
|
|
514
|
-
if (Trace.isEnabled()) {
|
|
515
|
-
CLog(CLogTypes.info, 'show(): before adding FrameLayout to container');
|
|
516
|
-
}
|
|
517
|
-
settings.container.addChild(mapViewLayout);
|
|
545
|
+
// Application.android.currentContext has been removed.
|
|
546
|
+
context = Application.android.foregroundActivity;
|
|
547
|
+
if (!context) {
|
|
548
|
+
context = Application.android.startActivity;
|
|
518
549
|
}
|
|
550
|
+
const mapViewLayout = new android.widget.FrameLayout(context);
|
|
519
551
|
if (Trace.isEnabled()) {
|
|
520
|
-
CLog(CLogTypes.info, 'show():
|
|
552
|
+
CLog(CLogTypes.info, 'show(): before adding mapboxViewInstance to FrameLayout');
|
|
521
553
|
}
|
|
522
|
-
|
|
554
|
+
mapViewLayout.addView(this._mapboxViewInstance);
|
|
555
|
+
if (Trace.isEnabled()) {
|
|
556
|
+
CLog(CLogTypes.info, 'show(): before adding FrameLayout to container');
|
|
557
|
+
}
|
|
558
|
+
settings.container.addChild(mapViewLayout);
|
|
559
|
+
}
|
|
560
|
+
if (Trace.isEnabled()) {
|
|
561
|
+
CLog(CLogTypes.info, 'show(): showIt() bottom');
|
|
562
|
+
}
|
|
563
|
+
// };
|
|
523
564
|
// FIXME: There is some initialization error. A short delay works around this.
|
|
524
|
-
setTimeout(showIt, settings.delay ? settings.delay : 200);
|
|
565
|
+
// setTimeout(showIt, settings.delay ? settings.delay : 200);
|
|
525
566
|
}
|
|
526
567
|
catch (ex) {
|
|
527
568
|
if (Trace.isEnabled()) {
|
|
528
|
-
CLog(CLogTypes.
|
|
569
|
+
CLog(CLogTypes.error, 'Error in mapbox.show: ' + ex);
|
|
529
570
|
}
|
|
571
|
+
console.error(ex, ex.stack);
|
|
530
572
|
reject(ex);
|
|
531
573
|
}
|
|
532
574
|
});
|
|
@@ -534,97 +576,125 @@ export class Mapbox extends MapboxCommon {
|
|
|
534
576
|
/**
|
|
535
577
|
* hide the map
|
|
536
578
|
*/
|
|
537
|
-
hide() {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
viewGroup.setVisibility(android.view.View.INVISIBLE);
|
|
544
|
-
}
|
|
579
|
+
async hide() {
|
|
580
|
+
try {
|
|
581
|
+
if (this._mapboxViewInstance) {
|
|
582
|
+
const viewGroup = this._mapboxViewInstance.getParent();
|
|
583
|
+
if (viewGroup !== null) {
|
|
584
|
+
viewGroup.setVisibility(android.view.View.INVISIBLE);
|
|
545
585
|
}
|
|
546
|
-
resolve();
|
|
547
586
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
reject(ex);
|
|
587
|
+
}
|
|
588
|
+
catch (ex) {
|
|
589
|
+
if (Trace.isEnabled()) {
|
|
590
|
+
CLog(CLogTypes.info, 'Error in mapbox.hide: ' + ex);
|
|
553
591
|
}
|
|
554
|
-
|
|
592
|
+
throw ex;
|
|
593
|
+
}
|
|
555
594
|
}
|
|
556
|
-
unhide() {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
this._mapboxViewInstance.getParent().setVisibility(android.view.View.VISIBLE);
|
|
561
|
-
resolve();
|
|
562
|
-
}
|
|
563
|
-
else {
|
|
564
|
-
reject('No map found');
|
|
565
|
-
}
|
|
595
|
+
async unhide() {
|
|
596
|
+
try {
|
|
597
|
+
if (this._mapboxViewInstance) {
|
|
598
|
+
this._mapboxViewInstance.getParent().setVisibility(android.view.View.VISIBLE);
|
|
566
599
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
CLog(CLogTypes.info, 'Error in mapbox.unhide: ' + ex);
|
|
570
|
-
}
|
|
571
|
-
reject(ex);
|
|
600
|
+
else {
|
|
601
|
+
throw new Error('No map found');
|
|
572
602
|
}
|
|
573
|
-
}
|
|
603
|
+
}
|
|
604
|
+
catch (ex) {
|
|
605
|
+
if (Trace.isEnabled()) {
|
|
606
|
+
CLog(CLogTypes.info, 'Error in mapbox.unhide: ' + ex);
|
|
607
|
+
}
|
|
608
|
+
throw ex;
|
|
609
|
+
}
|
|
574
610
|
}
|
|
575
611
|
/**
|
|
576
612
|
* destroy the map programmatically
|
|
577
613
|
*
|
|
578
614
|
* Destroy the map instance.
|
|
579
615
|
*/
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
616
|
+
clear(nativeMap) {
|
|
617
|
+
this.clearEventListeners();
|
|
618
|
+
this._markerIconDownloadCache = {};
|
|
619
|
+
if (Trace.isEnabled()) {
|
|
620
|
+
CLog(CLogTypes.info, 'destroy(): destroying mapbox view.');
|
|
621
|
+
}
|
|
622
|
+
if (this.lineManager) {
|
|
623
|
+
this.lineManager.onDestroy();
|
|
624
|
+
this.lineManager = null;
|
|
625
|
+
}
|
|
626
|
+
if (this.polygonManager) {
|
|
627
|
+
this.polygonManager.onDestroy();
|
|
628
|
+
this.polygonManager = null;
|
|
629
|
+
}
|
|
630
|
+
if (this.markerManager) {
|
|
631
|
+
this.markerManager.destroy();
|
|
632
|
+
this.markerManager = null;
|
|
633
|
+
}
|
|
634
|
+
// if (this.circleManager) {
|
|
635
|
+
// this.circleManager.onDestroy();
|
|
636
|
+
// this.circleManager = null;
|
|
637
|
+
// }
|
|
638
|
+
// if (this.symbolManager) {
|
|
639
|
+
// this.symbolManager.onDestroy();
|
|
640
|
+
// this.symbolManager = null;
|
|
641
|
+
// }
|
|
642
|
+
// if we have a location marker we need to disable it before destroying the map
|
|
643
|
+
//
|
|
644
|
+
// This is here to prevent a crash. The user code should disable/re-enable the
|
|
645
|
+
// location marker.
|
|
646
|
+
// if (this._locationComponent) {
|
|
647
|
+
// if (Trace.isEnabled()) {
|
|
648
|
+
// CLog(CLogTypes.info, 'destroy(): Location marker not disabled before destroy() called.');
|
|
649
|
+
// }
|
|
650
|
+
const locationPlugin = this._getPlugin('MAPBOX_LOCATION_COMPONENT_PLUGIN_ID');
|
|
651
|
+
locationPlugin.setEnabled(false);
|
|
652
|
+
// }
|
|
653
|
+
if (this._mapboxViewInstance) {
|
|
654
|
+
const viewGroup = this._mapboxViewInstance.getParent();
|
|
655
|
+
if (viewGroup !== null) {
|
|
604
656
|
if (Trace.isEnabled()) {
|
|
605
|
-
CLog(CLogTypes.info, 'destroy():
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
657
|
+
CLog(CLogTypes.info, 'destroy(): removing _mapboxViewInstance view.');
|
|
658
|
+
}
|
|
659
|
+
viewGroup.removeView(this._mapboxViewInstance);
|
|
660
|
+
}
|
|
661
|
+
// this._mapboxViewInstance.onPause();
|
|
662
|
+
this._mapboxViewInstance.onStop();
|
|
663
|
+
this._mapboxViewInstance.destroyDrawingCache();
|
|
664
|
+
// let the API know that we're programmatically destroying the map.
|
|
665
|
+
this._mapboxViewInstance.onDestroy();
|
|
666
|
+
this._mapboxViewInstance = null;
|
|
667
|
+
this._mapboxMapInstance = null;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
async destroy(nativeMap) {
|
|
671
|
+
this.clear();
|
|
672
|
+
}
|
|
673
|
+
// private enableUserLocationPlugin() {
|
|
674
|
+
// if (!this.map) {
|
|
675
|
+
// return;
|
|
676
|
+
// }
|
|
677
|
+
// try {
|
|
678
|
+
// const locationPlugin = this.mapView.getPlugin(com.mapbox.maps.plugin.locationcomponent.LocationComponentPlugin.class);
|
|
679
|
+
// locationPlugin.updateSettings((settings: any) => {
|
|
680
|
+
// settings.enabled = this._showUserLocation;
|
|
681
|
+
// if (this._showUserLocation) {
|
|
682
|
+
// settings.puckBearingEnabled = true;
|
|
683
|
+
// settings.locationPuck = com.mapbox.maps.plugin.LocationPuck2D.builder()
|
|
684
|
+
// .bearingImage(
|
|
685
|
+
// com.mapbox.maps.plugin.locationcomponent.ImageHolder.fromDrawable(
|
|
686
|
+
// this._context // you may need context
|
|
687
|
+
// /* your drawable resource id */
|
|
688
|
+
// )
|
|
689
|
+
// )
|
|
690
|
+
// .build();
|
|
691
|
+
// }
|
|
692
|
+
// return settings;
|
|
693
|
+
// });
|
|
694
|
+
// } catch (e) {
|
|
695
|
+
// console.log('Error enabling user location plugin:', e);
|
|
696
|
+
// }
|
|
697
|
+
// }
|
|
628
698
|
/**
|
|
629
699
|
* Clear Event Listeners
|
|
630
700
|
*
|
|
@@ -634,70 +704,80 @@ export class Mapbox extends MapboxCommon {
|
|
|
634
704
|
* idea to remove these handlers explicitly.
|
|
635
705
|
*/
|
|
636
706
|
clearEventListeners() {
|
|
637
|
-
if (this.onDidFailLoadingMapListener) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}
|
|
641
|
-
if (this.onDidFinishLoadingMapListener) {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
}
|
|
645
|
-
if (this.onDidFinishLoadingStyleListener) {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
}
|
|
649
|
-
if (this.
|
|
707
|
+
// if (this.onDidFailLoadingMapListener) {
|
|
708
|
+
// this._mapboxViewInstance.removeOnDidFailLoadingMapListener(this.onDidFailLoadingMapListener);
|
|
709
|
+
// this.onDidFailLoadingMapListener = null;
|
|
710
|
+
// }
|
|
711
|
+
// if (this.onDidFinishLoadingMapListener) {
|
|
712
|
+
// this._mapboxViewInstance.removeOnDidFinishLoadingMapListener(this.onDidFinishLoadingMapListener);
|
|
713
|
+
// this.onDidFinishLoadingMapListener = null;
|
|
714
|
+
// }
|
|
715
|
+
// if (this.onDidFinishLoadingStyleListener) {
|
|
716
|
+
// this._mapboxViewInstance.removeOnDidFinishLoadingStyleListener(this.onDidFinishLoadingStyleListener);
|
|
717
|
+
// this.onDidFinishLoadingStyleListener = null;
|
|
718
|
+
// }
|
|
719
|
+
if (this.onIndicatorPositionChangedListener) {
|
|
720
|
+
const locationPlugin = this._getPlugin('MAPBOX_LOCATION_COMPONENT_PLUGIN_ID');
|
|
721
|
+
locationPlugin.removeOnIndicatorPositionChangedListener(this.onIndicatorPositionChangedListener);
|
|
722
|
+
this.onIndicatorPositionChangedListener = null;
|
|
723
|
+
}
|
|
724
|
+
if (this.onAnnotationClickListener && this.lineManager) {
|
|
650
725
|
this.lineManager.removeClickListener(this.onAnnotationClickListener);
|
|
651
726
|
this.onAnnotationClickListener = null;
|
|
652
727
|
}
|
|
653
|
-
if (this.onMarkerClickListener) {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
if (this.onInfoWindowClickListener) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
}
|
|
661
|
-
if (this.onDidFailLoadingMapListener) {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
}
|
|
728
|
+
// if (this.onMarkerClickListener) {
|
|
729
|
+
// this._mapboxMapInstance.setOnMarkerClickListener(null);
|
|
730
|
+
// this.onMarkerClickListener = null;
|
|
731
|
+
// }
|
|
732
|
+
// if (this.onInfoWindowClickListener) {
|
|
733
|
+
// this._mapboxMapInstance.setOnInfoWindowClickListener(null);
|
|
734
|
+
// this.onInfoWindowClickListener = null;
|
|
735
|
+
// }
|
|
736
|
+
// if (this.onDidFailLoadingMapListener) {
|
|
737
|
+
// this._mapboxViewInstance.removeOnDidFailLoadingMapListener(this.onDidFailLoadingMapListener);
|
|
738
|
+
// this.onDidFailLoadingMapListener = null;
|
|
739
|
+
// }
|
|
665
740
|
if (this.onMapClickListener) {
|
|
666
|
-
|
|
741
|
+
com.mapbox.maps.plugin.gestures.GesturesUtils.removeOnMapClickListener(this._mapboxMapInstance, this.onMapClickListener);
|
|
667
742
|
this.onMapClickListener = null;
|
|
668
743
|
}
|
|
669
744
|
if (this.onMapLongClickListener) {
|
|
670
|
-
|
|
745
|
+
com.mapbox.maps.plugin.gestures.GesturesUtils.removeOnMapLongClickListener(this._mapboxMapInstance, this.onMapLongClickListener);
|
|
671
746
|
this.onMapLongClickListener = null;
|
|
672
747
|
}
|
|
673
|
-
if (this.
|
|
674
|
-
|
|
675
|
-
this.
|
|
748
|
+
if (this.onMoveBeginListener) {
|
|
749
|
+
com.mapbox.maps.plugin.gestures.GesturesUtils.removeOnMoveListener(this._mapboxMapInstance, this.onMoveBeginListener);
|
|
750
|
+
this.onMoveBeginListener = null;
|
|
751
|
+
}
|
|
752
|
+
if (this.onMoveEndListener) {
|
|
753
|
+
com.mapbox.maps.plugin.gestures.GesturesUtils.removeOnMoveListener(this._mapboxMapInstance, this.onMoveEndListener);
|
|
754
|
+
this.onMoveEndListener = null;
|
|
676
755
|
}
|
|
677
756
|
if (this.onScrollListener) {
|
|
678
|
-
|
|
757
|
+
com.mapbox.maps.plugin.gestures.GesturesUtils.removeOnMoveListener(this._mapboxMapInstance, this.onScrollListener);
|
|
679
758
|
this.onScrollListener = null;
|
|
680
759
|
}
|
|
681
760
|
if (this.onFlingListener) {
|
|
682
|
-
|
|
761
|
+
com.mapbox.maps.plugin.gestures.GesturesUtils.removeOnFlingListener(this._mapboxMapInstance, this.onFlingListener);
|
|
683
762
|
this.onFlingListener = null;
|
|
684
763
|
}
|
|
764
|
+
// const cameraPlugin = this._getPlugin<com.mapbox.maps.plugin.animation.CameraAnimationsPlugin>("MAPBOX_CAMERA_PLUGIN_ID");
|
|
685
765
|
if (this.onCameraMoveListener) {
|
|
686
|
-
this.
|
|
766
|
+
this.onCameraMoveListener.cancel();
|
|
687
767
|
this.onCameraMoveListener = null;
|
|
688
768
|
}
|
|
689
|
-
if (this.onCameraMoveCancelListener) {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}
|
|
693
|
-
if (this.
|
|
694
|
-
this.
|
|
695
|
-
this.
|
|
696
|
-
}
|
|
697
|
-
if (this.onLocationClickListener) {
|
|
698
|
-
this._locationComponent.removeOnLocationClickListener(this.onLocationClickListener);
|
|
699
|
-
this.onLocationClickListener = null;
|
|
769
|
+
// if (this.onCameraMoveCancelListener) {
|
|
770
|
+
// cameraPlugin.removeOnCameraMoveCancelListener(this.onCameraMoveCancelListener);
|
|
771
|
+
// this.onCameraMoveCancelListener = null;
|
|
772
|
+
// }
|
|
773
|
+
if (this.onMapIdleListener) {
|
|
774
|
+
this.onMapIdleListener.cancel();
|
|
775
|
+
this.onMapIdleListener = null;
|
|
700
776
|
}
|
|
777
|
+
// if (this.onLocationClickListener) {
|
|
778
|
+
// this._locationComponent.removeOnLocationClickListener(this.onLocationClickListener);
|
|
779
|
+
// this.onLocationClickListener = null;
|
|
780
|
+
// }
|
|
701
781
|
}
|
|
702
782
|
// ------------------------------------------------
|
|
703
783
|
// Life Cycle Hooks
|
|
@@ -708,30 +788,30 @@ export class Mapbox extends MapboxCommon {
|
|
|
708
788
|
}
|
|
709
789
|
this._mapboxViewInstance.onStart();
|
|
710
790
|
}
|
|
711
|
-
async onResume(nativeMapViewInstance) {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
}
|
|
717
|
-
async onPause(nativeMapViewInstance) {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
}
|
|
791
|
+
// async onResume(nativeMapViewInstance?: any) {
|
|
792
|
+
// if (Trace.isEnabled()) {
|
|
793
|
+
// CLog(CLogTypes.info, 'onResume()');
|
|
794
|
+
// }
|
|
795
|
+
// this._mapboxViewInstance.onResume();
|
|
796
|
+
// }
|
|
797
|
+
// async onPause(nativeMapViewInstance?: any) {
|
|
798
|
+
// if (Trace.isEnabled()) {
|
|
799
|
+
// CLog(CLogTypes.info, 'onPause()');
|
|
800
|
+
// }
|
|
801
|
+
// this._mapboxViewInstance.onPause();
|
|
802
|
+
// }
|
|
723
803
|
async onStop(nativeMap) {
|
|
724
804
|
if (Trace.isEnabled()) {
|
|
725
805
|
CLog(CLogTypes.info, 'onStop()');
|
|
726
806
|
}
|
|
727
807
|
this._mapboxViewInstance.onStop();
|
|
728
808
|
}
|
|
729
|
-
async onLowMemory(nativeMap) {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
}
|
|
809
|
+
// async onLowMemory(nativeMap?: any) {
|
|
810
|
+
// if (Trace.isEnabled()) {
|
|
811
|
+
// CLog(CLogTypes.info, 'onLowMemory()');
|
|
812
|
+
// }
|
|
813
|
+
// this._mapboxViewInstance.onLowMemory();
|
|
814
|
+
// }
|
|
735
815
|
async onDestroy(nativeMap) {
|
|
736
816
|
if (Trace.isEnabled()) {
|
|
737
817
|
CLog(CLogTypes.info, 'onDestroy()');
|
|
@@ -838,26 +918,21 @@ export class Mapbox extends MapboxCommon {
|
|
|
838
918
|
* an invoke any registered callbacks.
|
|
839
919
|
*/
|
|
840
920
|
handleLineClickEvent(clickOverlay) {
|
|
841
|
-
const
|
|
842
|
-
|
|
843
|
-
CLog(CLogTypes.info, "Mapbox:handleLineClickEvent(): checking lineEntry clickOverlay id '" + entry.clickOverlay + "' against clickOverlay '" + clickOverlay + "'");
|
|
844
|
-
}
|
|
845
|
-
return entry.clickOverlay === clickOverlay;
|
|
846
|
-
});
|
|
847
|
-
if (!lineEntry) {
|
|
921
|
+
const lineEntryId = Object.keys(this._polylines).find((key) => this._polylines[key] === clickOverlay);
|
|
922
|
+
if (!lineEntryId) {
|
|
848
923
|
console.error('Mapbox:handleLineClick(): click on overlay without an underlying line layer');
|
|
849
924
|
return false;
|
|
850
925
|
}
|
|
851
926
|
for (let x = 0; x < this.eventCallbacks['click'].length; x++) {
|
|
852
927
|
const entry = this.eventCallbacks['click'][x];
|
|
853
928
|
if (Trace.isEnabled()) {
|
|
854
|
-
CLog(CLogTypes.info, "Mapbox:handleLineClickEvent(): checking entry id '" + entry.id + "' against lineEnty id '" +
|
|
929
|
+
CLog(CLogTypes.info, "Mapbox:handleLineClickEvent(): checking entry id '" + entry.id + "' against lineEnty id '" + lineEntryId + "'");
|
|
855
930
|
}
|
|
856
|
-
if (entry.id ===
|
|
931
|
+
if (entry.id === lineEntryId) {
|
|
857
932
|
if (Trace.isEnabled()) {
|
|
858
933
|
CLog(CLogTypes.info, "Mapbox:handleLineClickEvent(): calling callback for '" + entry.id + "'");
|
|
859
934
|
}
|
|
860
|
-
return entry.callback(
|
|
935
|
+
return entry.callback({ id: lineEntryId, android: clickOverlay });
|
|
861
936
|
}
|
|
862
937
|
} // end of for loop over events.
|
|
863
938
|
return false;
|
|
@@ -892,12 +967,12 @@ export class Mapbox extends MapboxCommon {
|
|
|
892
967
|
* NOTE: The style must be explicitly set using this method in the onMapReady() handler.
|
|
893
968
|
*
|
|
894
969
|
* @param {string | MapStyle } style - a style following the Mapbox style specification or a URL to a style.
|
|
895
|
-
* @param {any} nativeMapViewInstance - native map view (com.mapbox.
|
|
970
|
+
* @param {any} nativeMapViewInstance - native map view (com.mapbox.maps.MapView)
|
|
896
971
|
*
|
|
897
972
|
* @see MapboxViewCommonBase:setMapStyle()
|
|
898
973
|
*
|
|
899
974
|
* @link https://docs.mapbox.com/android/api/map-sdk/7.1.2/com/mapbox/mapboxsdk/maps/Style.Builder.html
|
|
900
|
-
* @link https://docs.mapbox.com/android/api/map-sdk/7.1.2/com/mapbox/mapboxsdk/maps/MapboxMap.html#setStyle-java.lang.String-com.mapbox.
|
|
975
|
+
* @link https://docs.mapbox.com/android/api/map-sdk/7.1.2/com/mapbox/mapboxsdk/maps/MapboxMap.html#setStyle-java.lang.String-com.mapbox.maps.Style.OnStyleLoaded-
|
|
901
976
|
*/
|
|
902
977
|
setMapStyle(style, nativeMapViewInstance) {
|
|
903
978
|
return new Promise((resolve, reject) => {
|
|
@@ -906,57 +981,14 @@ export class Mapbox extends MapboxCommon {
|
|
|
906
981
|
if (Trace.isEnabled()) {
|
|
907
982
|
CLog(CLogTypes.info, 'setMapStyle(): with style:', style);
|
|
908
983
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
onDidFinishLoadingStyle: () => {
|
|
984
|
+
this._mapboxMapInstance.loadStyle(mapStyle, new com.mapbox.maps.Style.OnStyleLoaded({
|
|
985
|
+
onStyleLoaded: (param0) => {
|
|
912
986
|
if (Trace.isEnabled()) {
|
|
913
987
|
CLog(CLogTypes.info, 'Mapbox:setMapStyle(): style loaded');
|
|
914
988
|
}
|
|
915
|
-
// FIXME: now that the map is initialized and the style is loaded we can
|
|
916
|
-
// create the annotation managers that allow us to (hopefully) reliably
|
|
917
|
-
// receive events on lines
|
|
918
|
-
const nMapbox = this._mapboxMapInstance;
|
|
919
|
-
const nMapView = this._mapboxViewInstance;
|
|
920
|
-
const nStyle = nMapbox.getStyle();
|
|
921
|
-
this.lineManager = new com.mapbox.mapboxsdk.plugins.annotation.LineManager(nMapView, nMapbox, nStyle);
|
|
922
|
-
// this.symbolManager = new com.mapbox.mapboxsdk.plugins.annotation.SymbolManager(nMapView, nMapbox, nStyle);
|
|
923
|
-
// this.symbolManager.addClickListener(
|
|
924
|
-
// new com.mapbox.mapboxsdk.plugins.annotation.OnSymbolClickListener({
|
|
925
|
-
// onAnnotationClick: (marker: com.mapbox.mapboxsdk.plugins.annotation.Symbol) => {
|
|
926
|
-
// const cachedMarker = this._getClickedMarkerDetails(marker);
|
|
927
|
-
// if (cachedMarker && cachedMarker.onTap) {
|
|
928
|
-
// cachedMarker.onTap(cachedMarker);
|
|
929
|
-
// }
|
|
930
|
-
// return false;
|
|
931
|
-
// },
|
|
932
|
-
// })
|
|
933
|
-
// );
|
|
934
|
-
this.onAnnotationClickListener = new com.mapbox.mapboxsdk.plugins.annotation.OnAnnotationClickListener({
|
|
935
|
-
onAnnotationClick: (line) => {
|
|
936
|
-
if (Trace.isEnabled()) {
|
|
937
|
-
CLog(CLogTypes.info, 'Mapbox:setMapStyle(): click on line:', line);
|
|
938
|
-
}
|
|
939
|
-
this.handleLineClickEvent(line);
|
|
940
|
-
return true;
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
this.lineManager.addClickListener(this.onAnnotationClickListener);
|
|
944
989
|
resolve();
|
|
945
990
|
}
|
|
946
|
-
});
|
|
947
|
-
this._mapboxViewInstance.addOnDidFinishLoadingStyleListener(this.onDidFinishLoadingStyleListener);
|
|
948
|
-
// callback if loading the style fails.
|
|
949
|
-
this.onDidFailLoadingMapListener = new com.mapbox.mapboxsdk.maps.MapView.OnDidFailLoadingMapListener({
|
|
950
|
-
onDidFailLoadingMap: (error) => {
|
|
951
|
-
if (Trace.isEnabled()) {
|
|
952
|
-
CLog(CLogTypes.error, 'Mapbox:setMapStyle(): style failed', mapStyle, error);
|
|
953
|
-
}
|
|
954
|
-
reject(error);
|
|
955
|
-
}
|
|
956
|
-
});
|
|
957
|
-
this._mapboxViewInstance.addOnDidFailLoadingMapListener(this.onDidFailLoadingMapListener);
|
|
958
|
-
const builder = new com.mapbox.mapboxsdk.maps.Style.Builder();
|
|
959
|
-
this._mapboxMapInstance.setStyle(builder.fromUri(mapStyle));
|
|
991
|
+
}));
|
|
960
992
|
}
|
|
961
993
|
catch (ex) {
|
|
962
994
|
if (Trace.isEnabled()) {
|
|
@@ -1028,17 +1060,27 @@ export class Mapbox extends MapboxCommon {
|
|
|
1028
1060
|
}
|
|
1029
1061
|
});
|
|
1030
1062
|
}
|
|
1063
|
+
/**
|
|
1064
|
+
*
|
|
1065
|
+
* @deprecated
|
|
1066
|
+
* @link https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation
|
|
1067
|
+
*/
|
|
1031
1068
|
async addMarkers(markers, nativeMap) {
|
|
1032
1069
|
try {
|
|
1033
|
-
this._addMarkers(markers, this._mapboxViewInstance);
|
|
1070
|
+
await this._addMarkers(markers, this._mapboxViewInstance);
|
|
1034
1071
|
}
|
|
1035
1072
|
catch (ex) {
|
|
1036
1073
|
if (Trace.isEnabled()) {
|
|
1037
|
-
CLog(CLogTypes.
|
|
1074
|
+
CLog(CLogTypes.error, 'Error in mapbox.addMarkers: ' + ex + ex.stack);
|
|
1038
1075
|
}
|
|
1039
1076
|
throw ex;
|
|
1040
1077
|
}
|
|
1041
1078
|
}
|
|
1079
|
+
/**
|
|
1080
|
+
*
|
|
1081
|
+
* @deprecated
|
|
1082
|
+
* @link https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation
|
|
1083
|
+
*/
|
|
1042
1084
|
async removeMarkers(ids, nativeMap) {
|
|
1043
1085
|
try {
|
|
1044
1086
|
this._removeMarkers(ids, this._mapboxViewInstance);
|
|
@@ -1050,146 +1092,124 @@ export class Mapbox extends MapboxCommon {
|
|
|
1050
1092
|
throw ex;
|
|
1051
1093
|
}
|
|
1052
1094
|
}
|
|
1053
|
-
|
|
1054
|
-
*
|
|
1055
|
-
* @deprecated
|
|
1056
|
-
* @link https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation
|
|
1057
|
-
*/
|
|
1058
|
-
_addMarkers(markers, nativeMap) {
|
|
1095
|
+
async _addMarkers(markers, nativeMap) {
|
|
1059
1096
|
if (!markers) {
|
|
1060
1097
|
if (Trace.isEnabled()) {
|
|
1061
|
-
CLog(CLogTypes.
|
|
1098
|
+
CLog(CLogTypes.error, 'No markers passed');
|
|
1062
1099
|
}
|
|
1063
1100
|
return;
|
|
1064
1101
|
}
|
|
1065
1102
|
if (!Array.isArray(markers)) {
|
|
1066
1103
|
if (Trace.isEnabled()) {
|
|
1067
|
-
CLog(CLogTypes.
|
|
1104
|
+
CLog(CLogTypes.error, "markers must be passed as an Array: [{title:'foo'}]");
|
|
1068
1105
|
}
|
|
1069
1106
|
return;
|
|
1070
1107
|
}
|
|
1071
1108
|
if (!this._mapboxMapInstance) {
|
|
1072
1109
|
return;
|
|
1073
1110
|
}
|
|
1074
|
-
if (!this.onMarkerClickListener) {
|
|
1075
|
-
this.onMarkerClickListener = new com.mapbox.mapboxsdk.maps.MapboxMap.OnMarkerClickListener({
|
|
1076
|
-
onMarkerClick: (marker) => {
|
|
1077
|
-
const cachedMarker = this._getClickedMarkerDetails(marker);
|
|
1078
|
-
if (cachedMarker && cachedMarker.onTap) {
|
|
1079
|
-
cachedMarker.onTap(cachedMarker);
|
|
1080
|
-
}
|
|
1081
|
-
return false;
|
|
1082
|
-
}
|
|
1083
|
-
});
|
|
1084
|
-
this._mapboxMapInstance.setOnMarkerClickListener(this.onMarkerClickListener);
|
|
1085
|
-
}
|
|
1086
|
-
if (!this.onInfoWindowClickListener) {
|
|
1087
|
-
this.onInfoWindowClickListener = new com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowClickListener({
|
|
1088
|
-
onInfoWindowClick: (marker) => {
|
|
1089
|
-
const cachedMarker = this._getClickedMarkerDetails(marker);
|
|
1090
|
-
if (cachedMarker && cachedMarker.onCalloutTap) {
|
|
1091
|
-
cachedMarker.onCalloutTap(cachedMarker);
|
|
1092
|
-
}
|
|
1093
|
-
return true;
|
|
1094
|
-
}
|
|
1095
|
-
});
|
|
1096
|
-
this._mapboxMapInstance.setOnInfoWindowClickListener(this.onInfoWindowClickListener);
|
|
1097
|
-
}
|
|
1098
|
-
if (!this.iconFactory) {
|
|
1099
|
-
this.iconFactory = com.mapbox.mapboxsdk.annotations.IconFactory.getInstance(Application.android.context);
|
|
1100
|
-
}
|
|
1101
|
-
const iconFactory = this.iconFactory;
|
|
1102
1111
|
// if any markers need to be downloaded from the web they need to be available synchronously, so fetch them first before looping
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
else {
|
|
1127
|
-
console.warn(`No icon found for this device density for icon ' ${marker.icon}'. Falling back to the default icon.`);
|
|
1112
|
+
if (Trace.isEnabled()) {
|
|
1113
|
+
CLog(CLogTypes.log, 'adding markers');
|
|
1114
|
+
}
|
|
1115
|
+
const updatedMarkers = await this._downloadMarkerImages(markers);
|
|
1116
|
+
if (Trace.isEnabled()) {
|
|
1117
|
+
CLog(CLogTypes.log, 'adding updatedMarkers: ' + JSON.stringify(updatedMarkers));
|
|
1118
|
+
}
|
|
1119
|
+
for (let index = 0; index < updatedMarkers.length; index++) {
|
|
1120
|
+
const marker = updatedMarkers[index];
|
|
1121
|
+
// const markerOptions = new com.mapbox.maps.annotations.MarkerOptions();
|
|
1122
|
+
// markerOptions.setTitle(marker.title);
|
|
1123
|
+
// markerOptions.setSnippet(marker.subtitle);
|
|
1124
|
+
// markerOptions.setPosition(new com.mapbox.maps.geometry.LatLng(marker.lat, marker.lng));
|
|
1125
|
+
let icon;
|
|
1126
|
+
marker.icon = marker.icon || 'res://ic_red_marker';
|
|
1127
|
+
if (marker.icon) {
|
|
1128
|
+
// for markers from url see UrlMarker in https://github.com/mapbox/mapbox-gl-native/issues/5370
|
|
1129
|
+
if (marker.icon.startsWith(Utils.RESOURCE_PREFIX)) {
|
|
1130
|
+
let cached = this.iconCache[marker.icon];
|
|
1131
|
+
if (!cached) {
|
|
1132
|
+
const bitmap = bitmapFromDrawableResource(marker.icon.substring(Utils.RESOURCE_PREFIX.length));
|
|
1133
|
+
if (bitmap) {
|
|
1134
|
+
cached = this.iconCache[marker.icon] = new ImageSource(bitmap);
|
|
1128
1135
|
}
|
|
1129
1136
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
markerOptions.setIcon(iconFactory.fromBitmap(marker.iconDownloaded));
|
|
1133
|
-
}
|
|
1137
|
+
if (cached) {
|
|
1138
|
+
icon = cached;
|
|
1134
1139
|
}
|
|
1135
1140
|
else {
|
|
1136
|
-
|
|
1137
|
-
CLog(CLogTypes.info, 'Please use res://resourcename, http(s)://imageurl or iconPath to use a local path');
|
|
1138
|
-
}
|
|
1141
|
+
console.warn(`No icon found for this device density for icon ' ${marker.icon}'. Falling back to the default icon.`);
|
|
1139
1142
|
}
|
|
1140
1143
|
}
|
|
1141
|
-
else if (marker.
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
// if the file doesn't exist the app will crash, so checking it
|
|
1146
|
-
if (File.exists(iconFullPath)) {
|
|
1147
|
-
// could set width, height, retina, see https://github.com/Telerik-Verified-Plugins/Mapbox/pull/42/files?diff=unified&short_path=1c65267, but that's what the marker.icon param is for..
|
|
1148
|
-
cached = this.iconCache[marker.iconPath] = iconFactory.fromPath(iconFullPath);
|
|
1149
|
-
}
|
|
1144
|
+
else if (marker.icon.startsWith('http')) {
|
|
1145
|
+
if (marker.downloadedIcon !== null) {
|
|
1146
|
+
icon = marker.downloadedIcon;
|
|
1147
|
+
// markerOptions.setIcon(iconFactory.fromBitmap(marker.iconDownloaded));
|
|
1150
1148
|
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1149
|
+
}
|
|
1150
|
+
else {
|
|
1151
|
+
if (Trace.isEnabled()) {
|
|
1152
|
+
CLog(CLogTypes.info, 'Please use res://resourcename, http(s)://imageurl or iconPath to use a local path');
|
|
1153
1153
|
}
|
|
1154
|
-
|
|
1155
|
-
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
else if (marker.iconPath) {
|
|
1157
|
+
let cached = this.iconCache[marker.iconPath];
|
|
1158
|
+
if (!cached) {
|
|
1159
|
+
const iconFullPath = path.join(knownFolders.currentApp().path, marker.iconPath.replace('~/', ''));
|
|
1160
|
+
// if the file doesn't exist the app will crash, so checking it
|
|
1161
|
+
if (File.exists(iconFullPath)) {
|
|
1162
|
+
// could set width, height, retina, see https://github.com/Telerik-Verified-Plugins/Mapbox/pull/42/files?diff=unified&short_path=1c65267, but that's what the marker.icon param is for..
|
|
1163
|
+
cached = this.iconCache[marker.iconPath] = ImageSource.fromFileSync(iconFullPath);
|
|
1156
1164
|
}
|
|
1157
1165
|
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
this._mapboxMapInstance.selectMarker(marker.android);
|
|
1166
|
+
if (cached) {
|
|
1167
|
+
icon = cached;
|
|
1161
1168
|
}
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
_marker.lng = newSettings.lng;
|
|
1183
|
-
_marker.android.setPosition(new com.mapbox.mapboxsdk.geometry.LatLng(parseFloat(newSettings.lat), parseFloat(newSettings.lng)));
|
|
1184
|
-
}
|
|
1185
|
-
if (newSettings.selected) {
|
|
1186
|
-
this._mapboxMapInstance.selectMarker(_marker.android);
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1169
|
+
else {
|
|
1170
|
+
console.warn(`Marker icon not found, using the default instead. Requested path: '" + ${marker.iconPath}'.`);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
marker.android = this.markerManager.addMarker(new AndroidMarker({
|
|
1174
|
+
position: com.mapbox.geojson.Point.fromLngLat(marker.lng, marker.lat),
|
|
1175
|
+
title: marker.title,
|
|
1176
|
+
snippet: marker.subtitle,
|
|
1177
|
+
icon: icon?.android
|
|
1178
|
+
}));
|
|
1179
|
+
this._markers.push(marker);
|
|
1180
|
+
if (marker.selected) {
|
|
1181
|
+
this.markerManager.selectMarker(marker.android);
|
|
1182
|
+
}
|
|
1183
|
+
marker.update = (newSettings) => {
|
|
1184
|
+
console.log('update marker', Object.keys(newSettings), newSettings);
|
|
1185
|
+
const theMarker = this._markers.find((m) => m.id === marker.id);
|
|
1186
|
+
if (theMarker) {
|
|
1187
|
+
if (newSettings.onTap) {
|
|
1188
|
+
theMarker.onTap = newSettings.onTap;
|
|
1189
1189
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1190
|
+
if (newSettings.onCalloutTap) {
|
|
1191
|
+
theMarker.onCalloutTap = newSettings.onCalloutTap;
|
|
1192
|
+
}
|
|
1193
|
+
if (newSettings.title) {
|
|
1194
|
+
theMarker.title = newSettings.title;
|
|
1195
|
+
theMarker.android.title = newSettings.title;
|
|
1196
|
+
}
|
|
1197
|
+
if (newSettings.subtitle) {
|
|
1198
|
+
theMarker.subtitle = newSettings.subtitle;
|
|
1199
|
+
theMarker.android.snippet = newSettings.subtitle;
|
|
1200
|
+
}
|
|
1201
|
+
if (newSettings.lat && newSettings.lng) {
|
|
1202
|
+
theMarker.lat = newSettings.lat;
|
|
1203
|
+
theMarker.lng = newSettings.lng;
|
|
1204
|
+
theMarker.android.position = com.mapbox.geojson.Point.fromLngLat(theMarker.lng, theMarker.lat);
|
|
1205
|
+
}
|
|
1206
|
+
this.markerManager.updateMarker(theMarker.android);
|
|
1207
|
+
if (newSettings.selected) {
|
|
1208
|
+
this.markerManager.selectMarker(theMarker.android, false, true);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1193
1213
|
}
|
|
1194
1214
|
/**
|
|
1195
1215
|
*
|
|
@@ -1199,14 +1219,13 @@ export class Mapbox extends MapboxCommon {
|
|
|
1199
1219
|
if (!this._mapboxMapInstance) {
|
|
1200
1220
|
return;
|
|
1201
1221
|
}
|
|
1202
|
-
|
|
1203
|
-
const marker = this._markers[m];
|
|
1222
|
+
this._markers.forEach((marker) => {
|
|
1204
1223
|
if (!ids || (marker && marker.id && ids.indexOf(marker.id) > -1)) {
|
|
1205
1224
|
if (marker && marker.android) {
|
|
1206
|
-
this.
|
|
1225
|
+
this.markerManager.removeMarker(marker.android);
|
|
1207
1226
|
}
|
|
1208
1227
|
}
|
|
1209
|
-
}
|
|
1228
|
+
});
|
|
1210
1229
|
// remove markers from cache
|
|
1211
1230
|
if (ids) {
|
|
1212
1231
|
this._markers = this._markers.filter((marker) => ids.indexOf(marker.id) === -1);
|
|
@@ -1218,13 +1237,13 @@ export class Mapbox extends MapboxCommon {
|
|
|
1218
1237
|
setCenter(options, nativeMap) {
|
|
1219
1238
|
return new Promise((resolve, reject) => {
|
|
1220
1239
|
try {
|
|
1221
|
-
const cameraPosition = new com.mapbox.
|
|
1240
|
+
const cameraPosition = new com.mapbox.maps.CameraOptions.Builder().center(com.mapbox.geojson.Point.fromLngLat(options.lng, options.lat)).build();
|
|
1222
1241
|
if (options.animated === true) {
|
|
1223
|
-
const
|
|
1224
|
-
|
|
1242
|
+
const animationOptions = new com.mapbox.maps.plugin.animation.MapAnimationOptions.Builder().duration(1000).build();
|
|
1243
|
+
com.nativescript.mapbox.Camera.flyTo(this._mapboxViewInstance, cameraPosition, animationOptions, null);
|
|
1225
1244
|
}
|
|
1226
1245
|
else {
|
|
1227
|
-
this._mapboxMapInstance.
|
|
1246
|
+
this._mapboxMapInstance.setCamera(cameraPosition);
|
|
1228
1247
|
}
|
|
1229
1248
|
resolve();
|
|
1230
1249
|
}
|
|
@@ -1239,10 +1258,10 @@ export class Mapbox extends MapboxCommon {
|
|
|
1239
1258
|
getCenter(nativeMap) {
|
|
1240
1259
|
return new Promise((resolve, reject) => {
|
|
1241
1260
|
try {
|
|
1242
|
-
const coordinate = this._mapboxMapInstance.
|
|
1261
|
+
const coordinate = this._mapboxMapInstance.getCameraState().getCenter();
|
|
1243
1262
|
resolve({
|
|
1244
|
-
lat: coordinate.
|
|
1245
|
-
lng: coordinate.
|
|
1263
|
+
lat: coordinate.latitude(),
|
|
1264
|
+
lng: coordinate.longitude()
|
|
1246
1265
|
});
|
|
1247
1266
|
}
|
|
1248
1267
|
catch (ex) {
|
|
@@ -1259,12 +1278,13 @@ export class Mapbox extends MapboxCommon {
|
|
|
1259
1278
|
const animated = options.animated === undefined || options.animated;
|
|
1260
1279
|
const level = options.level;
|
|
1261
1280
|
if (level >= 0 && level <= 20) {
|
|
1262
|
-
const
|
|
1281
|
+
const cameraPosition = new com.mapbox.maps.CameraOptions.Builder().zoom(java.lang.Double.valueOf(level)).build();
|
|
1263
1282
|
if (animated) {
|
|
1264
|
-
|
|
1283
|
+
const animationOptions = new com.mapbox.maps.plugin.animation.MapAnimationOptions.Builder().build();
|
|
1284
|
+
com.nativescript.mapbox.Camera.flyTo(this._mapboxViewInstance, cameraPosition, animationOptions, null);
|
|
1265
1285
|
}
|
|
1266
1286
|
else {
|
|
1267
|
-
this._mapboxMapInstance.
|
|
1287
|
+
this._mapboxMapInstance.setCamera(cameraPosition);
|
|
1268
1288
|
}
|
|
1269
1289
|
resolve();
|
|
1270
1290
|
}
|
|
@@ -1283,7 +1303,7 @@ export class Mapbox extends MapboxCommon {
|
|
|
1283
1303
|
getZoomLevel(nativeMap) {
|
|
1284
1304
|
return new Promise((resolve, reject) => {
|
|
1285
1305
|
try {
|
|
1286
|
-
const level = this._mapboxMapInstance.
|
|
1306
|
+
const level = this._mapboxMapInstance.getCameraState().getZoom();
|
|
1287
1307
|
resolve(level);
|
|
1288
1308
|
}
|
|
1289
1309
|
catch (ex) {
|
|
@@ -1298,13 +1318,21 @@ export class Mapbox extends MapboxCommon {
|
|
|
1298
1318
|
return new Promise((resolve, reject) => {
|
|
1299
1319
|
try {
|
|
1300
1320
|
const tilt = options.tilt ? options.tilt : 30;
|
|
1301
|
-
const
|
|
1302
|
-
const
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1321
|
+
const cameraPosition = new com.mapbox.maps.CameraOptions.Builder().pitch(java.lang.Double.valueOf(tilt)).build();
|
|
1322
|
+
const animated = options.animated === undefined || options.animated;
|
|
1323
|
+
if (animated) {
|
|
1324
|
+
const animationOptions = new com.mapbox.maps.plugin.animation.MapAnimationOptions.Builder().duration(options.duration ? options.duration : 5000).build();
|
|
1325
|
+
com.nativescript.mapbox.Camera.flyTo(this._mapboxViewInstance, cameraPosition, animationOptions, new android.animation.Animator.AnimatorListener({
|
|
1326
|
+
onAnimationCancel: () => resolve(),
|
|
1327
|
+
onAnimationEnd: () => resolve(),
|
|
1328
|
+
onAnimationStart: () => { },
|
|
1329
|
+
onAnimationRepeat: () => { }
|
|
1330
|
+
}));
|
|
1331
|
+
}
|
|
1332
|
+
else {
|
|
1333
|
+
this._mapboxMapInstance.setCamera(cameraPosition);
|
|
1306
1334
|
resolve();
|
|
1307
|
-
}
|
|
1335
|
+
}
|
|
1308
1336
|
}
|
|
1309
1337
|
catch (ex) {
|
|
1310
1338
|
if (Trace.isEnabled()) {
|
|
@@ -1317,7 +1345,7 @@ export class Mapbox extends MapboxCommon {
|
|
|
1317
1345
|
getTilt(nativeMap) {
|
|
1318
1346
|
return new Promise((resolve, reject) => {
|
|
1319
1347
|
try {
|
|
1320
|
-
const tilt = this._mapboxMapInstance.
|
|
1348
|
+
const tilt = this._mapboxMapInstance.getCameraState().getPitch();
|
|
1321
1349
|
resolve(tilt);
|
|
1322
1350
|
}
|
|
1323
1351
|
catch (ex) {
|
|
@@ -1336,12 +1364,18 @@ export class Mapbox extends MapboxCommon {
|
|
|
1336
1364
|
getUserLocation() {
|
|
1337
1365
|
return new Promise((resolve, reject) => {
|
|
1338
1366
|
try {
|
|
1339
|
-
const
|
|
1340
|
-
|
|
1367
|
+
// const locationPlugin = this._getPlugin<com.mapbox.maps.plugin.locationcomponent.LocationComponentPlugin>("MAPBOX_LOCATION_COMPONENT_PLUGIN_ID");
|
|
1368
|
+
// const loc = this._locationComponent ? this._locationComponent.getLastKnownLocation() : null;
|
|
1369
|
+
if (this.lastKnownLocation === null) {
|
|
1341
1370
|
reject('Location not available');
|
|
1342
1371
|
}
|
|
1343
1372
|
else {
|
|
1344
|
-
resolve(
|
|
1373
|
+
resolve({
|
|
1374
|
+
location: {
|
|
1375
|
+
lat: this.lastKnownLocation.latitude(),
|
|
1376
|
+
lng: this.lastKnownLocation.longitude()
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1345
1379
|
}
|
|
1346
1380
|
}
|
|
1347
1381
|
catch (ex) {
|
|
@@ -1362,24 +1396,36 @@ export class Mapbox extends MapboxCommon {
|
|
|
1362
1396
|
reject("Please set the 'point' parameter");
|
|
1363
1397
|
return;
|
|
1364
1398
|
}
|
|
1399
|
+
if (!this._mapboxMapInstance) {
|
|
1400
|
+
reject('No map has been loaded');
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1365
1403
|
if (!options) {
|
|
1366
1404
|
options = {};
|
|
1367
1405
|
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
if (this._mapboxMapInstance.queryRenderedFeatures) {
|
|
1371
|
-
const queryFilter = options.filter ? ExpressionParser.parseJson(options.filter) : null;
|
|
1372
|
-
const features = this._mapboxMapInstance.queryRenderedFeatures(screenLocation, queryFilter, options.layers);
|
|
1373
|
-
const result = [];
|
|
1374
|
-
for (let i = 0; i < features.size(); i++) {
|
|
1375
|
-
const feature = features.get(i);
|
|
1376
|
-
result.push(JSON.parse(feature.toJson()));
|
|
1377
|
-
}
|
|
1378
|
-
resolve(result);
|
|
1379
|
-
}
|
|
1380
|
-
else {
|
|
1381
|
-
reject('Feature not supported by this Mapbox version');
|
|
1406
|
+
if (Trace.isEnabled()) {
|
|
1407
|
+
CLog(CLogTypes.info, 'Mapbox:queryRenderedFeatures(): ', JSON.stringify(options));
|
|
1382
1408
|
}
|
|
1409
|
+
const mapboxPoint = com.mapbox.geojson.Point.fromLngLat(options.point.lng, options.point.lat);
|
|
1410
|
+
const screenLocation = this._mapboxMapInstance.pixelForCoordinate(mapboxPoint);
|
|
1411
|
+
const queryFilter = options.filter ? ExpressionParser.parseJson(options.filter) : null;
|
|
1412
|
+
const queryOptions = new com.mapbox.maps.RenderedQueryOptions(java.util.Arrays.asList(options.layers), queryFilter);
|
|
1413
|
+
this._mapboxMapInstance.queryRenderedFeatures(com.mapbox.maps.RenderedQueryGeometry.valueOf(screenLocation), queryOptions, new com.mapbox.maps.QueryRenderedFeaturesCallback({
|
|
1414
|
+
run: (result) => {
|
|
1415
|
+
if (result.isError()) {
|
|
1416
|
+
reject(new Error(result.getError()));
|
|
1417
|
+
}
|
|
1418
|
+
else {
|
|
1419
|
+
const features = result.getValue();
|
|
1420
|
+
const jsFeatures = [];
|
|
1421
|
+
for (let i = 0; i < features.size(); i++) {
|
|
1422
|
+
const feature = features.get(i);
|
|
1423
|
+
jsFeatures.push(JSON.parse(feature.getQueriedFeature().getFeature().toJson()));
|
|
1424
|
+
}
|
|
1425
|
+
resolve(jsFeatures);
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
}));
|
|
1383
1429
|
}
|
|
1384
1430
|
catch (ex) {
|
|
1385
1431
|
if (Trace.isEnabled()) {
|
|
@@ -1395,30 +1441,34 @@ export class Mapbox extends MapboxCommon {
|
|
|
1395
1441
|
if (!options) {
|
|
1396
1442
|
options = {};
|
|
1397
1443
|
}
|
|
1398
|
-
const source = this.
|
|
1444
|
+
const source = this.getSource(sourceId);
|
|
1399
1445
|
if (!source) {
|
|
1400
1446
|
throw new Error(`Source with id "${sourceId}" not found.`);
|
|
1401
1447
|
}
|
|
1402
|
-
let features;
|
|
1403
1448
|
const queryFilter = options.filter ? ExpressionParser.parseJson(options.filter) : null;
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1449
|
+
this._mapboxMapInstance.querySourceFeatures(sourceId, new com.mapbox.maps.SourceQueryOptions(null, // source layer IDs
|
|
1450
|
+
queryFilter), new com.mapbox.maps.QuerySourceFeaturesCallback({
|
|
1451
|
+
run(result) {
|
|
1452
|
+
if (result.isError()) {
|
|
1453
|
+
reject(new Error(result.getError()));
|
|
1454
|
+
}
|
|
1455
|
+
else {
|
|
1456
|
+
const lineFeatures = result.getValue();
|
|
1457
|
+
if (lineFeatures.size() === 0) {
|
|
1458
|
+
reject(new Error('no line string feature found'));
|
|
1459
|
+
}
|
|
1460
|
+
else {
|
|
1461
|
+
const features = result.getValue();
|
|
1462
|
+
const jsFeatures = [];
|
|
1463
|
+
for (let i = 0; i < features.size(); i++) {
|
|
1464
|
+
const feature = features.get(i);
|
|
1465
|
+
jsFeatures.push(JSON.parse(feature.getQueriedFeature().getFeature().toJson()));
|
|
1466
|
+
}
|
|
1467
|
+
resolve(jsFeatures);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1410
1470
|
}
|
|
1411
|
-
|
|
1412
|
-
}
|
|
1413
|
-
else {
|
|
1414
|
-
throw new Error('Only sources from type "vector" or "geojson" are supported.');
|
|
1415
|
-
}
|
|
1416
|
-
const result = [];
|
|
1417
|
-
for (let i = 0; i < features.size(); i++) {
|
|
1418
|
-
const feature = features.get(i);
|
|
1419
|
-
result.push(JSON.parse(feature.toJson()));
|
|
1420
|
-
}
|
|
1421
|
-
resolve(result);
|
|
1471
|
+
}));
|
|
1422
1472
|
}
|
|
1423
1473
|
catch (ex) {
|
|
1424
1474
|
if (Trace.isEnabled()) {
|
|
@@ -1440,21 +1490,21 @@ export class Mapbox extends MapboxCommon {
|
|
|
1440
1490
|
reject("Please set the 'points' parameter");
|
|
1441
1491
|
return;
|
|
1442
1492
|
}
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
polygonOptions.add(new com.mapbox.mapboxsdk.geometry.LatLng(point.lat, point.lng));
|
|
1493
|
+
if (!this.polygonManager) {
|
|
1494
|
+
const annotationPlugin = this._getPlugin('MAPBOX_ANNOTATION_PLUGIN_ID');
|
|
1495
|
+
this.polygonManager = annotationPlugin.createAnnotationManager(com.mapbox.maps.plugin.annotation.AnnotationType.PolygonAnnotation, new com.mapbox.maps.plugin.annotation.AnnotationConfig());
|
|
1447
1496
|
}
|
|
1448
|
-
polygonOptions.
|
|
1449
|
-
|
|
1497
|
+
const polygonOptions = new com.mapbox.maps.plugin.annotation.generated.PolygonAnnotationOptions();
|
|
1498
|
+
const nPoints = java.util.Arrays.asList([java.util.Arrays.asList(points.map((p) => com.mapbox.geojson.Point.fromLngLat(p.lng, p.lat)))]);
|
|
1499
|
+
console.log('add points', nPoints);
|
|
1500
|
+
polygonOptions.withPoints(nPoints);
|
|
1501
|
+
polygonOptions.withFillColor(Mapbox.getAndroidColor(options.fillColor));
|
|
1502
|
+
polygonOptions.withFillOpacity(options.fillOpacity === undefined ? 1 : options.fillOpacity);
|
|
1450
1503
|
// Note that the stroke is barely visible, see https://github.com/mapbox/mapbox-gl-native/issues/5676
|
|
1451
1504
|
if (options.strokeColor) {
|
|
1452
|
-
polygonOptions.
|
|
1505
|
+
polygonOptions.withFillOutlineColor(Mapbox.getAndroidColor(options.strokeColor));
|
|
1453
1506
|
}
|
|
1454
|
-
this.
|
|
1455
|
-
id: options.id || new Date().getTime(),
|
|
1456
|
-
android: this._mapboxMapInstance.addPolygon(polygonOptions)
|
|
1457
|
-
});
|
|
1507
|
+
this._polylines[options.id || new Date().getTime()] = this.polygonManager.create(polygonOptions);
|
|
1458
1508
|
resolve();
|
|
1459
1509
|
}
|
|
1460
1510
|
catch (ex) {
|
|
@@ -1477,18 +1527,16 @@ export class Mapbox extends MapboxCommon {
|
|
|
1477
1527
|
reject("Please set the 'points' parameter");
|
|
1478
1528
|
return;
|
|
1479
1529
|
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
android: this._mapboxMapInstance.addPolyline(polylineOptions)
|
|
1491
|
-
});
|
|
1530
|
+
if (!this.lineManager) {
|
|
1531
|
+
const annotationPlugin = this._getPlugin('MAPBOX_ANNOTATION_PLUGIN_ID');
|
|
1532
|
+
this.lineManager = annotationPlugin.createAnnotationManager(com.mapbox.maps.plugin.annotation.AnnotationType.PolylineAnnotation, new com.mapbox.maps.plugin.annotation.AnnotationConfig());
|
|
1533
|
+
}
|
|
1534
|
+
const polylineOptions = new com.mapbox.maps.plugin.annotation.generated.PolylineAnnotationOptions();
|
|
1535
|
+
polylineOptions.withLineWidth(options.width || 5); // default 5
|
|
1536
|
+
polylineOptions.withLineColor(Mapbox.getAndroidColor(options.color));
|
|
1537
|
+
polylineOptions.withLineOpacity(options.opacity === undefined ? 1 : options.opacity);
|
|
1538
|
+
polylineOptions.withPoints(java.util.Arrays.asList(points.map((p) => com.mapbox.geojson.Point.fromLngLat(p.lng, p.lat))));
|
|
1539
|
+
this._polylines[options.id || new Date().getTime()] = this.lineManager.create(polylineOptions);
|
|
1492
1540
|
resolve();
|
|
1493
1541
|
}
|
|
1494
1542
|
catch (ex) {
|
|
@@ -1502,12 +1550,16 @@ export class Mapbox extends MapboxCommon {
|
|
|
1502
1550
|
removePolygons(ids, nativeMap) {
|
|
1503
1551
|
return new Promise((resolve, reject) => {
|
|
1504
1552
|
try {
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1553
|
+
if (!ids) {
|
|
1554
|
+
this.polygonManager.deleteAll();
|
|
1555
|
+
this._polygons = {};
|
|
1556
|
+
}
|
|
1557
|
+
ids.forEach((id) => {
|
|
1558
|
+
if (this._polygons[id]) {
|
|
1559
|
+
this.polygonManager.delete(this._polygons[id]);
|
|
1560
|
+
delete this._polygons[id];
|
|
1509
1561
|
}
|
|
1510
|
-
}
|
|
1562
|
+
});
|
|
1511
1563
|
resolve();
|
|
1512
1564
|
}
|
|
1513
1565
|
catch (ex) {
|
|
@@ -1521,12 +1573,16 @@ export class Mapbox extends MapboxCommon {
|
|
|
1521
1573
|
removePolylines(ids, nativeMap) {
|
|
1522
1574
|
return new Promise((resolve, reject) => {
|
|
1523
1575
|
try {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1576
|
+
if (!ids) {
|
|
1577
|
+
this.lineManager.deleteAll();
|
|
1578
|
+
this._polylines = {};
|
|
1579
|
+
}
|
|
1580
|
+
ids.forEach((id) => {
|
|
1581
|
+
if (this._polylines[id]) {
|
|
1582
|
+
this.lineManager.delete(this._polylines[id]);
|
|
1583
|
+
delete this._polylines[id];
|
|
1528
1584
|
}
|
|
1529
|
-
}
|
|
1585
|
+
});
|
|
1530
1586
|
resolve();
|
|
1531
1587
|
}
|
|
1532
1588
|
catch (ex) {
|
|
@@ -1545,12 +1601,19 @@ export class Mapbox extends MapboxCommon {
|
|
|
1545
1601
|
const padding = options.padding || 0;
|
|
1546
1602
|
const defaultPadding = 0;
|
|
1547
1603
|
// ensure padding is an object and assign default values
|
|
1548
|
-
const {
|
|
1549
|
-
const
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1604
|
+
const { bottom = defaultPadding, left = defaultPadding, right = defaultPadding, top = defaultPadding } = typeof padding === 'object' ? padding : { top: padding, left: padding, bottom: padding, right: padding };
|
|
1605
|
+
const cameraForBounds = this._mapboxMapInstance.cameraForCoordinates(java.util.Arrays.asList([
|
|
1606
|
+
com.mapbox.geojson.Point.fromLngLat(options.bounds.west, options.bounds.north),
|
|
1607
|
+
com.mapbox.geojson.Point.fromLngLat(options.bounds.east, options.bounds.south)
|
|
1608
|
+
]), new com.mapbox.maps.EdgeInsets(top, left, bottom, right), java.lang.Double.valueOf(options.bearing ?? 0), // bearing
|
|
1609
|
+
java.lang.Double.valueOf(options.tilt ?? 0) // pitch
|
|
1610
|
+
);
|
|
1611
|
+
const cameraOptionsBuilder = new com.mapbox.maps.CameraOptions.Builder();
|
|
1612
|
+
cameraOptionsBuilder.center(cameraForBounds.getCenter());
|
|
1613
|
+
cameraOptionsBuilder.zoom(cameraForBounds.getZoom());
|
|
1614
|
+
cameraOptionsBuilder.bearing(cameraForBounds.getBearing());
|
|
1615
|
+
cameraOptionsBuilder.pitch(cameraForBounds.getPitch());
|
|
1616
|
+
com.nativescript.mapbox.Camera.flyTo(this._mapboxViewInstance, cameraOptionsBuilder.build(), new com.mapbox.maps.plugin.animation.MapAnimationOptions.Builder().duration(durationMs).build(), null);
|
|
1554
1617
|
}
|
|
1555
1618
|
else {
|
|
1556
1619
|
const target = options.target;
|
|
@@ -1558,17 +1621,18 @@ export class Mapbox extends MapboxCommon {
|
|
|
1558
1621
|
reject("Please set the 'target' parameter");
|
|
1559
1622
|
return;
|
|
1560
1623
|
}
|
|
1561
|
-
const
|
|
1624
|
+
const cameraOptionsBuilder = new com.mapbox.maps.CameraOptions.Builder();
|
|
1625
|
+
cameraOptionsBuilder.center(com.mapbox.geojson.Point.fromLngLat(target.lng, target.lat));
|
|
1562
1626
|
if (options.bearing) {
|
|
1563
|
-
|
|
1627
|
+
cameraOptionsBuilder.bearing(java.lang.Double.valueOf(options.bearing));
|
|
1564
1628
|
}
|
|
1565
1629
|
if (options.tilt) {
|
|
1566
|
-
|
|
1630
|
+
cameraOptionsBuilder.pitch(java.lang.Double.valueOf(options.tilt));
|
|
1567
1631
|
}
|
|
1568
1632
|
if (options.zoomLevel) {
|
|
1569
|
-
|
|
1633
|
+
cameraOptionsBuilder.zoom(java.lang.Double.valueOf(options.zoomLevel));
|
|
1570
1634
|
}
|
|
1571
|
-
this.
|
|
1635
|
+
com.nativescript.mapbox.Camera.flyTo(this._mapboxViewInstance, cameraOptionsBuilder.build(), new com.mapbox.maps.plugin.animation.MapAnimationOptions.Builder().duration(durationMs).build(), null);
|
|
1572
1636
|
}
|
|
1573
1637
|
setTimeout(() => {
|
|
1574
1638
|
resolve();
|
|
@@ -1582,14 +1646,6 @@ export class Mapbox extends MapboxCommon {
|
|
|
1582
1646
|
}
|
|
1583
1647
|
});
|
|
1584
1648
|
}
|
|
1585
|
-
/**
|
|
1586
|
-
* set an on map click listener.
|
|
1587
|
-
*
|
|
1588
|
-
* The new Mapbox Native SDK allows for multiple listeners on an event and follows the standard
|
|
1589
|
-
* pattern of returning 'true' when a handler has handled the event and others shouldn't.
|
|
1590
|
-
*
|
|
1591
|
-
* Not returning a boolean from the listener function will cause a crash.
|
|
1592
|
-
*/
|
|
1593
1649
|
setOnMapClickListener(listener, nativeMap) {
|
|
1594
1650
|
return new Promise((resolve, reject) => {
|
|
1595
1651
|
try {
|
|
@@ -1597,23 +1653,23 @@ export class Mapbox extends MapboxCommon {
|
|
|
1597
1653
|
reject('No map has been loaded');
|
|
1598
1654
|
return;
|
|
1599
1655
|
}
|
|
1600
|
-
this.onMapClickListener = new com.mapbox.
|
|
1656
|
+
this.onMapClickListener = new com.mapbox.maps.plugin.gestures.OnMapClickListener({
|
|
1601
1657
|
onMapClick: (point) => {
|
|
1602
1658
|
if (Trace.isEnabled()) {
|
|
1603
1659
|
CLog(CLogTypes.info, 'Mapbox:setOnMapClickListener(): click event at point:', point);
|
|
1604
1660
|
}
|
|
1605
|
-
return
|
|
1606
|
-
lat: point.
|
|
1607
|
-
lng: point.
|
|
1661
|
+
return this.checkForClickEvent({
|
|
1662
|
+
lat: point.latitude(),
|
|
1663
|
+
lng: point.longitude()
|
|
1608
1664
|
});
|
|
1609
1665
|
}
|
|
1610
1666
|
});
|
|
1611
|
-
|
|
1667
|
+
com.mapbox.maps.plugin.gestures.GesturesUtils.addOnMapClickListener(this._mapboxMapInstance, this.onMapClickListener);
|
|
1612
1668
|
resolve();
|
|
1613
1669
|
}
|
|
1614
1670
|
catch (ex) {
|
|
1615
1671
|
if (Trace.isEnabled()) {
|
|
1616
|
-
CLog(CLogTypes.info, 'Error in mapbox.
|
|
1672
|
+
CLog(CLogTypes.info, 'Error in mapbox.setOnMapLongClickListener: ' + ex);
|
|
1617
1673
|
}
|
|
1618
1674
|
reject(ex);
|
|
1619
1675
|
}
|
|
@@ -1626,13 +1682,13 @@ export class Mapbox extends MapboxCommon {
|
|
|
1626
1682
|
reject('No map has been loaded');
|
|
1627
1683
|
return;
|
|
1628
1684
|
}
|
|
1629
|
-
this.onMapLongClickListener = new com.mapbox.
|
|
1685
|
+
this.onMapLongClickListener = new com.mapbox.maps.plugin.gestures.OnMapLongClickListener({
|
|
1630
1686
|
onMapLongClick: (point) => listener({
|
|
1631
|
-
lat: point.
|
|
1632
|
-
lng: point.
|
|
1687
|
+
lat: point.latitude(),
|
|
1688
|
+
lng: point.longitude()
|
|
1633
1689
|
})
|
|
1634
1690
|
});
|
|
1635
|
-
this.
|
|
1691
|
+
this._getGesturesPlugin().addOnMapLongClickListener(this.onMapLongClickListener);
|
|
1636
1692
|
resolve();
|
|
1637
1693
|
}
|
|
1638
1694
|
catch (ex) {
|
|
@@ -1653,18 +1709,18 @@ export class Mapbox extends MapboxCommon {
|
|
|
1653
1709
|
if (Trace.isEnabled()) {
|
|
1654
1710
|
CLog(CLogTypes.info, 'setOnMoveBeginListener():');
|
|
1655
1711
|
}
|
|
1656
|
-
this.
|
|
1657
|
-
onMoveBegin: (detector
|
|
1658
|
-
const coordinate = this._mapboxMapInstance.
|
|
1712
|
+
this.onMoveBeginListener = new com.mapbox.maps.plugin.gestures.OnMoveListener({
|
|
1713
|
+
onMoveBegin: (detector) => {
|
|
1714
|
+
const coordinate = this._mapboxMapInstance.getCameraState().getCenter();
|
|
1659
1715
|
return listener({
|
|
1660
|
-
lat: coordinate.
|
|
1661
|
-
lng: coordinate.
|
|
1716
|
+
lat: coordinate.latitude(),
|
|
1717
|
+
lng: coordinate.longitude()
|
|
1662
1718
|
});
|
|
1663
1719
|
},
|
|
1664
|
-
onMove: (detector
|
|
1665
|
-
onMoveEnd: (detector
|
|
1720
|
+
onMove: (detector) => false,
|
|
1721
|
+
onMoveEnd: (detector) => { }
|
|
1666
1722
|
});
|
|
1667
|
-
|
|
1723
|
+
com.mapbox.maps.plugin.gestures.GesturesUtils.addOnMoveListener(this._mapboxMapInstance, this.onMoveBeginListener);
|
|
1668
1724
|
resolve();
|
|
1669
1725
|
}
|
|
1670
1726
|
catch (ex) {
|
|
@@ -1685,18 +1741,18 @@ export class Mapbox extends MapboxCommon {
|
|
|
1685
1741
|
if (Trace.isEnabled()) {
|
|
1686
1742
|
CLog(CLogTypes.info, 'setOnMoveEndListener():');
|
|
1687
1743
|
}
|
|
1688
|
-
this.
|
|
1744
|
+
this.onMoveEndListener = new com.mapbox.maps.plugin.gestures.OnMoveListener({
|
|
1689
1745
|
onMoveBegin: (detector /* MoveGestureDetector */) => { },
|
|
1690
|
-
onMove: (detector
|
|
1746
|
+
onMove: (detector) => false,
|
|
1691
1747
|
onMoveEnd: (detector /* MoveGestureDetector */) => {
|
|
1692
|
-
const coordinate = this._mapboxMapInstance.
|
|
1748
|
+
const coordinate = this._mapboxMapInstance.getCameraState().getCenter();
|
|
1693
1749
|
return listener({
|
|
1694
|
-
lat: coordinate.
|
|
1695
|
-
lng: coordinate.
|
|
1750
|
+
lat: coordinate.latitude(),
|
|
1751
|
+
lng: coordinate.longitude()
|
|
1696
1752
|
});
|
|
1697
1753
|
}
|
|
1698
1754
|
});
|
|
1699
|
-
|
|
1755
|
+
com.mapbox.maps.plugin.gestures.GesturesUtils.addOnMoveListener(this._mapboxMapInstance, this.onMoveEndListener);
|
|
1700
1756
|
resolve();
|
|
1701
1757
|
}
|
|
1702
1758
|
catch (ex) {
|
|
@@ -1718,18 +1774,19 @@ export class Mapbox extends MapboxCommon {
|
|
|
1718
1774
|
CLog(CLogTypes.info, 'setOnScrollListener():');
|
|
1719
1775
|
}
|
|
1720
1776
|
// the 'onMove' event seems like the one closest to the iOS implementation
|
|
1721
|
-
this.onScrollListener = new com.mapbox.
|
|
1777
|
+
this.onScrollListener = new com.mapbox.maps.plugin.gestures.OnMoveListener({
|
|
1722
1778
|
onMoveBegin: (detector /* MoveGestureDetector */) => { },
|
|
1723
1779
|
onMove: (detector /* MoveGestureDetector */) => {
|
|
1724
|
-
const coordinate = this._mapboxMapInstance.
|
|
1725
|
-
|
|
1726
|
-
lat: coordinate.
|
|
1727
|
-
lng: coordinate.
|
|
1780
|
+
const coordinate = this._mapboxMapInstance.getCameraState().getCenter();
|
|
1781
|
+
listener({
|
|
1782
|
+
lat: coordinate.latitude(),
|
|
1783
|
+
lng: coordinate.longitude()
|
|
1728
1784
|
});
|
|
1785
|
+
return false;
|
|
1729
1786
|
},
|
|
1730
1787
|
onMoveEnd: (detector /* MoveGestureDetector */) => { }
|
|
1731
1788
|
});
|
|
1732
|
-
|
|
1789
|
+
com.mapbox.maps.plugin.gestures.GesturesUtils.addOnMoveListener(this._mapboxMapInstance, this.onScrollListener);
|
|
1733
1790
|
resolve();
|
|
1734
1791
|
}
|
|
1735
1792
|
catch (ex) {
|
|
@@ -1747,10 +1804,10 @@ export class Mapbox extends MapboxCommon {
|
|
|
1747
1804
|
reject('No map has been loaded');
|
|
1748
1805
|
return;
|
|
1749
1806
|
}
|
|
1750
|
-
this.onFlingListener = new com.mapbox.
|
|
1807
|
+
this.onFlingListener = new com.mapbox.maps.plugin.gestures.OnFlingListener({
|
|
1751
1808
|
onFling: () => listener()
|
|
1752
1809
|
});
|
|
1753
|
-
this.
|
|
1810
|
+
this._getGesturesPlugin().addOnFlingListener(this.onFlingListener);
|
|
1754
1811
|
resolve();
|
|
1755
1812
|
}
|
|
1756
1813
|
catch (ex) {
|
|
@@ -1761,17 +1818,18 @@ export class Mapbox extends MapboxCommon {
|
|
|
1761
1818
|
}
|
|
1762
1819
|
});
|
|
1763
1820
|
}
|
|
1764
|
-
|
|
1821
|
+
setOnCameraChangeListener(listener, nativeMap) {
|
|
1765
1822
|
return new Promise((resolve, reject) => {
|
|
1766
1823
|
try {
|
|
1767
1824
|
if (!this._mapboxMapInstance) {
|
|
1768
1825
|
reject('No map has been loaded');
|
|
1769
1826
|
return;
|
|
1770
1827
|
}
|
|
1771
|
-
this.onCameraMoveListener = new com.mapbox.
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1828
|
+
this.onCameraMoveListener = this._mapboxMapInstance.subscribeCameraChanged(new com.mapbox.maps.CameraChangedCallback({
|
|
1829
|
+
run(param) {
|
|
1830
|
+
listener(0, false);
|
|
1831
|
+
}
|
|
1832
|
+
}));
|
|
1775
1833
|
resolve();
|
|
1776
1834
|
}
|
|
1777
1835
|
catch (ex) {
|
|
@@ -1784,36 +1842,19 @@ export class Mapbox extends MapboxCommon {
|
|
|
1784
1842
|
}
|
|
1785
1843
|
setOnCameraMoveCancelListener(listener, nativeMap) {
|
|
1786
1844
|
return new Promise((resolve, reject) => {
|
|
1787
|
-
|
|
1788
|
-
if (!this._mapboxMapInstance) {
|
|
1789
|
-
reject('No map has been loaded');
|
|
1790
|
-
return;
|
|
1791
|
-
}
|
|
1792
|
-
this.onCameraMoveCancelListener = new com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveCanceledListener({
|
|
1793
|
-
onCameraMoveCanceled: () => listener()
|
|
1794
|
-
});
|
|
1795
|
-
this._mapboxMapInstance.addOnCameraMoveCancelListener(this.onCameraMoveCancelListener);
|
|
1796
|
-
resolve();
|
|
1797
|
-
}
|
|
1798
|
-
catch (ex) {
|
|
1799
|
-
if (Trace.isEnabled()) {
|
|
1800
|
-
CLog(CLogTypes.info, 'Error in mapbox.setOnCameraMoveCancelListener: ' + ex);
|
|
1801
|
-
}
|
|
1802
|
-
reject(ex);
|
|
1803
|
-
}
|
|
1845
|
+
reject('No conCameraMoveCancel event');
|
|
1804
1846
|
});
|
|
1805
1847
|
}
|
|
1806
|
-
|
|
1848
|
+
setOnMapIdleListener(listener, nativeMap) {
|
|
1807
1849
|
return new Promise((resolve, reject) => {
|
|
1808
1850
|
try {
|
|
1809
1851
|
if (!this._mapboxMapInstance) {
|
|
1810
1852
|
reject('No map has been loaded');
|
|
1811
1853
|
return;
|
|
1812
1854
|
}
|
|
1813
|
-
this.
|
|
1814
|
-
|
|
1815
|
-
});
|
|
1816
|
-
this._mapboxMapInstance.addOnCameraIdleListener(this.onCameraIdleListener);
|
|
1855
|
+
this.onMapIdleListener = this._mapboxMapInstance.subscribeMapIdle(new com.mapbox.maps.MapIdleCallback({
|
|
1856
|
+
run: () => listener()
|
|
1857
|
+
}));
|
|
1817
1858
|
resolve();
|
|
1818
1859
|
}
|
|
1819
1860
|
catch (ex) {
|
|
@@ -1824,31 +1865,38 @@ export class Mapbox extends MapboxCommon {
|
|
|
1824
1865
|
}
|
|
1825
1866
|
});
|
|
1826
1867
|
}
|
|
1827
|
-
getViewport(nativeMap) {
|
|
1828
|
-
return new Promise((resolve, reject) => {
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1868
|
+
async getViewport(nativeMap) {
|
|
1869
|
+
// return new Promise((resolve, reject) => {
|
|
1870
|
+
try {
|
|
1871
|
+
if (!this._mapboxMapInstance) {
|
|
1872
|
+
throw new Error('No map has been loaded');
|
|
1873
|
+
}
|
|
1874
|
+
const cameraState = this._mapboxMapInstance.getCameraState();
|
|
1875
|
+
// Get the screen coordinate bounds
|
|
1876
|
+
// Get the map view size
|
|
1877
|
+
const width = this._mapboxViewInstance.getWidth();
|
|
1878
|
+
const height = this._mapboxViewInstance.getHeight();
|
|
1879
|
+
// Top-left (NW)
|
|
1880
|
+
const nw = this._mapboxMapInstance.coordinateForPixel(new com.mapbox.maps.ScreenCoordinate(0, 0));
|
|
1881
|
+
// Bottom-right (SE)
|
|
1882
|
+
const se = this._mapboxMapInstance.coordinateForPixel(new com.mapbox.maps.ScreenCoordinate(width, height));
|
|
1883
|
+
return {
|
|
1884
|
+
bounds: {
|
|
1885
|
+
north: nw.latitude(),
|
|
1886
|
+
east: se.longitude(),
|
|
1887
|
+
south: se.latitude(),
|
|
1888
|
+
west: nw.longitude()
|
|
1889
|
+
},
|
|
1890
|
+
zoomLevel: cameraState.getZoom()
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
catch (ex) {
|
|
1894
|
+
if (Trace.isEnabled()) {
|
|
1895
|
+
CLog(CLogTypes.info, 'Error in mapbox.getViewport: ' + ex);
|
|
1850
1896
|
}
|
|
1851
|
-
|
|
1897
|
+
throw ex;
|
|
1898
|
+
}
|
|
1899
|
+
// });
|
|
1852
1900
|
}
|
|
1853
1901
|
setViewport(options, nativeMap) {
|
|
1854
1902
|
return new Promise((resolve, reject) => {
|
|
@@ -1857,22 +1905,29 @@ export class Mapbox extends MapboxCommon {
|
|
|
1857
1905
|
reject('No map has been loaded');
|
|
1858
1906
|
return;
|
|
1859
1907
|
}
|
|
1860
|
-
const bounds = new com.mapbox.mapboxsdk.geometry.LatLngBounds.Builder()
|
|
1861
|
-
.include(new com.mapbox.mapboxsdk.geometry.LatLng(options.bounds.north, options.bounds.east))
|
|
1862
|
-
.include(new com.mapbox.mapboxsdk.geometry.LatLng(options.bounds.south, options.bounds.west))
|
|
1863
|
-
.build();
|
|
1864
1908
|
const defaultPadding = 25;
|
|
1865
1909
|
const padding = options.padding ?? defaultPadding;
|
|
1866
1910
|
const animated = options.animated === undefined || options.animated;
|
|
1867
1911
|
const durationMs = animated ? 1000 : 0;
|
|
1868
1912
|
// ensure padding is an object and assign default values
|
|
1869
|
-
const {
|
|
1870
|
-
const
|
|
1913
|
+
const { bottom = defaultPadding, left = defaultPadding, right = defaultPadding, top = defaultPadding } = typeof padding === 'object' ? padding : { top: padding, left: padding, bottom: padding, right: padding };
|
|
1914
|
+
const cameraForBounds = this._mapboxMapInstance.cameraForCoordinates(java.util.Arrays.asList([
|
|
1915
|
+
com.mapbox.geojson.Point.fromLngLat(options.bounds.west, options.bounds.north),
|
|
1916
|
+
com.mapbox.geojson.Point.fromLngLat(options.bounds.east, options.bounds.south)
|
|
1917
|
+
]), new com.mapbox.maps.EdgeInsets(top, left, bottom, right), java.lang.Double.valueOf(0), // bearing
|
|
1918
|
+
java.lang.Double.valueOf(0) // pitch
|
|
1919
|
+
);
|
|
1920
|
+
const cameraOptionsBuilder = new com.mapbox.maps.CameraOptions.Builder();
|
|
1921
|
+
cameraOptionsBuilder.center(cameraForBounds.getCenter());
|
|
1922
|
+
cameraOptionsBuilder.zoom(cameraForBounds.getZoom());
|
|
1923
|
+
cameraOptionsBuilder.bearing(cameraForBounds.getBearing());
|
|
1924
|
+
cameraOptionsBuilder.pitch(cameraForBounds.getPitch());
|
|
1925
|
+
const cameraOptions = cameraOptionsBuilder.build();
|
|
1871
1926
|
if (animated) {
|
|
1872
|
-
|
|
1927
|
+
com.nativescript.mapbox.Camera.flyTo(this._mapboxViewInstance, cameraOptions, new com.mapbox.maps.plugin.animation.MapAnimationOptions.Builder().duration(durationMs).build(), null);
|
|
1873
1928
|
}
|
|
1874
1929
|
else {
|
|
1875
|
-
this._mapboxMapInstance.
|
|
1930
|
+
this._mapboxMapInstance.setCamera(cameraOptions);
|
|
1876
1931
|
}
|
|
1877
1932
|
setTimeout(() => {
|
|
1878
1933
|
resolve();
|
|
@@ -1889,65 +1944,84 @@ export class Mapbox extends MapboxCommon {
|
|
|
1889
1944
|
downloadOfflineRegion(options) {
|
|
1890
1945
|
return new Promise((resolve, reject) => {
|
|
1891
1946
|
try {
|
|
1892
|
-
const styleURL = this._getMapStyle(options.style);
|
|
1893
|
-
const bounds = new com.mapbox.mapboxsdk.geometry.LatLngBounds.Builder()
|
|
1894
|
-
.include(new com.mapbox.mapboxsdk.geometry.LatLng(options.bounds.north, options.bounds.east))
|
|
1895
|
-
.include(new com.mapbox.mapboxsdk.geometry.LatLng(options.bounds.south, options.bounds.west))
|
|
1896
|
-
.build();
|
|
1897
|
-
const retinaFactor = Utils.layout.getDisplayDensity();
|
|
1898
|
-
const offlineRegionDefinition = new com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition(styleURL, bounds, options.minZoom, options.maxZoom, retinaFactor);
|
|
1899
|
-
const info = {
|
|
1900
|
-
name: options.name,
|
|
1901
|
-
...options.metadata
|
|
1902
|
-
};
|
|
1903
|
-
const infoStr = new java.lang.String(JSON.stringify(info));
|
|
1904
|
-
const encodedMetadata = infoStr.getBytes();
|
|
1905
1947
|
if (!this._accessToken && !options.accessToken) {
|
|
1906
1948
|
reject("First show a map, or pass in an 'accessToken' param");
|
|
1907
1949
|
return;
|
|
1908
1950
|
}
|
|
1909
1951
|
if (!this._accessToken) {
|
|
1910
1952
|
this._accessToken = options.accessToken;
|
|
1911
|
-
com.mapbox.
|
|
1953
|
+
com.mapbox.common.MapboxOptions.setAccessToken(this._accessToken);
|
|
1912
1954
|
}
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1955
|
+
const styleURL = this._getMapStyle(options.style);
|
|
1956
|
+
const regionId = `${options.regionId || Date.now()}`;
|
|
1957
|
+
// Optional: download style pack (the style JSON, sprites, fonts)
|
|
1958
|
+
// const stylePackLoadOptions = new com.mapbox.maps.StylePackLoadOptions.Builder().metadata(Value.fromJson(`{"regionId": "${options.regionId || Date.now()}"}`)).build();
|
|
1959
|
+
const descriptorOptionsBuilder = new com.mapbox.maps.TilesetDescriptorOptions.Builder().styleURI(styleURL);
|
|
1960
|
+
if (options.minZoom !== undefined) {
|
|
1961
|
+
descriptorOptionsBuilder.minZoom(options.minZoom);
|
|
1962
|
+
}
|
|
1963
|
+
if (options.maxZoom !== undefined) {
|
|
1964
|
+
descriptorOptionsBuilder.maxZoom(options.maxZoom);
|
|
1965
|
+
}
|
|
1966
|
+
const descriptorOptions = descriptorOptionsBuilder.build();
|
|
1967
|
+
const tilesetDescriptor = this._getOfflineManager().createTilesetDescriptor(descriptorOptions);
|
|
1968
|
+
const Point = com.mapbox.geojson.Point;
|
|
1969
|
+
const bbox = com.mapbox.geojson.Polygon.fromLngLats(java.util.Arrays.asList([
|
|
1970
|
+
java.util.Arrays.asList([
|
|
1971
|
+
Point.fromLngLat(options.bounds.west, options.bounds.south), // SW
|
|
1972
|
+
Point.fromLngLat(options.bounds.east, options.bounds.south), // SE
|
|
1973
|
+
Point.fromLngLat(options.bounds.east, options.bounds.north), // NE
|
|
1974
|
+
Point.fromLngLat(options.bounds.west, options.bounds.north), // NW
|
|
1975
|
+
Point.fromLngLat(options.bounds.west, options.bounds.south) // close ring
|
|
1976
|
+
])
|
|
1977
|
+
]));
|
|
1978
|
+
const info = {
|
|
1979
|
+
name: options.name,
|
|
1980
|
+
regionId,
|
|
1981
|
+
styleUrl: styleURL,
|
|
1982
|
+
minZoom: options.minZoom,
|
|
1983
|
+
maxZoom: options.maxZoom,
|
|
1984
|
+
bounds: options.bounds,
|
|
1985
|
+
...options.metadata
|
|
1986
|
+
};
|
|
1987
|
+
console.log('downloadRegion', regionId, new com.mapbox.bindgen.Value(JSON.stringify(info)));
|
|
1988
|
+
const regionOptions = new com.mapbox.common.TileRegionLoadOptions.Builder()
|
|
1989
|
+
.geometry(bbox)
|
|
1990
|
+
.descriptors(java.util.Collections.singletonList(tilesetDescriptor))
|
|
1991
|
+
.metadata(new com.mapbox.bindgen.Value(JSON.stringify(info)))
|
|
1992
|
+
.networkRestriction(options['networkRestriction'] ?? com.mapbox.common.NetworkRestriction.NONE)
|
|
1993
|
+
.acceptExpired(options['acceptExpired'] ?? true)
|
|
1994
|
+
.build();
|
|
1995
|
+
this._getTileStore().loadTileRegion(regionId, regionOptions, new com.mapbox.common.TileRegionLoadProgressCallback({
|
|
1996
|
+
run(progress) {
|
|
1997
|
+
const percentage = progress.getRequiredResourceCount() >= 0 ? (100.0 * progress.getCompletedResourceCount()) / progress.getRequiredResourceCount() : 0.0;
|
|
1998
|
+
if (options.onProgress) {
|
|
1999
|
+
options.onProgress({
|
|
2000
|
+
name: options.name,
|
|
2001
|
+
completedSize: progress.getCompletedResourceSize(),
|
|
2002
|
+
completed: progress.getCompletedResourceCount(),
|
|
2003
|
+
expected: progress.getRequiredResourceCount(),
|
|
2004
|
+
percentage: Math.round(percentage * 100) / 100,
|
|
2005
|
+
// downloading: status.getDownloadState() == com.mapbox.maps.offline.OfflineRegion.STATE_ACTIVE,
|
|
2006
|
+
complete: percentage === 1
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
}), new com.mapbox.common.TileRegionCallback({
|
|
2011
|
+
run(expected) {
|
|
2012
|
+
if (expected.isValue()) {
|
|
2013
|
+
// if (options.onProgress) {
|
|
2014
|
+
// options.onProgress({
|
|
2015
|
+
// name: options.name,
|
|
2016
|
+
// percentage: 100,
|
|
2017
|
+
// complete: true
|
|
2018
|
+
// });
|
|
2019
|
+
// }
|
|
2020
|
+
resolve(expected.getValue());
|
|
2021
|
+
}
|
|
2022
|
+
else {
|
|
2023
|
+
reject(expected.getError());
|
|
2024
|
+
}
|
|
1951
2025
|
}
|
|
1952
2026
|
}));
|
|
1953
2027
|
}
|
|
@@ -1968,40 +2042,42 @@ export class Mapbox extends MapboxCommon {
|
|
|
1968
2042
|
}
|
|
1969
2043
|
if (!this._accessToken) {
|
|
1970
2044
|
this._accessToken = options.accessToken;
|
|
1971
|
-
com.mapbox.
|
|
2045
|
+
com.mapbox.common.MapboxOptions.setAccessToken(this._accessToken);
|
|
1972
2046
|
}
|
|
1973
|
-
this.
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
const
|
|
1982
|
-
const
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2047
|
+
const tileStore = this._getTileStore();
|
|
2048
|
+
tileStore.getAllTileRegions(new com.mapbox.common.TileRegionsCallback({
|
|
2049
|
+
run: async (result) => {
|
|
2050
|
+
try {
|
|
2051
|
+
if (result.isError()) {
|
|
2052
|
+
reject(result.isError());
|
|
2053
|
+
}
|
|
2054
|
+
else {
|
|
2055
|
+
const offlineRegions = result.getValue();
|
|
2056
|
+
const regions = [];
|
|
2057
|
+
if (offlineRegions !== null) {
|
|
2058
|
+
for (let i = 0; i < offlineRegions.size(); i++) {
|
|
2059
|
+
const offlineRegion = offlineRegions.get(i);
|
|
2060
|
+
// const bounds = offlineRegionDefinition.getBounds();
|
|
2061
|
+
const { bounds, maxZoom, minZoom, name, regionId, styleUrl, ...metadata } = await this._getRegionMetadata(offlineRegion);
|
|
2062
|
+
regions.push({
|
|
2063
|
+
id: regionId,
|
|
2064
|
+
name,
|
|
2065
|
+
style: styleUrl,
|
|
2066
|
+
minZoom,
|
|
2067
|
+
maxZoom,
|
|
2068
|
+
bounds,
|
|
2069
|
+
metadata
|
|
2070
|
+
// pixelRatio: offlineRegionDefinition.getPixelRatio(),
|
|
2071
|
+
// type: offlineRegionDefinition.getType()
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
resolve(regions);
|
|
2002
2076
|
}
|
|
2003
2077
|
}
|
|
2004
|
-
|
|
2078
|
+
catch (error) {
|
|
2079
|
+
reject(error);
|
|
2080
|
+
}
|
|
2005
2081
|
}
|
|
2006
2082
|
}));
|
|
2007
2083
|
}
|
|
@@ -2020,34 +2096,48 @@ export class Mapbox extends MapboxCommon {
|
|
|
2020
2096
|
reject("Pass in the 'id' or 'name' param");
|
|
2021
2097
|
return;
|
|
2022
2098
|
}
|
|
2023
|
-
this.
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2099
|
+
const tileStore = this._getTileStore();
|
|
2100
|
+
tileStore.getAllTileRegions(new com.mapbox.common.TileRegionsCallback({
|
|
2101
|
+
run: async (result) => {
|
|
2102
|
+
try {
|
|
2103
|
+
if (result.isError()) {
|
|
2104
|
+
reject(result.isError());
|
|
2105
|
+
}
|
|
2106
|
+
else {
|
|
2107
|
+
const offlineRegions = result.getValue();
|
|
2108
|
+
let found = false;
|
|
2109
|
+
if (offlineRegions !== null) {
|
|
2110
|
+
for (let i = 0; i < offlineRegions.size(); i++) {
|
|
2111
|
+
const offlineRegion = offlineRegions.get(i);
|
|
2112
|
+
const regionId = options.id ? offlineRegion.getId() : await this._getRegionName(offlineRegion);
|
|
2113
|
+
if (regionId === (options.id || options.name)) {
|
|
2114
|
+
found = true;
|
|
2115
|
+
await new Promise((resolve, reject) => {
|
|
2116
|
+
tileStore.removeTileRegion(offlineRegion.getId(), new com.mapbox.common.TileRegionCallback({
|
|
2117
|
+
run(result) {
|
|
2118
|
+
if (result.isError()) {
|
|
2119
|
+
reject(result.getError());
|
|
2120
|
+
}
|
|
2121
|
+
else {
|
|
2122
|
+
resolve();
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
}));
|
|
2126
|
+
});
|
|
2127
|
+
// don't break the loop as there may be multiple packs with the same name
|
|
2043
2128
|
}
|
|
2044
|
-
}
|
|
2045
|
-
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
if (!found) {
|
|
2132
|
+
reject('Region not found');
|
|
2133
|
+
}
|
|
2134
|
+
else {
|
|
2135
|
+
resolve();
|
|
2046
2136
|
}
|
|
2047
2137
|
}
|
|
2048
2138
|
}
|
|
2049
|
-
|
|
2050
|
-
reject(
|
|
2139
|
+
catch (error) {
|
|
2140
|
+
reject(error);
|
|
2051
2141
|
}
|
|
2052
2142
|
}
|
|
2053
2143
|
}));
|
|
@@ -2062,25 +2152,32 @@ export class Mapbox extends MapboxCommon {
|
|
|
2062
2152
|
}
|
|
2063
2153
|
_getOfflineManager() {
|
|
2064
2154
|
if (!this._offlineManager) {
|
|
2065
|
-
this._offlineManager = com.mapbox.
|
|
2155
|
+
this._offlineManager = new com.mapbox.maps.OfflineManager();
|
|
2066
2156
|
}
|
|
2067
2157
|
return this._offlineManager;
|
|
2068
2158
|
}
|
|
2159
|
+
_getTileStore() {
|
|
2160
|
+
if (!this._tileStore) {
|
|
2161
|
+
this._tileStore = com.mapbox.common.TileStore.create();
|
|
2162
|
+
}
|
|
2163
|
+
return this._tileStore;
|
|
2164
|
+
}
|
|
2069
2165
|
addExtrusion(options, nativeMap) {
|
|
2070
2166
|
return new Promise((resolve, reject) => {
|
|
2071
2167
|
try {
|
|
2072
2168
|
// Create fill extrusion layer
|
|
2073
|
-
const fillExtrusionLayer = new com.mapbox.
|
|
2074
|
-
fillExtrusionLayer.
|
|
2075
|
-
fillExtrusionLayer.
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2169
|
+
const fillExtrusionLayer = new com.mapbox.maps.extension.style.layers.generated.FillExtrusionLayer('3d-buildings', 'composite');
|
|
2170
|
+
fillExtrusionLayer.sourceLayer('building');
|
|
2171
|
+
fillExtrusionLayer.minZoom(15);
|
|
2172
|
+
LayerFactory.applyLayerProperties(fillExtrusionLayer, {
|
|
2173
|
+
'fill-extrusion-color': android.graphics.Color.LTGRAY,
|
|
2174
|
+
'fill-extrusion-height': '["get", "height]',
|
|
2175
|
+
'fill-extrusion-base': '["get", "min_height]',
|
|
2176
|
+
'fill-extrusion-opacity': 0.6,
|
|
2177
|
+
filter: '["==", ["get", "extrude"], true]'
|
|
2178
|
+
});
|
|
2179
|
+
// TODO: missing extension typings
|
|
2180
|
+
//@ts-ignore
|
|
2084
2181
|
this._mapboxMapInstance.getStyle().addLayer(fillExtrusionLayer);
|
|
2085
2182
|
resolve();
|
|
2086
2183
|
}
|
|
@@ -2104,7 +2201,7 @@ export class Mapbox extends MapboxCommon {
|
|
|
2104
2201
|
reject('No map has been loaded');
|
|
2105
2202
|
return;
|
|
2106
2203
|
}
|
|
2107
|
-
const source =
|
|
2204
|
+
const source = this.getSource(id, theMap);
|
|
2108
2205
|
if (!source) {
|
|
2109
2206
|
reject('Source does not exists: ' + id);
|
|
2110
2207
|
return;
|
|
@@ -2112,7 +2209,7 @@ export class Mapbox extends MapboxCommon {
|
|
|
2112
2209
|
switch (options.type) {
|
|
2113
2210
|
case 'geojson':
|
|
2114
2211
|
const geoJsonString = JSON.stringify(options.data);
|
|
2115
|
-
source.
|
|
2212
|
+
source.data(geoJsonString);
|
|
2116
2213
|
resolve();
|
|
2117
2214
|
break;
|
|
2118
2215
|
default:
|
|
@@ -2145,33 +2242,39 @@ export class Mapbox extends MapboxCommon {
|
|
|
2145
2242
|
reject('No map has been loaded');
|
|
2146
2243
|
return;
|
|
2147
2244
|
}
|
|
2148
|
-
if (
|
|
2245
|
+
if (this.getSource(id, theMap)) {
|
|
2149
2246
|
reject('Source exists: ' + id);
|
|
2150
2247
|
return;
|
|
2151
2248
|
}
|
|
2152
2249
|
switch (options.type) {
|
|
2153
2250
|
case 'vector': {
|
|
2251
|
+
const builder = new com.mapbox.maps.extension.style.sources.generated.VectorSource.Builder(id);
|
|
2154
2252
|
if (options.url) {
|
|
2155
|
-
|
|
2253
|
+
builder.url(options.url);
|
|
2156
2254
|
}
|
|
2157
2255
|
else {
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2256
|
+
builder.tiles(java.util.Arrays.asList(options.tiles));
|
|
2257
|
+
}
|
|
2258
|
+
if (options.minzoom) {
|
|
2259
|
+
builder.minzoom(options.minzoom);
|
|
2260
|
+
}
|
|
2261
|
+
if (options.maxzoom) {
|
|
2262
|
+
builder.maxzoom(options.maxzoom);
|
|
2263
|
+
}
|
|
2264
|
+
if (options.scheme) {
|
|
2265
|
+
switch (options.scheme) {
|
|
2266
|
+
case 'tms':
|
|
2267
|
+
builder.scheme(com.mapbox.maps.extension.style.sources.generated.Scheme.TMS);
|
|
2268
|
+
break;
|
|
2269
|
+
default:
|
|
2270
|
+
builder.scheme(com.mapbox.maps.extension.style.sources.generated.Scheme.XYZ);
|
|
2271
|
+
break;
|
|
2172
2272
|
}
|
|
2173
|
-
source = new com.mapbox.mapboxsdk.style.sources.VectorSource(id, tileSet);
|
|
2174
2273
|
}
|
|
2274
|
+
if (options.bounds) {
|
|
2275
|
+
builder.bounds(java.util.Arrays.asList(options.bounds.map((val) => java.lang.Float.valueOf(val))));
|
|
2276
|
+
}
|
|
2277
|
+
source = builder.build();
|
|
2175
2278
|
break;
|
|
2176
2279
|
}
|
|
2177
2280
|
case 'geojson': {
|
|
@@ -2179,21 +2282,21 @@ export class Mapbox extends MapboxCommon {
|
|
|
2179
2282
|
CLog(CLogTypes.info, 'Mapbox:addSource(): before addSource with geojson');
|
|
2180
2283
|
CLog(CLogTypes.info, 'Mapbox:addSource(): before adding geoJSON to GeoJsonSource');
|
|
2181
2284
|
}
|
|
2182
|
-
|
|
2183
|
-
if (options.minzoom) {
|
|
2184
|
-
|
|
2185
|
-
}
|
|
2285
|
+
let builder = new com.mapbox.maps.extension.style.sources.generated.GeoJsonSource.Builder(id);
|
|
2286
|
+
// if (options.minzoom) {
|
|
2287
|
+
// builder.minzoom(options.minzoom);
|
|
2288
|
+
// }
|
|
2186
2289
|
if (options.maxzoom) {
|
|
2187
|
-
|
|
2290
|
+
builder.maxzoom(options.maxzoom);
|
|
2188
2291
|
}
|
|
2189
2292
|
if (options.lineMetrics !== undefined) {
|
|
2190
|
-
|
|
2293
|
+
builder.lineMetrics(options.lineMetrics);
|
|
2191
2294
|
}
|
|
2192
2295
|
if (options.cluster) {
|
|
2193
|
-
|
|
2194
|
-
.
|
|
2195
|
-
.
|
|
2196
|
-
.
|
|
2296
|
+
builder = builder
|
|
2297
|
+
.cluster(true)
|
|
2298
|
+
.clusterMaxZoom(options.cluster.maxZoom || 13)
|
|
2299
|
+
.clusterRadius(options.cluster.radius || 40);
|
|
2197
2300
|
if (options.cluster.properties) {
|
|
2198
2301
|
for (const property of Object.keys(options.cluster.properties)) {
|
|
2199
2302
|
const propertyValues = options.cluster.properties[property];
|
|
@@ -2201,36 +2304,42 @@ export class Mapbox extends MapboxCommon {
|
|
|
2201
2304
|
if (!Array.isArray(operator)) {
|
|
2202
2305
|
operator = [operator];
|
|
2203
2306
|
}
|
|
2204
|
-
|
|
2307
|
+
builder.clusterProperty(property, ExpressionParser.parseJson(operator), ExpressionParser.parseJson(propertyValues[1]));
|
|
2205
2308
|
}
|
|
2206
2309
|
}
|
|
2207
2310
|
}
|
|
2208
|
-
const geoJsonSource = new com.mapbox.mapboxsdk.style.sources.GeoJsonSource(id, geojsonOptions);
|
|
2209
2311
|
if (options.data) {
|
|
2210
2312
|
const geoJsonString = JSON.stringify(options.data);
|
|
2211
|
-
|
|
2313
|
+
builder.data(geoJsonString);
|
|
2212
2314
|
}
|
|
2315
|
+
const geoJsonSource = builder.build();
|
|
2213
2316
|
source = geoJsonSource;
|
|
2214
2317
|
break;
|
|
2215
2318
|
}
|
|
2216
2319
|
case 'raster':
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
options.tiles.forEach((val, i) => (tiles[i] = val));
|
|
2220
|
-
const tileSet = new com.mapbox.mapboxsdk.style.sources.TileSet('2.0.0', tiles);
|
|
2320
|
+
const builder = new com.mapbox.maps.extension.style.sources.generated.RasterSource.Builder(id);
|
|
2321
|
+
builder.tiles(java.util.Arrays.asList(options.tiles));
|
|
2221
2322
|
if (options.minzoom) {
|
|
2222
|
-
|
|
2323
|
+
builder.minzoom(options.minzoom);
|
|
2223
2324
|
}
|
|
2224
2325
|
if (options.maxzoom) {
|
|
2225
|
-
|
|
2326
|
+
builder.maxzoom(options.maxzoom);
|
|
2226
2327
|
}
|
|
2227
2328
|
if (options.scheme) {
|
|
2228
|
-
|
|
2329
|
+
switch (options.scheme) {
|
|
2330
|
+
case 'tms':
|
|
2331
|
+
builder.scheme(com.mapbox.maps.extension.style.sources.generated.Scheme.TMS);
|
|
2332
|
+
break;
|
|
2333
|
+
default:
|
|
2334
|
+
builder.scheme(com.mapbox.maps.extension.style.sources.generated.Scheme.XYZ);
|
|
2335
|
+
break;
|
|
2336
|
+
}
|
|
2229
2337
|
}
|
|
2230
2338
|
if (options.bounds) {
|
|
2231
|
-
|
|
2339
|
+
builder.bounds(java.util.Arrays.asList(options.bounds.map((val) => java.lang.Float.valueOf(val))));
|
|
2232
2340
|
}
|
|
2233
|
-
|
|
2341
|
+
builder.tileSize(options.tileSize || 256);
|
|
2342
|
+
source = builder.build();
|
|
2234
2343
|
break;
|
|
2235
2344
|
default:
|
|
2236
2345
|
reject('Invalid source type: ' + options['type']);
|
|
@@ -2244,6 +2353,8 @@ export class Mapbox extends MapboxCommon {
|
|
|
2244
2353
|
reject(ex);
|
|
2245
2354
|
return;
|
|
2246
2355
|
}
|
|
2356
|
+
// TODO: missing extension typings
|
|
2357
|
+
//@ts-ignore
|
|
2247
2358
|
theMap.getStyle().addSource(source);
|
|
2248
2359
|
resolve();
|
|
2249
2360
|
}
|
|
@@ -2294,7 +2405,7 @@ export class Mapbox extends MapboxCommon {
|
|
|
2294
2405
|
* - only a subset of paint properties are available.
|
|
2295
2406
|
*
|
|
2296
2407
|
* @param {object} style - a style following the Mapbox style specification.
|
|
2297
|
-
* @param {any} nativeMapView - native map view (com.mapbox.
|
|
2408
|
+
* @param {any} nativeMapView - native map view (com.mapbox.maps.MapView)
|
|
2298
2409
|
*
|
|
2299
2410
|
* @link https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers
|
|
2300
2411
|
*/
|
|
@@ -2304,19 +2415,25 @@ export class Mapbox extends MapboxCommon {
|
|
|
2304
2415
|
return Promise.reject('No map has been loaded');
|
|
2305
2416
|
}
|
|
2306
2417
|
let source = null;
|
|
2307
|
-
if (typeof style.source
|
|
2418
|
+
if (typeof style.source !== 'string') {
|
|
2308
2419
|
await this.addSource(style.id + '_source', style.source);
|
|
2309
|
-
source =
|
|
2420
|
+
source = this.getSource(style.id + '_source', theMap);
|
|
2310
2421
|
}
|
|
2311
2422
|
else {
|
|
2312
|
-
source =
|
|
2423
|
+
source = this.getSource(style.source, theMap);
|
|
2313
2424
|
}
|
|
2314
2425
|
const layer = await LayerFactory.createLayer(style, source);
|
|
2426
|
+
console.log('addLayer', layer.getNativeInstance());
|
|
2315
2427
|
if (belowLayerId) {
|
|
2428
|
+
// TODO: missing extension typings
|
|
2429
|
+
//@ts-ignore
|
|
2316
2430
|
this._mapboxMapInstance.getStyle().addLayerBelow(layer.getNativeInstance(), belowLayerId);
|
|
2317
|
-
return;
|
|
2318
2431
|
}
|
|
2319
|
-
|
|
2432
|
+
else {
|
|
2433
|
+
// TODO: missing extension typings
|
|
2434
|
+
//@ts-ignore
|
|
2435
|
+
this._mapboxMapInstance.getStyle().addLayer(layer.getNativeInstance());
|
|
2436
|
+
}
|
|
2320
2437
|
}
|
|
2321
2438
|
/**
|
|
2322
2439
|
* remove layer by ID
|
|
@@ -2332,6 +2449,11 @@ export class Mapbox extends MapboxCommon {
|
|
|
2332
2449
|
CLog(CLogTypes.info, 'Mapbox:removeLayer(): after removing layer');
|
|
2333
2450
|
}
|
|
2334
2451
|
}
|
|
2452
|
+
getSource(sId, mapboxInstance = this._mapboxMapInstance) {
|
|
2453
|
+
// TODO: missing extension typings
|
|
2454
|
+
//@ts-ignore
|
|
2455
|
+
return mapboxInstance.getStyle().getSource(sId);
|
|
2456
|
+
}
|
|
2335
2457
|
/**
|
|
2336
2458
|
* @deprecated
|
|
2337
2459
|
* Add a point to a line
|
|
@@ -2346,33 +2468,52 @@ export class Mapbox extends MapboxCommon {
|
|
|
2346
2468
|
* @link https://docs.oracle.com/javase/8/docs/api/java/util/List.html
|
|
2347
2469
|
*/
|
|
2348
2470
|
async addLinePoint(id, lnglat, sourceId, nativeMapView) {
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2471
|
+
return new Promise((resolve, reject) => {
|
|
2472
|
+
try {
|
|
2473
|
+
const sId = !!sourceId ? sourceId : id + '_source';
|
|
2474
|
+
const lineSource = this.getSource(sId);
|
|
2475
|
+
if (!lineSource) {
|
|
2476
|
+
throw new Error(`no source found with id: ${sId}`);
|
|
2477
|
+
}
|
|
2478
|
+
this._mapboxMapInstance.querySourceFeatures(sId, new com.mapbox.maps.SourceQueryOptions(null, // source layer IDs
|
|
2479
|
+
ExpressionParser.parseJson(['==', '$type', 'LineString'])), new com.mapbox.maps.QuerySourceFeaturesCallback({
|
|
2480
|
+
run(result) {
|
|
2481
|
+
if (result.isError()) {
|
|
2482
|
+
reject(new Error(result.getError()));
|
|
2483
|
+
}
|
|
2484
|
+
else {
|
|
2485
|
+
const lineFeatures = result.getValue();
|
|
2486
|
+
if (lineFeatures.size() === 0) {
|
|
2487
|
+
reject(new Error('no line string feature found'));
|
|
2488
|
+
}
|
|
2489
|
+
else {
|
|
2490
|
+
const feature = lineFeatures.get(0).getQueriedFeature().getFeature();
|
|
2491
|
+
const newPoints = new java.util.ArrayList(feature.geometry().coordinates());
|
|
2492
|
+
newPoints.add(com.mapbox.geojson.Point.fromLngLat(lnglat[0], lnglat[1]));
|
|
2493
|
+
const newFeature = com.mapbox.geojson.LineString.fromLngLats(newPoints);
|
|
2494
|
+
lineSource.geometry(newFeature);
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
}));
|
|
2354
2499
|
}
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
throw new Error('no line string feature found');
|
|
2500
|
+
catch (error) {
|
|
2501
|
+
reject(error);
|
|
2358
2502
|
}
|
|
2359
|
-
|
|
2360
|
-
const newPoints = new java.util.ArrayList(feature.geometry().coordinates());
|
|
2361
|
-
newPoints.add(com.mapbox.geojson.Point.fromLngLat(lnglat[0], lnglat[1]));
|
|
2362
|
-
const newFeature = com.mapbox.geojson.LineString.fromLngLats(newPoints);
|
|
2363
|
-
lineSource.setGeoJson(newFeature);
|
|
2364
|
-
}
|
|
2365
|
-
catch (error) {
|
|
2366
|
-
return error;
|
|
2367
|
-
}
|
|
2503
|
+
});
|
|
2368
2504
|
}
|
|
2369
2505
|
addGeoJsonClustered(options, nativeMap) {
|
|
2370
2506
|
return new Promise((resolve, reject) => {
|
|
2371
2507
|
try {
|
|
2372
|
-
|
|
2373
|
-
.
|
|
2374
|
-
.
|
|
2375
|
-
.
|
|
2508
|
+
const geoJsonSource = new com.mapbox.maps.extension.style.sources.generated.GeoJsonSource.Builder(options.name)
|
|
2509
|
+
.data(options.data)
|
|
2510
|
+
.cluster(true) // enable clustering
|
|
2511
|
+
.clusterMaxZoom(options.clusterMaxZoom || 13) // maximum zoom to cluster points
|
|
2512
|
+
.clusterRadius(options.clusterRadius || 40) // radius of each cluster in pixels
|
|
2513
|
+
.build();
|
|
2514
|
+
// TODO: missing extension typings
|
|
2515
|
+
//@ts-ignore
|
|
2516
|
+
this._mapboxMapInstance.getStyle().addSource(geoJsonSource);
|
|
2376
2517
|
const layers = [];
|
|
2377
2518
|
if (options.clusters) {
|
|
2378
2519
|
for (let i = 0; i < options.clusters.length; i++) {
|
|
@@ -2385,42 +2526,58 @@ export class Mapbox extends MapboxCommon {
|
|
|
2385
2526
|
layers.push([20, new Color('green').android]);
|
|
2386
2527
|
layers.push([0, new Color('blue').android]);
|
|
2387
2528
|
}
|
|
2388
|
-
const unclustered = new com.mapbox.
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2529
|
+
const unclustered = new com.mapbox.maps.extension.style.layers.generated.SymbolLayer('unclustered-points', options.name);
|
|
2530
|
+
LayerFactory.applyLayerProperties(unclustered, {
|
|
2531
|
+
'circle-color': 'red',
|
|
2532
|
+
'circle-radius': 16,
|
|
2533
|
+
'circle-blur': 0.2,
|
|
2534
|
+
filter: `["!=", ["get", "cluster"], true]`
|
|
2535
|
+
});
|
|
2536
|
+
// unclustered.setFilter(com.mapbox.maps.style.expressions.Expression.neq(com.mapbox.maps.style.expressions.Expression.get('cluster'), true));
|
|
2537
|
+
// TODO: missing extension typings
|
|
2538
|
+
//@ts-ignore
|
|
2395
2539
|
this._mapboxMapInstance.getStyle().addLayer(unclustered); // , "building");
|
|
2396
2540
|
for (let i = 0; i < layers.length; i++) {
|
|
2397
2541
|
// Add some nice circles
|
|
2398
|
-
const circles = new com.mapbox.
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
]);
|
|
2405
|
-
const pointCount = com.mapbox.mapboxsdk.style.expressions.Expression.toNumber(com.mapbox.mapboxsdk.style.expressions.Expression.get('point_count'));
|
|
2542
|
+
const circles = new com.mapbox.maps.extension.style.layers.generated.CircleLayer('cluster-' + i, options.name);
|
|
2543
|
+
const properties = {
|
|
2544
|
+
'circle-color': layers[i][1],
|
|
2545
|
+
'circle-radius': 22,
|
|
2546
|
+
'circle-blur': 0.2
|
|
2547
|
+
};
|
|
2406
2548
|
if (i === 0) {
|
|
2407
|
-
|
|
2549
|
+
properties['filter'] = `[">=", ["get", "point_count"], ${layers[i][0]}]`;
|
|
2550
|
+
// circles.setFilter(com.mapbox.maps.style.expressions.Expression.gte(pointCount, com.mapbox.maps.style.expressions.Expression.literal(java.lang.Integer.valueOf(layers[i][0]))));
|
|
2408
2551
|
}
|
|
2409
2552
|
else {
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
]))
|
|
2553
|
+
properties['filter'] = `["all", [">=", ["get", "point_count"], ${layers[i][0]}], ["<", ["get", "point_count"], ${layers[i - 1][0]}]]`;
|
|
2554
|
+
// (
|
|
2555
|
+
// com.mapbox.maps.style.expressions.Expression.all([
|
|
2556
|
+
// com.mapbox.maps.style.expressions.Expression.gte(pointCount, com.mapbox.maps.style.expressions.Expression.literal(java.lang.Integer.valueOf(layers[i][0]))),
|
|
2557
|
+
// com.mapbox.maps.style.expressions.Expression.lt(pointCount, com.mapbox.maps.style.expressions.Expression.literal(java.lang.Integer.valueOf(layers[i - 1][0])))
|
|
2558
|
+
// ])
|
|
2559
|
+
// );
|
|
2414
2560
|
}
|
|
2561
|
+
LayerFactory.applyLayerProperties(circles, properties);
|
|
2562
|
+
// const pointCount = com.mapbox.maps.style.expressions.Expression.toNumber(com.mapbox.maps.style.expressions.Expression.get('point_count'));
|
|
2563
|
+
// TODO: missing extension typings
|
|
2564
|
+
//@ts-ignore
|
|
2415
2565
|
this._mapboxMapInstance.getStyle().addLayer(circles); // , "building");
|
|
2416
2566
|
}
|
|
2417
2567
|
// Add the count labels (note that this doesn't show.. #sad)
|
|
2418
|
-
const count = new com.mapbox.
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2568
|
+
const count = new com.mapbox.maps.extension.style.layers.generated.SymbolLayer('count', options.name);
|
|
2569
|
+
LayerFactory.applyLayerProperties(count, {
|
|
2570
|
+
'text-field': '["get", "point_count"]',
|
|
2571
|
+
'text-size': 12,
|
|
2572
|
+
'text-color': 'white'
|
|
2573
|
+
});
|
|
2574
|
+
// count.setProperties([
|
|
2575
|
+
// com.mapbox.maps.extension.style.layers.generated.PropertyFactory.textField(com.mapbox.maps.style.expressions.Expression.get('point_count')),
|
|
2576
|
+
// com.mapbox.maps.extension.style.layers.generated.PropertyFactory.textSize(new java.lang.Float(12.0)),
|
|
2577
|
+
// com.mapbox.maps.extension.style.layers.generated.PropertyFactory.textColor(new Color('white').android)
|
|
2578
|
+
// ]);
|
|
2579
|
+
// TODO: missing extension typings
|
|
2580
|
+
//@ts-ignore
|
|
2424
2581
|
this._mapboxMapInstance.getStyle().addLayer(count);
|
|
2425
2582
|
resolve();
|
|
2426
2583
|
}
|
|
@@ -2447,14 +2604,11 @@ export class Mapbox extends MapboxCommon {
|
|
|
2447
2604
|
}
|
|
2448
2605
|
this.requestFineLocationPermission()
|
|
2449
2606
|
.then(() => {
|
|
2450
|
-
if (this._locationComponent) {
|
|
2451
|
-
|
|
2452
|
-
}
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
useDefaultLocationEngine: true
|
|
2456
|
-
});
|
|
2457
|
-
}
|
|
2607
|
+
// if (this._locationComponent) {
|
|
2608
|
+
// this.changeUserLocationMarkerMode(options.renderMode || 'COMPASS', options.cameraMode || 'TRACKING');
|
|
2609
|
+
// } else {
|
|
2610
|
+
this.showUserLocationMarker(options);
|
|
2611
|
+
// }
|
|
2458
2612
|
})
|
|
2459
2613
|
.catch((err) => {
|
|
2460
2614
|
console.error('Location permission denied. error:', err);
|
|
@@ -2470,20 +2624,19 @@ export class Mapbox extends MapboxCommon {
|
|
|
2470
2624
|
});
|
|
2471
2625
|
}
|
|
2472
2626
|
static getAndroidColor(color) {
|
|
2473
|
-
|
|
2474
|
-
if (
|
|
2475
|
-
|
|
2627
|
+
const temp = color instanceof Color ? color : new Color(color);
|
|
2628
|
+
if (Color.isValid(temp)) {
|
|
2629
|
+
return temp.android;
|
|
2476
2630
|
}
|
|
2477
2631
|
else {
|
|
2478
|
-
|
|
2632
|
+
return android.graphics.Color.BLACK;
|
|
2479
2633
|
}
|
|
2480
|
-
return androidColor;
|
|
2481
2634
|
}
|
|
2482
2635
|
_getMapStyle(input) {
|
|
2483
2636
|
if (Trace.isEnabled()) {
|
|
2484
2637
|
CLog(CLogTypes.info, '_getMapStyle(): top with input:', input);
|
|
2485
2638
|
}
|
|
2486
|
-
const Style = com.mapbox.
|
|
2639
|
+
const Style = com.mapbox.maps.Style;
|
|
2487
2640
|
// allow for a style URL to be passed
|
|
2488
2641
|
if (input.startsWith('mapbox://styles') || input.startsWith('http://') || input.startsWith('https://')) {
|
|
2489
2642
|
return input;
|
|
@@ -2491,30 +2644,12 @@ export class Mapbox extends MapboxCommon {
|
|
|
2491
2644
|
else if (input.startsWith('~/')) {
|
|
2492
2645
|
return 'file://' + path.join(knownFolders.currentApp().path, input.replace('~/', ''));
|
|
2493
2646
|
}
|
|
2494
|
-
else if (input === MapStyle.LIGHT) {
|
|
2495
|
-
return Style.LIGHT;
|
|
2496
|
-
}
|
|
2497
|
-
else if (input === MapStyle.DARK) {
|
|
2498
|
-
return Style.DARK;
|
|
2499
|
-
}
|
|
2500
|
-
else if (input === MapStyle.OUTDOORS) {
|
|
2501
|
-
return Style.OUTDOORS;
|
|
2502
|
-
}
|
|
2503
|
-
else if (input === MapStyle.SATELLITE) {
|
|
2504
|
-
return Style.SATELLITE;
|
|
2505
|
-
}
|
|
2506
|
-
else if (input === MapStyle.SATELLITE_STREETS) {
|
|
2507
|
-
return Style.SATELLITE_STREETS;
|
|
2508
|
-
}
|
|
2509
|
-
else if (input === MapStyle.TRAFFIC_DAY) {
|
|
2510
|
-
return Style.TRAFFIC_DAY;
|
|
2511
|
-
}
|
|
2512
|
-
else if (input === MapStyle.TRAFFIC_NIGHT) {
|
|
2513
|
-
return Style.TRAFFIC_NIGHT;
|
|
2514
|
-
}
|
|
2515
2647
|
else {
|
|
2516
|
-
|
|
2517
|
-
|
|
2648
|
+
const key = Object.keys(MapStyle)[Object.values(MapStyle).indexOf(input)];
|
|
2649
|
+
// fix because MAPBOX_STREETS and others are not exposed by the
|
|
2650
|
+
const field = Style.class.getDeclaredField(key) || Style.class.getDeclaredField('MAPBOX_STREETS');
|
|
2651
|
+
field.setAccessible(true);
|
|
2652
|
+
return field.get(null);
|
|
2518
2653
|
}
|
|
2519
2654
|
}
|
|
2520
2655
|
/**
|
|
@@ -2524,18 +2659,8 @@ export class Mapbox extends MapboxCommon {
|
|
|
2524
2659
|
* @link https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
|
|
2525
2660
|
* @link https://docs.mapbox.com/android/api/map-sdk/7.1.2/com/mapbox/mapboxsdk/maps/MapboxMapOptions.html
|
|
2526
2661
|
*/
|
|
2527
|
-
_getMapboxMapOptions(settings) {
|
|
2528
|
-
const
|
|
2529
|
-
.compassEnabled(!settings.hideCompass)
|
|
2530
|
-
.compassGravity(Mapbox.mapPositionToGravity(settings.compassPosition))
|
|
2531
|
-
.rotateGesturesEnabled(!settings.disableRotation)
|
|
2532
|
-
.scrollGesturesEnabled(!settings.disableScroll)
|
|
2533
|
-
.tiltGesturesEnabled(!settings.disableTilt)
|
|
2534
|
-
.zoomGesturesEnabled(!settings.disableZoom)
|
|
2535
|
-
.attributionEnabled(!settings.hideAttribution)
|
|
2536
|
-
.attributionGravity(Mapbox.mapPositionToGravity(settings.attributionPosition))
|
|
2537
|
-
.logoEnabled(!settings.hideLogo)
|
|
2538
|
-
.logoGravity(Mapbox.mapPositionToGravity(settings.logoPosition));
|
|
2662
|
+
_getMapboxMapOptions(context, settings) {
|
|
2663
|
+
const mapOptions = new com.mapbox.maps.MapOptions.Builder().pixelRatio(context.getResources().getDisplayMetrics().density).build();
|
|
2539
2664
|
// zoomlevel is not applied unless center is set
|
|
2540
2665
|
if (settings.zoomLevel && !settings.center) {
|
|
2541
2666
|
// Eiffel tower, Paris
|
|
@@ -2544,13 +2669,15 @@ export class Mapbox extends MapboxCommon {
|
|
|
2544
2669
|
lng: 2.294694
|
|
2545
2670
|
};
|
|
2546
2671
|
}
|
|
2672
|
+
let initialCameraOptions;
|
|
2547
2673
|
if (settings.center && settings.center.lat && settings.center.lng) {
|
|
2548
|
-
|
|
2549
|
-
.zoom(settings.zoomLevel)
|
|
2550
|
-
.
|
|
2551
|
-
|
|
2674
|
+
initialCameraOptions = new com.mapbox.maps.CameraOptions.Builder()
|
|
2675
|
+
.zoom(java.lang.Double.valueOf(settings.zoomLevel))
|
|
2676
|
+
.center(com.mapbox.geojson.Point.fromLngLat(settings.center.lng, settings.center.lat))
|
|
2677
|
+
.build();
|
|
2552
2678
|
}
|
|
2553
|
-
|
|
2679
|
+
com.mapbox.common.MapboxOptions.setAccessToken(this._accessToken);
|
|
2680
|
+
return new com.mapbox.maps.MapInitOptions(context, mapOptions, com.mapbox.maps.MapInitOptions.Companion.getDefaultPluginList(), initialCameraOptions, false);
|
|
2554
2681
|
}
|
|
2555
2682
|
static mapPositionToGravity(position) {
|
|
2556
2683
|
switch (position) {
|
|
@@ -2569,86 +2696,102 @@ export class Mapbox extends MapboxCommon {
|
|
|
2569
2696
|
*
|
|
2570
2697
|
* @link https://docs.mapbox.com/android/api/map-sdk/8.1.0/com/mapbox/mapboxsdk/location/modes/CameraMode.html
|
|
2571
2698
|
*/
|
|
2572
|
-
_stringToCameraMode(mode) {
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
}
|
|
2591
|
-
/**
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
_stringToRenderMode(mode) {
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
}
|
|
2609
|
-
_convertCameraMode(mode) {
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
}
|
|
2699
|
+
// _stringToCameraMode(mode: UserLocationCameraMode): any {
|
|
2700
|
+
// const modeRef = com.mapbox.maps.location.modes.CameraMode;
|
|
2701
|
+
// switch (mode) {
|
|
2702
|
+
// case 'NONE':
|
|
2703
|
+
// return modeRef.NONE;
|
|
2704
|
+
// case 'NONE_COMPASS':
|
|
2705
|
+
// return modeRef.NONE_COMPASS;
|
|
2706
|
+
// case 'NONE_GPS':
|
|
2707
|
+
// return modeRef.NONE_GPS;
|
|
2708
|
+
// case 'TRACKING':
|
|
2709
|
+
// return modeRef.TRACKING;
|
|
2710
|
+
// case 'TRACKING_COMPASS':
|
|
2711
|
+
// return modeRef.TRACKING_COMPASS;
|
|
2712
|
+
// case 'TRACKING_GPS':
|
|
2713
|
+
// return modeRef.TRACKING_GPS;
|
|
2714
|
+
// case 'TRACKING_GPS_NORTH':
|
|
2715
|
+
// return modeRef.TRACKING_GPS_NORTH;
|
|
2716
|
+
// }
|
|
2717
|
+
// }
|
|
2718
|
+
// /**
|
|
2719
|
+
// * convert string to render mode
|
|
2720
|
+
// */
|
|
2721
|
+
// _stringToRenderMode(mode): any {
|
|
2722
|
+
// let renderMode: any;
|
|
2723
|
+
// switch (mode) {
|
|
2724
|
+
// case 'NORMAL':
|
|
2725
|
+
// renderMode = com.mapbox.maps.location.modes.RenderMode.NORMAL;
|
|
2726
|
+
// break;
|
|
2727
|
+
// case 'COMPASS':
|
|
2728
|
+
// renderMode = com.mapbox.maps.location.modes.RenderMode.COMPASS;
|
|
2729
|
+
// break;
|
|
2730
|
+
// case 'GPS':
|
|
2731
|
+
// renderMode = com.mapbox.maps.location.modes.RenderMode.GPS;
|
|
2732
|
+
// break;
|
|
2733
|
+
// }
|
|
2734
|
+
// return renderMode;
|
|
2735
|
+
// }
|
|
2736
|
+
// _convertCameraMode(mode: any): UserLocationCameraMode {
|
|
2737
|
+
// const modeRef = com.mapbox.maps.plugin.locationcomponent.camera.CameraMode;
|
|
2738
|
+
// switch (mode) {
|
|
2739
|
+
// case modeRef.NONE:
|
|
2740
|
+
// return 'NONE';
|
|
2741
|
+
// case modeRef.NONE_COMPASS:
|
|
2742
|
+
// return 'NONE_COMPASS';
|
|
2743
|
+
// case modeRef.NONE_GPS:
|
|
2744
|
+
// return 'NONE_GPS';
|
|
2745
|
+
// case modeRef.TRACKING:
|
|
2746
|
+
// return 'TRACKING';
|
|
2747
|
+
// case modeRef.TRACKING_COMPASS:
|
|
2748
|
+
// return 'TRACKING_COMPASS';
|
|
2749
|
+
// case modeRef.TRACKING_GPS:
|
|
2750
|
+
// return 'TRACKING_GPS';
|
|
2751
|
+
// case modeRef.TRACKING_GPS_NORTH:
|
|
2752
|
+
// return 'TRACKING_GPS_NORTH';
|
|
2753
|
+
// }
|
|
2754
|
+
// return 'NONE';
|
|
2755
|
+
// }
|
|
2629
2756
|
_fineLocationPermissionGranted() {
|
|
2630
2757
|
let hasPermission = android.os.Build.VERSION.SDK_INT < 23; // Android M. (6.0)
|
|
2631
2758
|
if (!hasPermission) {
|
|
2632
|
-
hasPermission = com.mapbox.android.core.permissions.PermissionsManager.areLocationPermissionsGranted(
|
|
2759
|
+
hasPermission = com.mapbox.android.core.permissions.PermissionsManager.areLocationPermissionsGranted(Utils.android.getApplicationContext());
|
|
2633
2760
|
}
|
|
2634
2761
|
return hasPermission;
|
|
2635
2762
|
}
|
|
2636
|
-
_getRegionName(offlineRegion) {
|
|
2637
|
-
|
|
2638
|
-
const jsonStr = new java.lang.String(metadata, 'UTF-8');
|
|
2639
|
-
const jsonObj = new org.json.JSONObject(jsonStr);
|
|
2640
|
-
try {
|
|
2641
|
-
return jsonObj.getString('name');
|
|
2642
|
-
}
|
|
2643
|
-
catch (error) {
|
|
2644
|
-
return '';
|
|
2645
|
-
}
|
|
2763
|
+
async _getRegionName(offlineRegion) {
|
|
2764
|
+
return (await this._getRegionMetadata(offlineRegion))?.name;
|
|
2646
2765
|
}
|
|
2647
2766
|
_getRegionMetadata(offlineRegion) {
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2767
|
+
return new Promise((resolve, reject) => {
|
|
2768
|
+
this._getTileStore().getTileRegionMetadata(offlineRegion.getId(), new com.mapbox.common.TileRegionMetadataCallback({
|
|
2769
|
+
run(result) {
|
|
2770
|
+
if (result.isError()) {
|
|
2771
|
+
reject(result.getError());
|
|
2772
|
+
}
|
|
2773
|
+
else {
|
|
2774
|
+
try {
|
|
2775
|
+
resolve(JSON.parse(result.getValue().toString() || '{}') || {});
|
|
2776
|
+
}
|
|
2777
|
+
catch (error) {
|
|
2778
|
+
resolve(JSON.parse(result.getValue().toJson() || '{}') || {});
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
}));
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
_getPlugin(pluginId) {
|
|
2786
|
+
if (this._plugins[pluginId]) {
|
|
2787
|
+
return this._plugins[pluginId];
|
|
2788
|
+
}
|
|
2789
|
+
const plugin = (this._plugins[pluginId] = this._mapboxViewInstance.getPlugin(pluginId));
|
|
2790
|
+
return plugin;
|
|
2791
|
+
}
|
|
2792
|
+
_getGesturesPlugin() {
|
|
2793
|
+
return this._getPlugin('MAPBOX_GESTURES_PLUGIN_ID');
|
|
2794
|
+
// return this._mapboxMapInstance.getGestures() as com.mapbox.maps.plugin.gestures.GesturesPlugin;
|
|
2652
2795
|
}
|
|
2653
2796
|
/**
|
|
2654
2797
|
* show a user location marker
|
|
@@ -2677,94 +2820,120 @@ export class Mapbox extends MapboxCommon {
|
|
|
2677
2820
|
*
|
|
2678
2821
|
* @todo at least with simulated data, the location is only updated once hence adding support for forceLocation method.
|
|
2679
2822
|
*/
|
|
2680
|
-
showUserLocationMarker(options, nativeMap) {
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
}
|
|
2690
|
-
if (!com.mapbox.android.core.permissions.PermissionsManager.areLocationPermissionsGranted(Application.android.context)) {
|
|
2691
|
-
if (Trace.isEnabled()) {
|
|
2692
|
-
CLog(CLogTypes.info, 'showUserLocationMarker(): location permissions are not granted.');
|
|
2693
|
-
}
|
|
2694
|
-
reject('Location permissions not granted.');
|
|
2695
|
-
return;
|
|
2696
|
-
}
|
|
2697
|
-
let componentOptionsBuilder = com.mapbox.mapboxsdk.location.LocationComponentOptions.builder(Application.android.context);
|
|
2698
|
-
if (typeof options.elevation != 'undefined') {
|
|
2699
|
-
componentOptionsBuilder = componentOptionsBuilder.elevation(options.elevation);
|
|
2700
|
-
}
|
|
2701
|
-
if (typeof options.accuracyColor != 'undefined') {
|
|
2702
|
-
componentOptionsBuilder = componentOptionsBuilder.accuracyColor(android.graphics.Color.parseColor(options.accuracyColor));
|
|
2703
|
-
}
|
|
2704
|
-
if (typeof options.accuracyAlpha != 'undefined') {
|
|
2705
|
-
componentOptionsBuilder = componentOptionsBuilder.accuracyAlpha(options.accuracyAlpha);
|
|
2706
|
-
}
|
|
2707
|
-
if (typeof options.foregroundTintColor != 'undefined') {
|
|
2708
|
-
const foregroundTintColor = new java.lang.Integer(android.graphics.Color.parseColor(options.foregroundTintColor));
|
|
2709
|
-
componentOptionsBuilder = componentOptionsBuilder.foregroundTintColor(foregroundTintColor);
|
|
2710
|
-
}
|
|
2711
|
-
if (typeof options.foregroundStaleTintColor != 'undefined') {
|
|
2712
|
-
const foregroundStaleTintColor = new java.lang.Integer(android.graphics.Color.parseColor(options.foregroundStaleTintColor));
|
|
2713
|
-
componentOptionsBuilder = componentOptionsBuilder.foregroundStaleTintColor(foregroundStaleTintColor);
|
|
2714
|
-
}
|
|
2715
|
-
if (typeof options.backgroundTintColor != 'undefined') {
|
|
2716
|
-
const backgroundTintColor = new java.lang.Integer(android.graphics.Color.parseColor(options.backgroundTintColor));
|
|
2717
|
-
componentOptionsBuilder = componentOptionsBuilder.backgroundTintColor(backgroundTintColor);
|
|
2718
|
-
}
|
|
2719
|
-
if (typeof options.bearingTintColor != 'undefined') {
|
|
2720
|
-
const bearingTintColor = new java.lang.Integer(android.graphics.Color.parseColor(options.bearingTintColor));
|
|
2721
|
-
componentOptionsBuilder = componentOptionsBuilder.bearingTintColor(bearingTintColor);
|
|
2722
|
-
}
|
|
2723
|
-
const componentOptions = componentOptionsBuilder.build();
|
|
2724
|
-
this._locationComponent = this._mapboxMapInstance.getLocationComponent();
|
|
2725
|
-
const activationOptionsBuilder = com.mapbox.mapboxsdk.location.LocationComponentActivationOptions.builder(Application.android.context, this._mapboxMapInstance.getStyle());
|
|
2726
|
-
activationOptionsBuilder.locationComponentOptions(componentOptions);
|
|
2727
|
-
let useDefaultEngine = true;
|
|
2728
|
-
if (typeof options.useDefaultLocationEngine != 'undefined') {
|
|
2729
|
-
useDefaultEngine = options.useDefaultLocationEngine;
|
|
2730
|
-
}
|
|
2731
|
-
activationOptionsBuilder.useDefaultLocationEngine(useDefaultEngine);
|
|
2732
|
-
const locationComponentActivationOptions = activationOptionsBuilder.build();
|
|
2733
|
-
this._locationComponent.activateLocationComponent(locationComponentActivationOptions);
|
|
2734
|
-
this._locationComponent.setLocationComponentEnabled(true);
|
|
2735
|
-
let cameraMode = this._stringToCameraMode('TRACKING');
|
|
2736
|
-
if (typeof options.cameraMode != 'undefined') {
|
|
2737
|
-
cameraMode = this._stringToCameraMode(options.cameraMode);
|
|
2738
|
-
}
|
|
2739
|
-
this._locationComponent.setCameraMode(cameraMode);
|
|
2740
|
-
let renderMode = com.mapbox.mapboxsdk.location.modes.RenderMode.COMPASS;
|
|
2741
|
-
if (typeof options.renderMode != 'undefined') {
|
|
2742
|
-
renderMode = this._stringToRenderMode(options.renderMode);
|
|
2743
|
-
}
|
|
2744
|
-
this._locationComponent.setRenderMode(renderMode);
|
|
2823
|
+
async showUserLocationMarker(options, nativeMap) {
|
|
2824
|
+
try {
|
|
2825
|
+
if (Trace.isEnabled()) {
|
|
2826
|
+
CLog(CLogTypes.info, 'showUserLocationMarker()');
|
|
2827
|
+
}
|
|
2828
|
+
if (!this._mapboxMapInstance) {
|
|
2829
|
+
throw new Error('No map has been loaded');
|
|
2830
|
+
}
|
|
2831
|
+
if (!com.mapbox.android.core.permissions.PermissionsManager.areLocationPermissionsGranted(Utils.android.getApplicationContext())) {
|
|
2745
2832
|
if (Trace.isEnabled()) {
|
|
2746
|
-
CLog(CLogTypes.info, 'showUserLocationMarker():
|
|
2747
|
-
}
|
|
2748
|
-
if (typeof options.clickListener != 'undefined') {
|
|
2749
|
-
this.onLocationClickListener = new com.mapbox.mapboxsdk.location.OnLocationClickListener({
|
|
2750
|
-
onLocationComponentClick: () => {
|
|
2751
|
-
options.clickListener();
|
|
2752
|
-
}
|
|
2753
|
-
});
|
|
2754
|
-
this._locationComponent.addOnLocationClickListener(this.onLocationClickListener);
|
|
2755
|
-
}
|
|
2756
|
-
if (typeof options.cameraTrackingChangedListener != 'undefined') {
|
|
2757
|
-
this._locationComponent.addOnCameraTrackingChangedListener(options.cameraTrackingChangedListener);
|
|
2833
|
+
CLog(CLogTypes.info, 'showUserLocationMarker(): location permissions are not granted.');
|
|
2758
2834
|
}
|
|
2759
|
-
|
|
2835
|
+
throw new Error('Location permissions not granted.');
|
|
2760
2836
|
}
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2837
|
+
const locationPlugin = this._getPlugin('MAPBOX_LOCATION_COMPONENT_PLUGIN_ID');
|
|
2838
|
+
if (this.onIndicatorPositionChangedListener) {
|
|
2839
|
+
locationPlugin.removeOnIndicatorPositionChangedListener(this.onIndicatorPositionChangedListener);
|
|
2840
|
+
}
|
|
2841
|
+
this.onIndicatorPositionChangedListener = new com.mapbox.maps.plugin.locationcomponent.OnIndicatorPositionChangedListener({
|
|
2842
|
+
onIndicatorPositionChanged: (point) => {
|
|
2843
|
+
this.lastKnownLocation = point;
|
|
2844
|
+
if (!options.cameraMode || options.cameraMode?.indexOf('TRACKING') !== -1) {
|
|
2845
|
+
this._mapboxMapInstance.setCamera(new com.mapbox.maps.CameraOptions.Builder().center(point).build());
|
|
2846
|
+
}
|
|
2764
2847
|
}
|
|
2765
|
-
|
|
2848
|
+
});
|
|
2849
|
+
locationPlugin.addOnIndicatorPositionChangedListener(this.onIndicatorPositionChangedListener);
|
|
2850
|
+
locationPlugin.updateSettings(
|
|
2851
|
+
//@ts-ignore
|
|
2852
|
+
new kotlin.jvm.functions.Function1({
|
|
2853
|
+
invoke: (settings) => {
|
|
2854
|
+
settings.setEnabled(true);
|
|
2855
|
+
settings.setPulsingEnabled(true);
|
|
2856
|
+
console.log('setPuckBearingEnabled', options.cameraMode, options.renderMode, options.renderMode !== 'NORMAL', com.mapbox.maps.plugin.PuckBearing.HEADING, com.mapbox.maps.plugin.PuckBearing.COURSE);
|
|
2857
|
+
settings.setLocationPuck(com.mapbox.maps.plugin.locationcomponent.LocationComponentUtils.createDefault2DPuck(true));
|
|
2858
|
+
settings.setPuckBearingEnabled(options.renderMode !== 'NORMAL');
|
|
2859
|
+
settings.setPuckBearing(options.cameraMode?.indexOf('COMPASS') !== -1 ? com.mapbox.maps.plugin.PuckBearing.HEADING : com.mapbox.maps.plugin.PuckBearing.COURSE);
|
|
2860
|
+
if (options.accuracyColor !== undefined) {
|
|
2861
|
+
settings.setAccuracyRingColor(Mapbox.getAndroidColor(options.accuracyColor));
|
|
2862
|
+
}
|
|
2863
|
+
if (options.accuracyRingColor !== undefined) {
|
|
2864
|
+
settings.setAccuracyRingBorderColor(Mapbox.getAndroidColor(options.accuracyRingColor));
|
|
2865
|
+
}
|
|
2866
|
+
if (options.pulsingColor !== undefined) {
|
|
2867
|
+
settings.setPulsingColor(Mapbox.getAndroidColor(options.pulsingColor));
|
|
2868
|
+
}
|
|
2869
|
+
return settings;
|
|
2870
|
+
}
|
|
2871
|
+
}));
|
|
2872
|
+
// if (typeof options.elevation != 'undefined') {
|
|
2873
|
+
// componentOptionsBuilder = componentOptionsBuilder.elevation(options.elevation);
|
|
2874
|
+
// }
|
|
2875
|
+
// if (typeof options.accuracyAlpha != 'undefined') {
|
|
2876
|
+
// componentOptionsBuilder = componentOptionsBuilder.accuracyAlpha(options.accuracyAlpha);
|
|
2877
|
+
// }
|
|
2878
|
+
// if (typeof options.foregroundTintColor != 'undefined') {
|
|
2879
|
+
// const foregroundTintColor = new java.lang.Integer(android.graphics.Color.parseColor(options.foregroundTintColor));
|
|
2880
|
+
// componentOptionsBuilder = componentOptionsBuilder.foregroundTintColor(foregroundTintColor);
|
|
2881
|
+
// }
|
|
2882
|
+
// if (typeof options.foregroundStaleTintColor != 'undefined') {
|
|
2883
|
+
// const foregroundStaleTintColor = new java.lang.Integer(android.graphics.Color.parseColor(options.foregroundStaleTintColor));
|
|
2884
|
+
// componentOptionsBuilder = componentOptionsBuilder.foregroundStaleTintColor(foregroundStaleTintColor);
|
|
2885
|
+
// }
|
|
2886
|
+
// if (typeof options.backgroundTintColor != 'undefined') {
|
|
2887
|
+
// const backgroundTintColor = new java.lang.Integer(android.graphics.Color.parseColor(options.backgroundTintColor));
|
|
2888
|
+
// componentOptionsBuilder = componentOptionsBuilder.backgroundTintColor(backgroundTintColor);
|
|
2889
|
+
// }
|
|
2890
|
+
// if (typeof options.bearingTintColor != 'undefined') {
|
|
2891
|
+
// const bearingTintColor = new java.lang.Integer(android.graphics.Color.parseColor(options.bearingTintColor));
|
|
2892
|
+
// componentOptionsBuilder = componentOptionsBuilder.bearingTintColor(bearingTintColor);
|
|
2893
|
+
// }
|
|
2894
|
+
// const componentOptions = componentOptionsBuilder.build();
|
|
2895
|
+
// this._locationComponent = this._mapboxMapInstance.getLocationComponent();
|
|
2896
|
+
// const activationOptionsBuilder = com.mapbox.maps.location.LocationComponentActivationOptions.builder(Utils.android.getApplicationContext(), this._mapboxMapInstance.getStyle());
|
|
2897
|
+
// activationOptionsBuilder.locationComponentOptions(componentOptions);
|
|
2898
|
+
// let useDefaultEngine = true;
|
|
2899
|
+
// if (typeof options.useDefaultLocationEngine != 'undefined') {
|
|
2900
|
+
// useDefaultEngine = options.useDefaultLocationEngine;
|
|
2901
|
+
// }
|
|
2902
|
+
// activationOptionsBuilder.useDefaultLocationEngine(useDefaultEngine);
|
|
2903
|
+
// const locationComponentActivationOptions = activationOptionsBuilder.build();
|
|
2904
|
+
// this._locationComponent.activateLocationComponent(locationComponentActivationOptions);
|
|
2905
|
+
// this._locationComponent.setLocationComponentEnabled(true);
|
|
2906
|
+
// let cameraMode = this._stringToCameraMode('TRACKING');
|
|
2907
|
+
// if (typeof options.cameraMode != 'undefined') {
|
|
2908
|
+
// cameraMode = this._stringToCameraMode(options.cameraMode);
|
|
2909
|
+
// }
|
|
2910
|
+
// this._locationComponent.setCameraMode(cameraMode);
|
|
2911
|
+
// let renderMode = com.mapbox.maps.location.modes.RenderMode.COMPASS;
|
|
2912
|
+
// if (typeof options.renderMode != 'undefined') {
|
|
2913
|
+
// renderMode = this._stringToRenderMode(options.renderMode);
|
|
2914
|
+
// }
|
|
2915
|
+
// this._locationComponent.setRenderMode(renderMode);
|
|
2916
|
+
// if (Trace.isEnabled()) {
|
|
2917
|
+
// CLog(CLogTypes.info, 'showUserLocationMarker(): after renderMode');
|
|
2918
|
+
// }
|
|
2919
|
+
// if (typeof options.clickListener != 'undefined') {
|
|
2920
|
+
// this.onLocationClickListener = new com.mapbox.maps.location.OnLocationClickListener({
|
|
2921
|
+
// onLocationComponentClick: () => {
|
|
2922
|
+
// options.clickListener();
|
|
2923
|
+
// }
|
|
2924
|
+
// });
|
|
2925
|
+
// this._locationComponent.addOnLocationClickListener(this.onLocationClickListener);
|
|
2926
|
+
// }
|
|
2927
|
+
// if (typeof options.cameraTrackingChangedListener != 'undefined') {
|
|
2928
|
+
// this._locationComponent.addOnCameraTrackingChangedListener(options.cameraTrackingChangedListener);
|
|
2929
|
+
// }
|
|
2930
|
+
}
|
|
2931
|
+
catch (ex) {
|
|
2932
|
+
if (Trace.isEnabled()) {
|
|
2933
|
+
CLog(CLogTypes.info, 'Error in mapbox.showUserLocationMarker: ' + ex);
|
|
2766
2934
|
}
|
|
2767
|
-
|
|
2935
|
+
throw ex;
|
|
2936
|
+
}
|
|
2768
2937
|
}
|
|
2769
2938
|
/**
|
|
2770
2939
|
* hide (destroy) the user location marker
|
|
@@ -2781,14 +2950,15 @@ export class Mapbox extends MapboxCommon {
|
|
|
2781
2950
|
reject('No map has been loaded');
|
|
2782
2951
|
return;
|
|
2783
2952
|
}
|
|
2784
|
-
|
|
2953
|
+
const locationPlugin = this._getPlugin('MAPBOX_LOCATION_COMPONENT_PLUGIN_ID');
|
|
2954
|
+
if (!locationPlugin) {
|
|
2785
2955
|
if (Trace.isEnabled()) {
|
|
2786
2956
|
CLog(CLogTypes.info, 'hideUserLocationMarker(): no location component is loaded.');
|
|
2787
2957
|
}
|
|
2788
2958
|
resolve();
|
|
2789
2959
|
return;
|
|
2790
2960
|
}
|
|
2791
|
-
|
|
2961
|
+
locationPlugin.setEnabled(false);
|
|
2792
2962
|
resolve();
|
|
2793
2963
|
}
|
|
2794
2964
|
catch (ex) {
|
|
@@ -2808,41 +2978,47 @@ export class Mapbox extends MapboxCommon {
|
|
|
2808
2978
|
* The marker must be configured using showUserLocationMarker before this method
|
|
2809
2979
|
* can called.
|
|
2810
2980
|
*/
|
|
2811
|
-
changeUserLocationMarkerMode(
|
|
2981
|
+
changeUserLocationMarkerMode(renderMode, cameraMode, nativeMap) {
|
|
2812
2982
|
return new Promise((resolve, reject) => {
|
|
2813
2983
|
try {
|
|
2814
|
-
if (
|
|
2815
|
-
|
|
2816
|
-
return;
|
|
2984
|
+
if (Trace.isEnabled()) {
|
|
2985
|
+
CLog(CLogTypes.info, 'showUserLocationMarker()');
|
|
2817
2986
|
}
|
|
2818
|
-
if (
|
|
2819
|
-
|
|
2820
|
-
if (Trace.isEnabled()) {
|
|
2821
|
-
CLog(CLogTypes.info, `Mapbox::changeUserLocationMarkerMode(): current camera mode is: ${this._locationComponent.getCameraMode()}`);
|
|
2822
|
-
CLog(CLogTypes.info, `Mapbox::changeUserLocationMarkerMode(): changing camera mode to: ${cameraMode}`);
|
|
2823
|
-
}
|
|
2824
|
-
this._locationComponent.setCameraMode(cameraMode);
|
|
2825
|
-
if (Trace.isEnabled()) {
|
|
2826
|
-
CLog(CLogTypes.info, `Mapbox::changeUserLocationMarkerMode(): new camera mode is: ${this._locationComponent.getCameraMode()}`);
|
|
2827
|
-
}
|
|
2987
|
+
if (!this._mapboxMapInstance) {
|
|
2988
|
+
throw new Error('No map has been loaded');
|
|
2828
2989
|
}
|
|
2829
|
-
if (
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2990
|
+
if (!this.onIndicatorPositionChangedListener) {
|
|
2991
|
+
throw new Error('showUserLocationMarker must be used first');
|
|
2992
|
+
}
|
|
2993
|
+
const locationPlugin = this._getPlugin('MAPBOX_LOCATION_COMPONENT_PLUGIN_ID');
|
|
2994
|
+
if (this.onIndicatorPositionChangedListener) {
|
|
2995
|
+
locationPlugin.removeOnIndicatorPositionChangedListener(this.onIndicatorPositionChangedListener);
|
|
2996
|
+
}
|
|
2997
|
+
this.onIndicatorPositionChangedListener = new com.mapbox.maps.plugin.locationcomponent.OnIndicatorPositionChangedListener({
|
|
2998
|
+
onIndicatorPositionChanged: (point) => {
|
|
2999
|
+
this.lastKnownLocation = point;
|
|
3000
|
+
if (!cameraMode || cameraMode?.indexOf('TRACKING')) {
|
|
3001
|
+
this._mapboxMapInstance.setCamera(new com.mapbox.maps.CameraOptions.Builder().center(point).build());
|
|
3002
|
+
}
|
|
2834
3003
|
}
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
3004
|
+
});
|
|
3005
|
+
locationPlugin.addOnIndicatorPositionChangedListener(this.onIndicatorPositionChangedListener);
|
|
3006
|
+
locationPlugin.updateSettings(
|
|
3007
|
+
//@ts-ignore
|
|
3008
|
+
new kotlin.jvm.functions.Function1({
|
|
3009
|
+
invoke: (settings) => {
|
|
3010
|
+
settings.setEnabled(true);
|
|
3011
|
+
settings.setPulsingEnabled(true);
|
|
3012
|
+
settings.setPuckBearingEnabled(renderMode !== 'NORMAL');
|
|
3013
|
+
return settings;
|
|
2838
3014
|
}
|
|
2839
|
-
}
|
|
3015
|
+
}));
|
|
2840
3016
|
}
|
|
2841
3017
|
catch (ex) {
|
|
2842
3018
|
if (Trace.isEnabled()) {
|
|
2843
3019
|
CLog(CLogTypes.info, 'Error in mapbox.changeUserLocationMarkerMode: ' + ex);
|
|
2844
3020
|
}
|
|
2845
|
-
|
|
3021
|
+
throw ex;
|
|
2846
3022
|
}
|
|
2847
3023
|
});
|
|
2848
3024
|
}
|
|
@@ -2855,28 +3031,29 @@ export class Mapbox extends MapboxCommon {
|
|
|
2855
3031
|
*/
|
|
2856
3032
|
forceUserLocationUpdate(location, nativeMap) {
|
|
2857
3033
|
return new Promise((resolve, reject) => {
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
3034
|
+
//TODO: is it possible?
|
|
3035
|
+
reject('Not supported anymore');
|
|
3036
|
+
// try {
|
|
3037
|
+
// if (Trace.isEnabled()) {
|
|
3038
|
+
// CLog(CLogTypes.info, 'forceUserLocation(): top');
|
|
3039
|
+
// }
|
|
3040
|
+
// if (!this._locationComponent) {
|
|
3041
|
+
// reject('No location component has been loaded');
|
|
3042
|
+
// return;
|
|
3043
|
+
// }
|
|
3044
|
+
// // the location object needs to be converted into an android location
|
|
3045
|
+
// const nativeLocation = new android.location.Location('background');
|
|
3046
|
+
// nativeLocation.setLatitude(location.latitude);
|
|
3047
|
+
// nativeLocation.setLongitude(location.longitude);
|
|
3048
|
+
// nativeLocation.setAltitude(location.altitude);
|
|
3049
|
+
// this._locationComponent.forceLocationUpdate(nativeLocation);
|
|
3050
|
+
// resolve();
|
|
3051
|
+
// } catch (ex) {
|
|
3052
|
+
// if (Trace.isEnabled()) {
|
|
3053
|
+
// CLog(CLogTypes.info, 'Error in mapbox.forceUserLocationUpdate: ' + ex);
|
|
3054
|
+
// }
|
|
3055
|
+
// reject(ex);
|
|
3056
|
+
// }
|
|
2880
3057
|
});
|
|
2881
3058
|
}
|
|
2882
3059
|
getLayer(name, nativeMap) {
|
|
@@ -2887,8 +3064,10 @@ export class Mapbox extends MapboxCommon {
|
|
|
2887
3064
|
reject('No map has been loaded');
|
|
2888
3065
|
return;
|
|
2889
3066
|
}
|
|
2890
|
-
const styleLoadedCallback = new com.mapbox.
|
|
3067
|
+
const styleLoadedCallback = new com.mapbox.maps.Style.OnStyleLoaded({
|
|
2891
3068
|
onStyleLoaded: (style) => {
|
|
3069
|
+
//TODO: fix declaration which is missing extension for this
|
|
3070
|
+
//@ts-ignore
|
|
2892
3071
|
const layer = style.getLayer(name);
|
|
2893
3072
|
resolve(layer ? new Layer(layer) : null);
|
|
2894
3073
|
}
|
|
@@ -2911,12 +3090,15 @@ export class Mapbox extends MapboxCommon {
|
|
|
2911
3090
|
reject('No map has been loaded');
|
|
2912
3091
|
return;
|
|
2913
3092
|
}
|
|
2914
|
-
const styleLoadedCallback = new com.mapbox.
|
|
3093
|
+
const styleLoadedCallback = new com.mapbox.maps.Style.OnStyleLoaded({
|
|
2915
3094
|
onStyleLoaded: (style) => {
|
|
2916
|
-
const layers = style.
|
|
3095
|
+
const layers = style.getStyleLayers();
|
|
2917
3096
|
const result = [];
|
|
2918
3097
|
for (let i = 0; i < layers.size(); i++) {
|
|
2919
|
-
|
|
3098
|
+
const id = layers.get(i).getId();
|
|
3099
|
+
//TODO: fix declaration which is missing extension for this
|
|
3100
|
+
//@ts-ignore
|
|
3101
|
+
result.push(new Layer(style.getLayer(id)));
|
|
2920
3102
|
}
|
|
2921
3103
|
resolve(result);
|
|
2922
3104
|
}
|
|
@@ -2932,78 +3114,63 @@ export class Mapbox extends MapboxCommon {
|
|
|
2932
3114
|
});
|
|
2933
3115
|
}
|
|
2934
3116
|
_getClickedMarkerDetails(clicked) {
|
|
2935
|
-
for (
|
|
2936
|
-
const cached = this._markers[
|
|
3117
|
+
for (let index = 0; index < this._markers.length; index++) {
|
|
3118
|
+
const cached = this._markers[index];
|
|
2937
3119
|
if (
|
|
2938
3120
|
// eslint-disable-next-line eqeqeq
|
|
2939
|
-
cached.lat == clicked.
|
|
3121
|
+
cached.lat == clicked.position.latitude() &&
|
|
2940
3122
|
// eslint-disable-next-line eqeqeq
|
|
2941
|
-
cached.lng == clicked.
|
|
3123
|
+
cached.lng == clicked.position.longitude() &&
|
|
2942
3124
|
// eslint-disable-next-line eqeqeq
|
|
2943
|
-
cached.title == clicked.
|
|
3125
|
+
cached.title == clicked.title && // == because of null vs undefined
|
|
2944
3126
|
// eslint-disable-next-line eqeqeq
|
|
2945
|
-
cached.subtitle == clicked.
|
|
3127
|
+
cached.subtitle == clicked.snippet) {
|
|
2946
3128
|
return cached;
|
|
2947
3129
|
}
|
|
2948
3130
|
}
|
|
2949
3131
|
}
|
|
2950
|
-
_downloadImage(marker) {
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
resolve(marker);
|
|
2966
|
-
});
|
|
2967
|
-
});
|
|
3132
|
+
async _downloadImage(marker) {
|
|
3133
|
+
// to cache..
|
|
3134
|
+
if (this._markerIconDownloadCache[marker.icon]) {
|
|
3135
|
+
marker.downloadedIcon = this._markerIconDownloadCache[marker.icon];
|
|
3136
|
+
return marker;
|
|
3137
|
+
}
|
|
3138
|
+
// ..or not to cache
|
|
3139
|
+
try {
|
|
3140
|
+
const output = await Http.getImage(marker.icon);
|
|
3141
|
+
this._markerIconDownloadCache[marker.icon] = marker.downloadedIcon = output;
|
|
3142
|
+
return marker;
|
|
3143
|
+
}
|
|
3144
|
+
catch (error) {
|
|
3145
|
+
console.error(error);
|
|
3146
|
+
}
|
|
2968
3147
|
}
|
|
2969
|
-
_downloadMarkerImages(markers) {
|
|
2970
|
-
const iterations = [];
|
|
3148
|
+
async _downloadMarkerImages(markers) {
|
|
2971
3149
|
const result = [];
|
|
2972
3150
|
for (let i = 0; i < markers.length; i++) {
|
|
2973
3151
|
const marker = markers[i];
|
|
2974
3152
|
if (marker.icon && marker.icon.startsWith('http')) {
|
|
2975
|
-
const
|
|
2976
|
-
|
|
2977
|
-
});
|
|
2978
|
-
iterations.push(p);
|
|
3153
|
+
const mark = await this._downloadImage(marker);
|
|
3154
|
+
result.push(mark);
|
|
2979
3155
|
}
|
|
2980
3156
|
else {
|
|
2981
3157
|
result.push(marker);
|
|
2982
3158
|
}
|
|
2983
3159
|
}
|
|
2984
|
-
return
|
|
3160
|
+
return result;
|
|
2985
3161
|
}
|
|
2986
3162
|
project(data) {
|
|
2987
|
-
const mapboxPoint =
|
|
2988
|
-
const screenLocation = this._mapboxMapInstance.
|
|
2989
|
-
return { x: Utils.layout.toDeviceIndependentPixels(screenLocation.
|
|
3163
|
+
const mapboxPoint = com.mapbox.geojson.Point.fromLngLat(data.lng, data.lat);
|
|
3164
|
+
const screenLocation = this._mapboxMapInstance.pixelForCoordinate(mapboxPoint);
|
|
3165
|
+
return { x: Utils.layout.toDeviceIndependentPixels(screenLocation.getX()), y: Utils.layout.toDeviceIndependentPixels(screenLocation.getY()) };
|
|
2990
3166
|
}
|
|
2991
3167
|
projectBack(screenCoordinate) {
|
|
2992
|
-
const pointf = new
|
|
2993
|
-
const coordinate = this._mapboxMapInstance.
|
|
3168
|
+
const pointf = new com.mapbox.maps.ScreenCoordinate(screenCoordinate.x, screenCoordinate.y);
|
|
3169
|
+
const coordinate = this._mapboxMapInstance.coordinateForPixel(pointf);
|
|
2994
3170
|
return {
|
|
2995
|
-
lat: coordinate.
|
|
2996
|
-
lng: coordinate.
|
|
3171
|
+
lat: coordinate.latitude(),
|
|
3172
|
+
lng: coordinate.longitude()
|
|
2997
3173
|
};
|
|
2998
3174
|
}
|
|
2999
|
-
getUserLocationCameraMode(nativeMap) {
|
|
3000
|
-
if (!this._mapboxMapInstance) {
|
|
3001
|
-
return 'NONE';
|
|
3002
|
-
}
|
|
3003
|
-
if (!this._locationComponent) {
|
|
3004
|
-
return 'NONE';
|
|
3005
|
-
}
|
|
3006
|
-
return this._convertCameraMode(this._locationComponent.getCameraMode());
|
|
3007
|
-
}
|
|
3008
3175
|
}
|
|
3009
3176
|
//# sourceMappingURL=index.android.js.map
|