@@ -2167,7 +2167,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2167
2167
} ) ;
2168
2168
}
2169
2169
2170
- downloadOfflineRegion ( options : DownloadOfflineRegionOptions ) : Promise < void > {
2170
+ downloadOfflineRegion ( options : DownloadOfflineRegionOptions ) : Promise < any > {
2171
2171
return new Promise ( ( resolve , reject ) => {
2172
2172
try {
2173
2173
const styleURL = this . _getMapStyle ( options . style ) ;
@@ -2181,8 +2181,11 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2181
2181
2182
2182
const offlineRegionDefinition = new com . mapbox . mapboxsdk . offline . OfflineTilePyramidRegionDefinition ( styleURL , bounds , options . minZoom , options . maxZoom , retinaFactor ) ;
2183
2183
2184
- const info = '{name:"' + options . name + '"}' ;
2185
- const infoStr = new java . lang . String ( info ) ;
2184
+ const info = {
2185
+ name : options . name ,
2186
+ ...options . metadata
2187
+ } ;
2188
+ const infoStr = new java . lang . String ( JSON . stringify ( info ) ) ;
2186
2189
const encodedMetadata = infoStr . getBytes ( ) ;
2187
2190
2188
2191
if ( ! this . _accessToken && ! options . accessToken ) {
@@ -2229,7 +2232,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2229
2232
}
2230
2233
2231
2234
if ( status . isComplete ( ) ) {
2232
- resolve ( ) ;
2235
+ resolve ( status ) ;
2233
2236
} else if ( status . isRequiredResourceCountPrecise ( ) ) {
2234
2237
}
2235
2238
} ,
@@ -2280,8 +2283,10 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2280
2283
const name = this . _getRegionName ( offlineRegion ) ;
2281
2284
const offlineRegionDefinition = offlineRegion . getDefinition ( ) ;
2282
2285
const bounds = offlineRegionDefinition . getBounds ( ) ;
2286
+ const metadata = this . _getRegionMetadata ( offlineRegion ) ;
2283
2287
2284
2288
regions . push ( {
2289
+ id : offlineRegion . getID ( ) ,
2285
2290
name,
2286
2291
style : offlineRegionDefinition . getStyleURL ( ) ,
2287
2292
minZoom : offlineRegionDefinition . getMinZoom ( ) ,
@@ -2291,7 +2296,10 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2291
2296
east : bounds . getLonEast ( ) ,
2292
2297
south : bounds . getLatSouth ( ) ,
2293
2298
west : bounds . getLonWest ( )
2294
- }
2299
+ } ,
2300
+ metadata,
2301
+ pixelRatio : offlineRegionDefinition . getPixelRatio ( ) ,
2302
+ type : offlineRegionDefinition . getType ( )
2295
2303
} ) ;
2296
2304
}
2297
2305
}
@@ -2311,8 +2319,8 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2311
2319
deleteOfflineRegion ( options : DeleteOfflineRegionOptions ) : Promise < void > {
2312
2320
return new Promise ( ( resolve , reject ) => {
2313
2321
try {
2314
- if ( ! options || ! options . name ) {
2315
- reject ( "Pass in the 'name' param" ) ;
2322
+ if ( ! options || ( ! options . id && ! options . name ) ) {
2323
+ reject ( "Pass in the 'id' or ' name' param" ) ;
2316
2324
return ;
2317
2325
}
2318
2326
@@ -2327,8 +2335,8 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2327
2335
if ( offlineRegions !== null ) {
2328
2336
for ( let i = 0 ; i < offlineRegions . length ; i ++ ) {
2329
2337
const offlineRegion = offlineRegions [ i ] ;
2330
- const name = this . _getRegionName ( offlineRegion ) ;
2331
- if ( name === options . name ) {
2338
+ const regionId = options . id ? offlineRegion . getID ( ) : this . _getRegionName ( offlineRegion ) ;
2339
+ if ( regionId === ( options . id || options . name ) ) {
2332
2340
found = true ;
2333
2341
offlineRegion . delete (
2334
2342
new com . mapbox . mapboxsdk . offline . OfflineRegion . OfflineRegionDeleteCallback ( {
@@ -2353,7 +2361,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2353
2361
) ;
2354
2362
} catch ( ex ) {
2355
2363
if ( Trace . isEnabled ( ) ) {
2356
- CLog ( CLogTypes . info , 'Error in mapbox.listOfflineRegions : ' + ex ) ;
2364
+ CLog ( CLogTypes . info , 'Error in mapbox.deleteOfflineRegion : ' + ex ) ;
2357
2365
}
2358
2366
reject ( ex ) ;
2359
2367
}
@@ -2954,7 +2962,18 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2954
2962
const metadata = offlineRegion . getMetadata ( ) ;
2955
2963
const jsonStr = new java . lang . String ( metadata , 'UTF-8' ) ;
2956
2964
const jsonObj = new org . json . JSONObject ( jsonStr as any as string ) ;
2957
- return jsonObj . getString ( 'name' ) ;
2965
+ try {
2966
+ return jsonObj . getString ( 'name' ) ;
2967
+ } catch ( error ) {
2968
+ return '' ;
2969
+ }
2970
+ }
2971
+
2972
+ _getRegionMetadata ( offlineRegion : com . mapbox . mapboxsdk . offline . OfflineRegion ) {
2973
+ const metadata = offlineRegion . getMetadata ( ) ;
2974
+ const jsonStr = new java . lang . String ( metadata , 'UTF-8' ) ;
2975
+ const jsonObj = new org . json . JSONObject ( jsonStr as any as string ) ;
2976
+ return JSON . parse ( jsonObj . toString ( ) ) ;
2958
2977
}
2959
2978
2960
2979
/**
0 commit comments