forked from Yermo/nativescript-mapbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapbox.android.js
executable file
·717 lines (625 loc) · 23.7 KB
/
mapbox.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
var utils = require("utils/utils");
var application = require("application");
var frame = require("ui/frame");
var fs = require("file-system");
var mapbox = require("./mapbox-common");
var ACCESS_FINE_LOCATION_PERMISSION_REQUEST_CODE = 111;
var mapView;
var settings;
mapbox._fineLocationPermissionGranted = function () {
var hasPermission = android.os.Build.VERSION.SDK_INT < 23; // Android M. (6.0)
if (!hasPermission) {
hasPermission = android.content.pm.PackageManager.PERMISSION_GRANTED ==
android.support.v4.content.ContextCompat.checkSelfPermission(application.android.foregroundActivity, android.Manifest.permission.ACCESS_FINE_LOCATION);
}
return hasPermission;
};
mapbox.hasFineLocationPermission = function () {
return new Promise(function (resolve) {
resolve(mapbox._fineLocationPermissionGranted());
});
};
mapbox.requestFineLocationPermission = function () {
return new Promise(function (resolve) {
if (!mapbox._fineLocationPermissionGranted()) {
// in a future version we could hook up the callback and change this flow a bit
// android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback.extend({
// onRequestPermissionsResult: function (requestCode, permissions, grantResults) {
// console.log('request permissions granted: '+ requestCode+ " : " + permissions + " : " + grantResults);
// resolve();
// }
// });
application.android.on(application.AndroidApplication.activityRequestPermissionsEvent, function(args) {
console.log('permissions granted: ' + JSON.stringify(args.requestCode) + " : " + JSON.stringify(args.permissions) + " : " + JSON.stringify(args.grantResults));
// permissions granted: 111 : {"length":1} : {"length":1}
resolve();
});
android.support.v4.app.ActivityCompat.requestPermissions(
application.android.foregroundActivity, [android.Manifest.permission.ACCESS_FINE_LOCATION],
ACCESS_FINE_LOCATION_PERMISSION_REQUEST_CODE);
// this is not the nicest solution as the user needs to initiate scanning again after granting permission,
// so enhance this in a future version, but it's ok for now
// resolve();
} else {
resolve();
}
});
};
mapbox._getMapStyle = function(input) {
var Style = com.mapbox.mapboxsdk.constants.Style;
if (input === mapbox.MapStyle.LIGHT) {
return Style.LIGHT;
} else if (input === mapbox.MapStyle.DARK) {
return Style.DARK;
} else if (input === mapbox.MapStyle.OUTDOORS) {
return Style.OUTDOORS;
} else if (input === mapbox.MapStyle.SATELLITE) {
return Style.SATELLITE;
} else if (input === mapbox.MapStyle.HYBRID || mapbox.MapStyle.SATELLITE_STREETS) {
return Style.SATELLITE_STREETS;
} else {
// default
return input;
}
};
application.on(application.orientationChangedEvent, function() {
if(!mapView) {
return;
}
// var params = mapView.getLayoutParams();
// var topMostFrame = frame.topmost();
// params.height = topMostFrame.currentPage.android.getHeight();
// params.width = topMostFrame.currentPage.android.getWidth();
// mapView.requestLayout();
setTimeout(() => {
var topMostFrame = frame.topmost(),
density = utils.layout.getDisplayDensity(),
left = settings.margins.left * density,
right = settings.margins.right * density,
top = settings.margins.top * density,
bottom = settings.margins.bottom * density,
viewWidth = topMostFrame.currentPage.android.getWidth(),
viewHeight = topMostFrame.currentPage.android.getHeight();
var params = new android.widget.FrameLayout.LayoutParams(viewWidth - left - right, viewHeight - top - bottom);
params.setMargins(left, top, right, bottom);
mapView.setLayoutParams(params);
}, 500);
});
mapbox.show = function(arg) {
return new Promise(function (resolve, reject) {
try {
settings = mapbox.merge(arg, mapbox.defaults);
// if no accessToken was set the app may crash
if (settings.accessToken === undefined) {
reject("Please set the 'accessToken' parameter");
return;
}
mapbox._accessToken = settings.accessToken;
com.mapbox.mapboxsdk.MapboxAccountManager.start(application.android.context, settings.accessToken);
var cameraPositionBuilder = new com.mapbox.mapboxsdk.camera.CameraPosition.Builder()
.zoom(settings.zoomLevel);
if (settings.center) {
cameraPositionBuilder.target(new com.mapbox.mapboxsdk.geometry.LatLng(settings.center.lat, settings.center.lng));
}
var mapboxMapOptions = new com.mapbox.mapboxsdk.maps.MapboxMapOptions()
.styleUrl(mapbox._getMapStyle(settings.style))
.compassEnabled(!settings.hideCompass)
.rotateGesturesEnabled(!settings.disableRotation)
.scrollGesturesEnabled(!settings.disableScroll)
.tiltGesturesEnabled(!settings.disableTilt)
.zoomGesturesEnabled(!settings.disableZoom)
.attributionEnabled(!settings.hideAttribution)
.logoEnabled(!settings.hideLogo)
.camera(cameraPositionBuilder.build());
if (settings.showUserLocation) {
if (mapbox._fineLocationPermissionGranted()) {
mapboxMapOptions.locationEnabled(true);
} else {
// devs should ask permission upfront, otherwise enabling location will crash the app on Android 6
console.log("Mapbox plugin: not showing the user location on this device because persmission was not requested/granted");
}
}
mapView = new com.mapbox.mapboxsdk.maps.MapView(
application.android.context,
mapboxMapOptions);
mapView.getMapAsync(
new com.mapbox.mapboxsdk.maps.OnMapReadyCallback({
onMapReady: function (mbMap) {
mapbox.mapboxMap = mbMap;
// mapbox.mapboxMap.setStyleUrl(mapbox._getMapStyle(settings.style));
// mapbox.mapboxMap.setStyleUrl(com.mapbox.mapboxsdk.constants.Style.DARK);
mapbox._markers = [];
mapbox._addMarkers(settings.markers);
mapbox.mapboxMap.setOnMarkerClickListener(
new com.mapbox.mapboxsdk.maps.MapboxMap.OnMarkerClickListener ({
onMarkerClick: function (marker) {
var cachedMarker = mapbox._getClickedMarkerDetails(marker);
if (cachedMarker && cachedMarker.onTap) {
cachedMarker.onTap(cachedMarker);
}
return false;
}
})
);
mapbox.mapboxMap.setOnInfoWindowClickListener(
new com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowClickListener ({
onInfoWindowClick: function (marker) {
var cachedMarker = mapbox._getClickedMarkerDetails(marker);
if (cachedMarker && cachedMarker.onCalloutTap) {
cachedMarker.onCalloutTap(cachedMarker);
}
return true;
}
})
);
resolve();
}
})
);
// TODO remove stuff below if possible
mapView.onResume();
mapView.onCreate(null);
var topMostFrame = frame.topmost(),
density = utils.layout.getDisplayDensity(),
left = settings.margins.left * density,
right = settings.margins.right * density,
top = settings.margins.top * density,
bottom = settings.margins.bottom * density,
viewWidth = topMostFrame.currentPage.android.getWidth(),
viewHeight = topMostFrame.currentPage.android.getHeight();
var params = new android.widget.FrameLayout.LayoutParams(viewWidth - left - right, viewHeight - top - bottom);
params.setMargins(left, top, right, bottom);
mapView.setLayoutParams(params);
if (settings.center) {
// TODO use jumpTo?
// mapView.setCenterCoordinate(new com.mapbox.mapboxsdk.geometry.LatLng(settings.center.lat, settings.center.lng));
}
// TODO see https://github.com/mapbox/mapbox-gl-native/issues/4216
// mapView.setZoomLevel(settings.zoomLevel);
var activity = application.android.foregroundActivity;
var mapViewLayout = new android.widget.FrameLayout(activity);
mapViewLayout.addView(mapView);
topMostFrame.currentPage.android.getParent().addView(mapViewLayout);
} catch (ex) {
console.log("Error in mapbox.show: " + ex);
reject(ex);
}
});
};
mapbox._getClickedMarkerDetails = function (clicked) {
for (var m in mapbox._markers) {
var cached = mapbox._markers[m];
if (cached.lat == clicked.getPosition().getLatitude() &&
cached.lng == clicked.getPosition().getLongitude() &&
cached.title == clicked.getTitle() &&
cached.subtitle == clicked.getSnippet()) {
return cached;
}
}
};
mapbox.hide = function(arg) {
return new Promise(function (resolve, reject) {
try {
var viewGroup = mapView.getParent();
if (viewGroup !== null) {
viewGroup.removeView(mapView);
}
resolve();
} catch (ex) {
console.log("Error in mapbox.show: " + ex);
reject(ex);
}
});
};
mapbox.addMarkers = function (markers) {
return new Promise(function (resolve, reject) {
try {
mapbox._addMarkers(markers);
resolve();
} catch (ex) {
console.log("Error in mapbox.addMarkers: " + ex);
reject(ex);
}
});
};
mapbox._addMarkers = function(markers) {
if (!markers) {
return;
}
for (var m in markers) {
var marker = markers[m];
mapbox._markers.push(marker);
var markerOptions = new com.mapbox.mapboxsdk.annotations.MarkerOptions();
markerOptions.setTitle(marker.title);
markerOptions.setSnippet(marker.subtitle);
markerOptions.setPosition(new com.mapbox.mapboxsdk.geometry.LatLng(marker.lat, marker.lng));
if (marker.iconPath) {
// TODO these bits can be cached
var iconFactory = com.mapbox.mapboxsdk.annotations.IconFactory.getInstance(application.android.context);
var appPath = fs.knownFolders.currentApp().path;
var iconFullPath = appPath + "/" + marker.iconPath;
// if the file doesn't exist the app will crash, so checking it
if (fs.File.exists(iconFullPath)) {
var icon = iconFactory.fromPath(iconFullPath);
// TODO (future) width, height, retina, see https://github.com/Telerik-Verified-Plugins/Mapbox/pull/42/files?diff=unified&short_path=1c65267
markerOptions.setIcon(icon);
} else {
console.log("Marker icon not found, using the default instead. Requested full path: " + iconFullPath);
}
}
mapbox.mapboxMap.addMarker(markerOptions);
}
};
mapbox.setCenter = function (arg) {
return new Promise(function (resolve, reject) {
try {
var cameraPosition = new com.mapbox.mapboxsdk.camera.CameraPosition.Builder().target(
new com.mapbox.mapboxsdk.geometry.LatLng(arg.lat, arg.lng)).build();
if (arg.animated === true) {
mapbox.mapboxMap.animateCamera(
com.mapbox.mapboxsdk.camera.CameraUpdateFactory.newCameraPosition(cameraPosition),
1000,
null);
} else {
mapbox.mapboxMap.setCameraPosition(cameraPosition);
}
resolve();
} catch (ex) {
console.log("Error in mapbox.setCenter: " + ex);
reject(ex);
}
});
};
mapbox.getCenter = function () {
return new Promise(function (resolve, reject) {
try {
var coordinate = mapbox.mapboxMap.getCameraPosition().target;
resolve({
lat: coordinate.getLatitude(),
lng: coordinate.getLongitude()
});
} catch (ex) {
console.log("Error in mapbox.getCenter: " + ex);
reject(ex);
}
});
};
mapbox.setZoomLevel = function (arg) {
return new Promise(function (resolve, reject) {
try {
var animated = arg.animated || true;
var level = arg.level;
if (level >=0 && level <= 20) {
var cameraUpdate = com.mapbox.mapboxsdk.camera.CameraUpdateFactory.zoomTo(level);
if (animated) {
mapbox.mapboxMap.easeCamera(cameraUpdate);
} else {
mapbox.mapboxMap.moveCamera(cameraUpdate);
}
resolve();
} else {
reject("invalid zoomlevel, use any double value from 0 to 20 (like 8.3)");
}
} catch (ex) {
console.log("Error in mapbox.setZoomLevel: " + ex);
reject(ex);
}
});
};
mapbox.getZoomLevel = function () {
return new Promise(function (resolve, reject) {
try {
var level = mapbox.mapboxMap.getCameraPosition().zoom;
resolve(level);
} catch (ex) {
console.log("Error in mapbox.getZoomLevel: " + ex);
reject(ex);
}
});
};
mapbox.setTilt = function (arg) {
return new Promise(function (resolve, reject) {
try {
var tilt = 30;
if (arg.tilt) {
tilt = arg.tilt;
} else if (arg.pitch) {
tilt = arg.pitch;
}
var cameraPositionBuilder = new com.mapbox.mapboxsdk.camera.CameraPosition.Builder()
.tilt(tilt);
var cameraUpdate = com.mapbox.mapboxsdk.camera.CameraUpdateFactory.newCameraPosition(cameraPositionBuilder.build());
mapbox.mapboxMap.easeCamera(cameraUpdate, arg.duration || 5000);
resolve();
} catch (ex) {
console.log("Error in mapbox.setTilt: " + ex);
reject(ex);
}
});
};
mapbox.getTilt = function () {
return new Promise(function (resolve, reject) {
try {
var tilt = mapbox.mapboxMap.getCameraPosition().tilt;
resolve(tilt);
} catch (ex) {
console.log("Error in mapbox.getTilt: " + ex);
reject(ex);
}
});
};
mapbox.animateCamera = function (arg) {
return new Promise(function (resolve, reject) {
try {
var target = arg.target;
if (target === undefined) {
reject("Please set the 'target' parameter");
return;
}
var cameraPositionBuilder = new com.mapbox.mapboxsdk.camera.CameraPosition.Builder()
.target(new com.mapbox.mapboxsdk.geometry.LatLng(target.lat, target.lng));
if (arg.bearing) {
cameraPositionBuilder.bearing(arg.bearing);
}
if (arg.tilt) {
cameraPositionBuilder.tilt(arg.tilt);
}
if (arg.zoomLevel) {
cameraPositionBuilder.zoom(arg.zoomLevel);
}
mapbox.mapboxMap.animateCamera(
com.mapbox.mapboxsdk.camera.CameraUpdateFactory.newCameraPosition(cameraPositionBuilder.build()),
arg.duration ? arg.duration : 10000, // default 10 seconds
null);
resolve();
} catch (ex) {
console.log("Error in mapbox.animateCamera: " + ex);
reject(ex);
}
});
};
mapbox.addPolygon = function (arg) {
return new Promise(function (resolve, reject) {
try {
var points = arg.points;
if (points === undefined) {
reject("Please set the 'points' parameter");
return;
}
var polygonOptions = new com.mapbox.mapboxsdk.annotations.PolygonOptions();
for (var p in points) {
var point = points[p];
polygonOptions.add(new com.mapbox.mapboxsdk.geometry.LatLng(point.lat, point.lng));
}
mapView.addPolygon(polygonOptions);
resolve();
} catch (ex) {
console.log("Error in mapbox.addPolygon: " + ex);
reject(ex);
}
});
};
mapbox.addPolyline = function (arg) {
return new Promise(function (resolve, reject) {
try {
var points = arg.points;
if (points === undefined) {
reject("Please set the 'points' parameter");
return;
}
var polylineOptions = new com.mapbox.mapboxsdk.annotations.PolylineOptions();
polylineOptions.width(arg.width || 5); //Default width 5
polylineOptions.color(arg.color || 0xff000000); //Default color black
for (var p in points) {
var point = points[p];
polylineOptions.add(new com.mapbox.mapboxsdk.geometry.LatLng(point.lat, point.lng));
}
mapView.addPolyline(polylineOptions);
resolve();
} catch (ex) {
console.log("Error in mapbox.addPolyline: " + ex);
reject(ex);
}
});
};
mapbox.getViewport = function (arg) {
return new Promise(function (resolve, reject) {
try {
if (!mapbox.mapboxMap) {
reject("No map has been loaded");
return;
}
var bounds = mapbox.mapboxMap.getProjection().getVisibleRegion().latLngBounds;
resolve({
bounds: {
north: bounds.getLatNorth(),
east: bounds.getLonEast(),
south: bounds.getLatSouth(),
west: bounds.getLonWest()
},
zoomLevel: mapbox.mapboxMap.getCameraPosition().zoom
});
} catch (ex) {
console.log("Error in mapbox.getViewport: " + ex);
reject(ex);
}
});
};
mapbox._getRegionName = function (offlineRegion) {
var metadata = offlineRegion.getMetadata();
var jsonStr = new java.lang.String(metadata, "UTF-8");
var jsonObj = new org.json.JSONObject(jsonStr);
return jsonObj.getString("name");
};
mapbox.deleteOfflineRegion = function (arg) {
return new Promise(function (resolve, reject) {
try {
if (!arg || !arg.name) {
reject("Pass in the 'region' param");
return;
}
var pack = arg.name;
var offlineManager = mapbox._getOfflineManager(arg);
offlineManager.listOfflineRegions(new com.mapbox.mapboxsdk.offline.OfflineManager.ListOfflineRegionsCallback({
onError: function (errorString) {
reject(errorString);
},
onList: function (offlineRegions) {
var regions = [];
var found = false;
if (offlineRegions !== null) {
for (var i=0; i< offlineRegions.length; i++) {
var offlineRegion = offlineRegions[i];
var name = mapbox._getRegionName(offlineRegion);
if (name === pack) {
found = true;
offlineRegion.delete(new com.mapbox.mapboxsdk.offline.OfflineRegion.OfflineRegionDeleteCallback({
onError: function (errorString) {
reject(errorString);
},
onDelete: function () {
resolve();
// don't return, see note below
}
}));
// don't break the loop as there may be multiple packs with the same name
}
}
}
if (!found) {
reject("Region not found");
}
}
}));
} catch (ex) {
console.log("Error in mapbox.listOfflineRegions: " + ex);
reject(ex);
}
});
};
mapbox.listOfflineRegions = function (arg) {
return new Promise(function (resolve, reject) {
try {
if (!mapbox._accessToken && !arg.accessToken) {
reject("First show a map, or pass in an 'accessToken' param");
return;
}
var offlineManager = mapbox._getOfflineManager(arg);
offlineManager.listOfflineRegions(new com.mapbox.mapboxsdk.offline.OfflineManager.ListOfflineRegionsCallback({
onError: function (errorString) {
reject(errorString);
},
onList: function (offlineRegions) {
var regions = [];
if (offlineRegions !== null) {
for (var i=0; i < offlineRegions.length; i++) {
var offlineRegion = offlineRegions[i];
var name = mapbox._getRegionName(offlineRegion);
var offlineRegionDefinition = offlineRegion.getDefinition();
var bounds = offlineRegionDefinition.getBounds();
regions.push({
name: name,
style: offlineRegionDefinition.getStyleURL(),
minZoom: offlineRegionDefinition.getMinZoom() ,
maxZoom: offlineRegionDefinition.getMaxZoom() ,
bounds: {
north: bounds.getLatNorth(),
east: bounds.getLonEast(),
south: bounds.getLatSouth(),
west: bounds.getLonWest()
}
});
}
}
resolve(regions);
}
}));
} catch (ex) {
console.log("Error in mapbox.listOfflineRegions: " + ex);
reject(ex);
}
});
};
mapbox.downloadOfflineRegion = function (arg) {
return new Promise(function (resolve, reject) {
try {
// TODO verify input of all params, and mark them mandatory in TS d.
var styleURL = mapbox._getMapStyle(arg.style);
var bounds = new com.mapbox.mapboxsdk.geometry.LatLngBounds.Builder()
.include(new com.mapbox.mapboxsdk.geometry.LatLng(arg.bounds.north, arg.bounds.west))
.include(new com.mapbox.mapboxsdk.geometry.LatLng(arg.bounds.south, arg.bounds.east))
.build();
var retinaFactor = utils.layout.getDisplayDensity();
var offlineRegionDefinition = new com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition(
styleURL,
bounds,
arg.minZoom,
arg.maxZoom,
retinaFactor);
var info = '{name:"' + arg.name + '"}';
var infoStr = new java.lang.String(info);
var encodedMetadata = infoStr.getBytes();
if (!mapbox._accessToken && !arg.accessToken) {
reject("First show a map, or pass in an 'accessToken' param");
return;
}
var offlineManager = mapbox._getOfflineManager(arg);
offlineManager.createOfflineRegion(offlineRegionDefinition, encodedMetadata, new com.mapbox.mapboxsdk.offline.OfflineManager.CreateOfflineRegionCallback({
onError: function (errorString) {
reject(errorString);
},
onCreate: function (offlineRegion) {
if (arg.onCreate) {
arg.onCreate(offlineRegion);
}
offlineRegion.setDownloadState(com.mapbox.mapboxsdk.offline.OfflineRegion.STATE_ACTIVE);
// Monitor the download progress using setObserver
offlineRegion.setObserver(new com.mapbox.mapboxsdk.offline.OfflineRegion.OfflineRegionObserver({
onStatusChanged: function (status) {
// Calculate the download percentage and update the progress bar
var percentage = status.getRequiredResourceCount() >= 0 ?
(100.0 * status.getCompletedResourceCount() / status.getRequiredResourceCount()) :
0.0;
if (arg.onProgress) {
arg.onProgress({
name: arg.name,
completedSize: status.getCompletedResourceSize(),
completed: status.getCompletedResourceCount(),
expected: status.getRequiredResourceCount(),
percentage: Math.round(percentage * 100) / 100,
// downloading: status.getDownloadState() == com.mapbox.mapboxsdk.offline.OfflineRegion.STATE_ACTIVE,
complete: status.isComplete()
});
}
if (status.isComplete()) {
resolve();
} else if (status.isRequiredResourceCountPrecise()) {
}
},
onError: function (error) {
reject(error.getMessage() + ", reason: " + error.getReason());
},
mapboxTileCountLimitExceeded: function (limit) {
console.log("dl mapboxTileCountLimitExceeded: " + limit);
}
}));
}
}));
} catch (ex) {
console.log("Error in mapbox.downloadOfflineRegion: " + ex);
reject(ex);
}
});
};
mapbox._getOfflineManager = function (arg) {
if (!mapbox._offlineManager) {
mapbox._offlineManager = com.mapbox.mapboxsdk.offline.OfflineManager.getInstance(application.android.context);
if (arg.accessToken) {
mapbox._offlineManager.setAccessToken(arg.accessToken);
} else if (mapbox._accessToken) {
mapbox._offlineManager.setAccessToken(mapbox._accessToken);
}
}
return mapbox._offlineManager;
};
module.exports = mapbox;