@maplibre/maplibre-react-native 11.0.0-alpha.31 → 11.0.0-alpha.33

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.
Files changed (99) hide show
  1. package/README.md +1 -1
  2. package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +10 -12
  3. package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.kt +9 -0
  4. package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapViewManager.kt +5 -1
  5. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNModule.java +6 -24
  6. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNOfflineModule.kt +561 -0
  7. package/ios/components/map-view/MLRNMapView.h +1 -0
  8. package/ios/components/map-view/MLRNMapView.m +5 -0
  9. package/ios/components/map-view/MLRNMapViewComponentView.mm +4 -0
  10. package/ios/modules/mlrn/MLRNModule.m +0 -13
  11. package/ios/modules/offline/MLRNOfflineModule.h +4 -7
  12. package/ios/modules/offline/MLRNOfflineModule.mm +693 -0
  13. package/lib/commonjs/MLRNModule.js +1 -3
  14. package/lib/commonjs/MLRNModule.js.map +1 -1
  15. package/lib/commonjs/components/map-view/AndroidTextureMapViewNativeComponent.ts +1 -0
  16. package/lib/commonjs/components/map-view/MapView.js.map +1 -1
  17. package/lib/commonjs/components/map-view/MapViewNativeComponent.ts +1 -0
  18. package/lib/commonjs/index.js +0 -8
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/commonjs/modules/offline/NativeOfflineModule.js +9 -0
  21. package/lib/commonjs/modules/offline/NativeOfflineModule.js.map +1 -0
  22. package/lib/commonjs/modules/offline/OfflineManager.js +124 -164
  23. package/lib/commonjs/modules/offline/OfflineManager.js.map +1 -1
  24. package/lib/commonjs/modules/offline/OfflinePack.js +15 -25
  25. package/lib/commonjs/modules/offline/OfflinePack.js.map +1 -1
  26. package/lib/module/MLRNModule.js +0 -1
  27. package/lib/module/MLRNModule.js.map +1 -1
  28. package/lib/module/components/map-view/AndroidTextureMapViewNativeComponent.ts +1 -0
  29. package/lib/module/components/map-view/MapView.js.map +1 -1
  30. package/lib/module/components/map-view/MapViewNativeComponent.ts +1 -0
  31. package/lib/module/index.js +0 -1
  32. package/lib/module/index.js.map +1 -1
  33. package/lib/module/modules/offline/NativeOfflineModule.js +5 -0
  34. package/lib/module/modules/offline/NativeOfflineModule.js.map +1 -0
  35. package/lib/module/modules/offline/OfflineManager.js +123 -163
  36. package/lib/module/modules/offline/OfflineManager.js.map +1 -1
  37. package/lib/module/modules/offline/OfflinePack.js +14 -25
  38. package/lib/module/modules/offline/OfflinePack.js.map +1 -1
  39. package/lib/typescript/commonjs/src/MLRNModule.d.ts +1 -6
  40. package/lib/typescript/commonjs/src/MLRNModule.d.ts.map +1 -1
  41. package/lib/typescript/commonjs/src/components/map-view/AndroidTextureMapViewNativeComponent.d.ts +1 -0
  42. package/lib/typescript/commonjs/src/components/map-view/AndroidTextureMapViewNativeComponent.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/src/components/map-view/MapView.d.ts +6 -0
  44. package/lib/typescript/commonjs/src/components/map-view/MapView.d.ts.map +1 -1
  45. package/lib/typescript/commonjs/src/components/map-view/MapViewNativeComponent.d.ts +1 -0
  46. package/lib/typescript/commonjs/src/components/map-view/MapViewNativeComponent.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/src/index.d.ts +2 -5
  48. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  49. package/lib/typescript/commonjs/src/modules/offline/NativeOfflineModule.d.ts +50 -0
  50. package/lib/typescript/commonjs/src/modules/offline/NativeOfflineModule.d.ts.map +1 -0
  51. package/lib/typescript/commonjs/src/modules/offline/OfflineManager.d.ts +66 -69
  52. package/lib/typescript/commonjs/src/modules/offline/OfflineManager.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/src/modules/offline/OfflinePack.d.ts +11 -9
  54. package/lib/typescript/commonjs/src/modules/offline/OfflinePack.d.ts.map +1 -1
  55. package/lib/typescript/module/src/MLRNModule.d.ts +1 -6
  56. package/lib/typescript/module/src/MLRNModule.d.ts.map +1 -1
  57. package/lib/typescript/module/src/components/map-view/AndroidTextureMapViewNativeComponent.d.ts +1 -0
  58. package/lib/typescript/module/src/components/map-view/AndroidTextureMapViewNativeComponent.d.ts.map +1 -1
  59. package/lib/typescript/module/src/components/map-view/MapView.d.ts +6 -0
  60. package/lib/typescript/module/src/components/map-view/MapView.d.ts.map +1 -1
  61. package/lib/typescript/module/src/components/map-view/MapViewNativeComponent.d.ts +1 -0
  62. package/lib/typescript/module/src/components/map-view/MapViewNativeComponent.d.ts.map +1 -1
  63. package/lib/typescript/module/src/index.d.ts +2 -5
  64. package/lib/typescript/module/src/index.d.ts.map +1 -1
  65. package/lib/typescript/module/src/modules/offline/NativeOfflineModule.d.ts +50 -0
  66. package/lib/typescript/module/src/modules/offline/NativeOfflineModule.d.ts.map +1 -0
  67. package/lib/typescript/module/src/modules/offline/OfflineManager.d.ts +66 -69
  68. package/lib/typescript/module/src/modules/offline/OfflineManager.d.ts.map +1 -1
  69. package/lib/typescript/module/src/modules/offline/OfflinePack.d.ts +11 -9
  70. package/lib/typescript/module/src/modules/offline/OfflinePack.d.ts.map +1 -1
  71. package/package.json +7 -3
  72. package/src/MLRNModule.ts +0 -8
  73. package/src/components/map-view/AndroidTextureMapViewNativeComponent.ts +1 -0
  74. package/src/components/map-view/MapView.tsx +7 -0
  75. package/src/components/map-view/MapViewNativeComponent.ts +1 -0
  76. package/src/index.ts +13 -5
  77. package/src/modules/offline/NativeOfflineModule.ts +63 -0
  78. package/src/modules/offline/OfflineManager.ts +174 -210
  79. package/src/modules/offline/OfflinePack.ts +22 -32
  80. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNOfflineModule.java +0 -586
  81. package/ios/modules/offline/MLRNOfflineModule.m +0 -524
  82. package/lib/commonjs/modules/offline/OfflineCreatePackOptions.js +0 -37
  83. package/lib/commonjs/modules/offline/OfflineCreatePackOptions.js.map +0 -1
  84. package/lib/commonjs/utils/makeNativeBounds.js +0 -11
  85. package/lib/commonjs/utils/makeNativeBounds.js.map +0 -1
  86. package/lib/module/modules/offline/OfflineCreatePackOptions.js +0 -32
  87. package/lib/module/modules/offline/OfflineCreatePackOptions.js.map +0 -1
  88. package/lib/module/utils/makeNativeBounds.js +0 -7
  89. package/lib/module/utils/makeNativeBounds.js.map +0 -1
  90. package/lib/typescript/commonjs/src/modules/offline/OfflineCreatePackOptions.d.ts +0 -20
  91. package/lib/typescript/commonjs/src/modules/offline/OfflineCreatePackOptions.d.ts.map +0 -1
  92. package/lib/typescript/commonjs/src/utils/makeNativeBounds.d.ts +0 -2
  93. package/lib/typescript/commonjs/src/utils/makeNativeBounds.d.ts.map +0 -1
  94. package/lib/typescript/module/src/modules/offline/OfflineCreatePackOptions.d.ts +0 -20
  95. package/lib/typescript/module/src/modules/offline/OfflineCreatePackOptions.d.ts.map +0 -1
  96. package/lib/typescript/module/src/utils/makeNativeBounds.d.ts +0 -2
  97. package/lib/typescript/module/src/utils/makeNativeBounds.d.ts.map +0 -1
  98. package/src/modules/offline/OfflineCreatePackOptions.ts +0 -53
  99. package/src/utils/makeNativeBounds.ts +0 -5
@@ -1,524 +0,0 @@
1
- #import "MLRNOfflineModule.h"
2
- #import "MLRNEvent.h"
3
- #import "MLRNEventTypes.h"
4
- #import "MLRNUtils.h"
5
-
6
- @implementation MLRNOfflineModule {
7
- NSUInteger lastPackState;
8
- double lastPackTimestamp;
9
- double eventThrottle;
10
- BOOL hasListeners;
11
- NSMutableArray<RCTPromiseResolveBlock> *packRequestQueue;
12
- }
13
-
14
- RCT_EXPORT_MODULE()
15
-
16
- + (BOOL)requiresMainQueueSetup {
17
- return YES;
18
- }
19
-
20
- - (void)startObserving {
21
- [super startObserving];
22
- hasListeners = YES;
23
- }
24
-
25
- - (void)stopObserving {
26
- [super stopObserving];
27
- hasListeners = NO;
28
- }
29
-
30
- NSString *const RCT_MLRN_OFFLINE_CALLBACK_PROGRESS = @"OfflineRegionProgress";
31
- NSString *const RCT_MLRN_OFFLINE_CALLBACK_ERROR = @"OfflineRegionError";
32
-
33
- - (instancetype)init {
34
- if (self = [super init]) {
35
- packRequestQueue = [NSMutableArray new];
36
- eventThrottle = 300;
37
- lastPackState = -1;
38
-
39
- NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
40
- [defaultCenter addObserver:self
41
- selector:@selector(offlinePackProgressDidChange:)
42
- name:MLNOfflinePackProgressChangedNotification
43
- object:nil];
44
- [defaultCenter addObserver:self
45
- selector:@selector(offlinePackDidReceiveError:)
46
- name:MLNOfflinePackErrorNotification
47
- object:nil];
48
- [defaultCenter addObserver:self
49
- selector:@selector(offlinePackDidReceiveMaxAllowedMapboxTiles:)
50
- name:MLNOfflinePackMaximumMapboxTilesReachedNotification
51
- object:nil];
52
-
53
- [[MLNOfflineStorage sharedOfflineStorage] addObserver:self
54
- forKeyPath:@"packs"
55
- options:NSKeyValueObservingOptionInitial
56
- context:NULL];
57
- }
58
- return self;
59
- }
60
-
61
- - (void)dealloc {
62
- [[MLNOfflineStorage sharedOfflineStorage] removeObserver:self forKeyPath:@"packs"];
63
- [[NSNotificationCenter defaultCenter] removeObserver:self];
64
- }
65
-
66
- - (NSArray<NSString *> *)supportedEvents {
67
- return @[ RCT_MLRN_OFFLINE_CALLBACK_PROGRESS, RCT_MLRN_OFFLINE_CALLBACK_ERROR ];
68
- }
69
-
70
- - (void)observeValueForKeyPath:(NSString *)keyPath
71
- ofObject:(id)object
72
- change:(NSDictionary<NSKeyValueChangeKey, id> *)change
73
- context:(void *)context {
74
- if ([keyPath isEqualToString:@"state"] && [object isKindOfClass:[MLNOfflinePack class]]) {
75
- MLNOfflinePack *pack = (MLNOfflinePack *)object;
76
- [self observerStateForPack:pack context:context];
77
- return;
78
- }
79
-
80
- if (packRequestQueue.count == 0) {
81
- return;
82
- }
83
-
84
- NSArray<MLNOfflinePack *> *packs = [[MLNOfflineStorage sharedOfflineStorage] packs];
85
- if (packs == nil) {
86
- return;
87
- }
88
-
89
- while (packRequestQueue.count > 0) {
90
- RCTPromiseResolveBlock resolve = [packRequestQueue objectAtIndex:0];
91
- resolve([self _convertPacksToJson:packs]);
92
- [packRequestQueue removeObjectAtIndex:0];
93
- }
94
- }
95
-
96
- RCT_EXPORT_METHOD(createPack : (NSDictionary *)options resolver : (RCTPromiseResolveBlock)
97
- resolve rejecter : (RCTPromiseRejectBlock)reject) {
98
- NSString *styleURL = options[@"styleURL"];
99
- MLNCoordinateBounds bounds = [MLRNUtils fromFeatureCollection:options[@"bounds"]];
100
-
101
- id<MLNOfflineRegion> offlineRegion =
102
- [[MLNTilePyramidOfflineRegion alloc] initWithStyleURL:[NSURL URLWithString:styleURL]
103
- bounds:bounds
104
- fromZoomLevel:[options[@"minZoom"] doubleValue]
105
- toZoomLevel:[options[@"maxZoom"] doubleValue]];
106
- NSData *context = [self _archiveMetadata:options[@"metadata"]];
107
-
108
- [[MLNOfflineStorage sharedOfflineStorage]
109
- addPackForRegion:offlineRegion
110
- withContext:context
111
- completionHandler:^(MLNOfflinePack *pack, NSError *error) {
112
- if (error != nil) {
113
- reject(@"createPack", error.description, error);
114
- return;
115
- }
116
- resolve([self _convertPackToDict:pack]);
117
- [pack resume];
118
- }];
119
- }
120
-
121
- RCT_EXPORT_METHOD(mergeOfflineRegions : (NSString *)path resolver : (RCTPromiseResolveBlock)
122
- resolve rejecter : (RCTPromiseRejectBlock)reject) {
123
- NSString *absolutePath;
124
- if ([path isAbsolutePath]) {
125
- absolutePath = path;
126
- } else {
127
- NSBundle *mainBundle = [NSBundle mainBundle];
128
- NSString *fileName = [path stringByDeletingPathExtension];
129
- NSString *extension = [path pathExtension];
130
- absolutePath = [mainBundle pathForResource:fileName ofType:extension];
131
- if (!absolutePath) {
132
- return reject(
133
- @"asset_does_not_exist",
134
- [NSString
135
- stringWithFormat:@"The given assetName, %@, can't be found in the app's bundle.",
136
- path],
137
- nil);
138
- }
139
- }
140
-
141
- [[MLNOfflineStorage sharedOfflineStorage]
142
- addContentsOfFile:absolutePath
143
- withCompletionHandler:^(NSURL *fileURL, NSArray<MLNOfflinePack *> *packs, NSError *error) {
144
- if (error != nil) {
145
- reject(@"mergeOfflineRegions", error.description, error);
146
- return;
147
- }
148
- resolve(nil);
149
- }];
150
- }
151
-
152
- RCT_EXPORT_METHOD(getPacks : (RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)
153
- reject) {
154
- dispatch_async(dispatch_get_main_queue(), ^{
155
- NSArray<MLNOfflinePack *> *packs = [[MLNOfflineStorage sharedOfflineStorage] packs];
156
-
157
- if (packs == nil) {
158
- // packs have not loaded yet
159
- [self->packRequestQueue addObject:resolve];
160
- return;
161
- }
162
-
163
- resolve([self _convertPacksToJson:packs]);
164
- });
165
- }
166
-
167
- RCT_EXPORT_METHOD(invalidateAmbientCache : (RCTPromiseResolveBlock)
168
- resolve rejecter : (RCTPromiseRejectBlock)reject) {
169
- [[MLNOfflineStorage sharedOfflineStorage]
170
- invalidateAmbientCacheWithCompletionHandler:^(NSError *error) {
171
- if (error != nil) {
172
- reject(@"invalidateAmbientCache", error.description, error);
173
- return;
174
- }
175
- resolve(nil);
176
- }];
177
- }
178
-
179
- RCT_EXPORT_METHOD(clearAmbientCache : (RCTPromiseResolveBlock)
180
- resolve rejecter : (RCTPromiseRejectBlock)reject) {
181
- [[MLNOfflineStorage sharedOfflineStorage]
182
- clearAmbientCacheWithCompletionHandler:^(NSError *error) {
183
- if (error != nil) {
184
- reject(@"clearAmbientCache", error.description, error);
185
- return;
186
- }
187
- resolve(nil);
188
- }];
189
- }
190
-
191
- RCT_EXPORT_METHOD(setMaximumAmbientCacheSize : (NSUInteger)cacheSize resolver : (
192
- RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject) {
193
- [[MLNOfflineStorage sharedOfflineStorage]
194
- setMaximumAmbientCacheSize:cacheSize
195
- withCompletionHandler:^(NSError *error) {
196
- if (error != nil) {
197
- reject(@"setMaximumAmbientCacheSize", error.description, error);
198
- return;
199
- }
200
- resolve(nil);
201
- }];
202
- }
203
-
204
- RCT_EXPORT_METHOD(resetDatabase : (RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)
205
- reject) {
206
- [[MLNOfflineStorage sharedOfflineStorage] resetDatabaseWithCompletionHandler:^(NSError *error) {
207
- if (error != nil) {
208
- reject(@"resetDatabase", error.description, error);
209
- return;
210
- }
211
- resolve(nil);
212
- }];
213
- }
214
-
215
- RCT_EXPORT_METHOD(getPackStatus : (NSString *)name resolver : (RCTPromiseResolveBlock)
216
- resolve rejecter : (RCTPromiseRejectBlock)reject) {
217
- MLNOfflinePack *pack = [self _getPackFromName:name];
218
-
219
- if (pack == nil) {
220
- resolve(nil);
221
- NSLog(@"getPackStatus - Unknown offline region");
222
- return;
223
- }
224
-
225
- if (pack.state == MLNOfflinePackStateUnknown) {
226
- [pack addObserver:self
227
- forKeyPath:@"state"
228
- options:NSKeyValueObservingOptionNew
229
- context:(__bridge_retained void *)resolve];
230
- [pack requestProgress];
231
- } else {
232
- resolve([self _makeRegionStatusPayload:name pack:pack]);
233
- }
234
- }
235
-
236
- - (void)observerStateForPack:(MLNOfflinePack *)pack context:(nullable void *)context {
237
- RCTPromiseResolveBlock resolve = (__bridge_transfer RCTPromiseResolveBlock)context;
238
- dispatch_async(dispatch_get_main_queue(), ^{
239
- NSDictionary *metadata = [self _unarchiveMetadata:pack];
240
- NSString *name = metadata[@"name"];
241
- resolve([self _makeRegionStatusPayload:name pack:pack]);
242
- });
243
- [pack removeObserver:self forKeyPath:@"state" context:context];
244
- }
245
-
246
- RCT_EXPORT_METHOD(invalidatePack : (NSString *)name resolver : (RCTPromiseResolveBlock)
247
- resolve rejecter : (RCTPromiseRejectBlock)reject) {
248
- MLNOfflinePack *pack = [self _getPackFromName:name];
249
-
250
- if (pack == nil) {
251
- resolve(nil);
252
- return;
253
- }
254
- [[MLNOfflineStorage sharedOfflineStorage] invalidatePack:pack
255
- withCompletionHandler:^(NSError *error) {
256
- if (error != nil) {
257
- reject(@"invalidatePack", error.description, error);
258
- return;
259
- }
260
- resolve(nil);
261
- }];
262
- }
263
-
264
- RCT_EXPORT_METHOD(deletePack : (NSString *)name resolver : (RCTPromiseResolveBlock)
265
- resolve rejecter : (RCTPromiseRejectBlock)reject) {
266
- MLNOfflinePack *pack = [self _getPackFromName:name];
267
-
268
- if (pack == nil) {
269
- resolve(nil);
270
- return;
271
- }
272
- if (pack.state == MLNOfflinePackStateInvalid) {
273
- NSError *error = [NSError errorWithDomain:MLNErrorDomain
274
- code:1
275
- userInfo:@{
276
- NSLocalizedDescriptionKey :
277
- NSLocalizedString(@"Pack has already been deleted", nil)
278
- }];
279
- reject(@"deletePack", error.description, error);
280
- return;
281
- }
282
- [[MLNOfflineStorage sharedOfflineStorage] removePack:pack
283
- withCompletionHandler:^(NSError *error) {
284
- if (error != nil) {
285
- reject(@"deletePack", error.description, error);
286
- return;
287
- }
288
- resolve(nil);
289
- }];
290
- }
291
-
292
- RCT_EXPORT_METHOD(pausePackDownload : (NSString *)name resolver : (RCTPromiseResolveBlock)
293
- resolve rejecter : (RCTPromiseRejectBlock)reject) {
294
- MLNOfflinePack *pack = [self _getPackFromName:name];
295
-
296
- if (pack == nil) {
297
- reject(@"pausePackDownload", @"Unknown offline region", nil);
298
- return;
299
- }
300
-
301
- if (pack.state == MLNOfflinePackStateInactive || pack.state == MLNOfflinePackStateComplete) {
302
- resolve(nil);
303
- return;
304
- }
305
-
306
- [pack suspend];
307
- resolve(nil);
308
- }
309
-
310
- RCT_EXPORT_METHOD(resumePackDownload : (NSString *)name resolver : (RCTPromiseResolveBlock)
311
- resolve rejecter : (RCTPromiseRejectBlock)reject) {
312
- MLNOfflinePack *pack = [self _getPackFromName:name];
313
-
314
- if (pack == nil) {
315
- reject(@"resumePack", @"Unknown offline region", nil);
316
- return;
317
- }
318
-
319
- if (pack.state == MLNOfflinePackStateActive || pack.state == MLNOfflinePackStateComplete) {
320
- resolve(nil);
321
- return;
322
- }
323
-
324
- [pack resume];
325
- resolve(nil);
326
- }
327
-
328
- RCT_EXPORT_METHOD(setTileCountLimit : (nonnull NSNumber *)limit) {
329
- [[MLNOfflineStorage sharedOfflineStorage] setMaximumAllowedMapboxTiles:[limit intValue]];
330
- }
331
-
332
- RCT_EXPORT_METHOD(setProgressEventThrottle : (nonnull NSNumber *)throttleValue) {
333
- eventThrottle = [throttleValue doubleValue];
334
- }
335
-
336
- - (void)offlinePackProgressDidChange:(NSNotification *)notification {
337
- MLNOfflinePack *pack = notification.object;
338
-
339
- if (pack.state == MLNOfflinePackStateInvalid) {
340
- return; // Avoid invalid offline pack exception
341
- }
342
-
343
- if ([self _shouldSendProgressEvent:[self _getCurrentTimestamp] pack:pack]) {
344
- NSDictionary *metadata = [self _unarchiveMetadata:pack];
345
- MLRNEvent *event = [self _makeProgressEvent:metadata[@"name"] pack:pack];
346
- [self _sendEvent:RCT_MLRN_OFFLINE_CALLBACK_PROGRESS event:event];
347
- lastPackTimestamp = [self _getCurrentTimestamp];
348
- }
349
-
350
- lastPackState = pack.state;
351
- }
352
-
353
- - (void)offlinePackDidReceiveError:(NSNotification *)notification {
354
- MLNOfflinePack *pack = notification.object;
355
- if (pack.state == MLNOfflinePackStateInvalid) {
356
- return; // Avoid invalid offline pack exception
357
- }
358
- NSDictionary *metadata = [self _unarchiveMetadata:pack];
359
-
360
- NSString *name = metadata[@"name"];
361
- if (name != nil) {
362
- NSError *error = notification.userInfo[MLNOfflinePackUserInfoKeyError];
363
- MLRNEvent *event = [self _makeErrorEvent:name
364
- type:RCT_MLRN_OFFLINE_ERROR
365
- message:error.description];
366
- [self _sendEvent:RCT_MLRN_OFFLINE_CALLBACK_ERROR event:event];
367
- }
368
- }
369
-
370
- - (void)offlinePackDidReceiveMaxAllowedMapboxTiles:(NSNotification *)notification {
371
- MLNOfflinePack *pack = notification.object;
372
- NSDictionary *metadata = [self _unarchiveMetadata:pack];
373
-
374
- NSString *name = metadata[@"name"];
375
- if (name != nil) {
376
- MLRNEvent *event = [self _makeErrorEvent:name
377
- type:RCT_MLRN_OFFLINE_ERROR
378
- message:@"Mapbox tile limit exceeded"];
379
- [self _sendEvent:RCT_MLRN_OFFLINE_CALLBACK_ERROR event:event];
380
- }
381
- }
382
-
383
- - (double)_getCurrentTimestamp {
384
- return CACurrentMediaTime() * 1000;
385
- }
386
-
387
- - (NSData *)_archiveMetadata:(NSString *)metadata {
388
- return [NSKeyedArchiver archivedDataWithRootObject:metadata];
389
- }
390
-
391
- - (NSDictionary *)_unarchiveMetadata:(MLNOfflinePack *)pack {
392
- id data = [NSKeyedUnarchiver unarchiveObjectWithData:pack.context];
393
- // Version v5 store data as NSDictionary while v6 store data as JSON string.
394
- // User might save offline pack in v5 and then try to read in v6.
395
- // In v5 are metadata stored nested which need to be handled in JS.
396
- // Example of how data are stored in v5
397
- // {
398
- // name: "New York",
399
- // metadata: {
400
- // customMeta: "...",
401
- // }
402
- // }
403
- if ([data isKindOfClass:[NSDictionary class]]) {
404
- return data;
405
- }
406
-
407
- if (data == nil) {
408
- return @{};
409
- }
410
-
411
- return [NSJSONSerialization JSONObjectWithData:[data dataUsingEncoding:NSUTF8StringEncoding]
412
- options:NSJSONReadingMutableContainers
413
- error:nil];
414
- }
415
-
416
- - (NSDictionary *)_makeRegionStatusPayload:(NSString *)name pack:(MLNOfflinePack *)pack {
417
- uint64_t completedResources = pack.progress.countOfResourcesCompleted;
418
- uint64_t expectedResources = pack.progress.countOfResourcesExpected;
419
- float progressPercentage = (float)completedResources / expectedResources;
420
-
421
- // prevent NaN errors when expectedResources is 0
422
- if (expectedResources == 0) {
423
- progressPercentage = 0;
424
- }
425
-
426
- return @{
427
- @"state" : @(pack.state),
428
- @"name" : name,
429
- @"percentage" : @(ceilf(progressPercentage * 100.0)),
430
- @"completedResourceCount" : @(pack.progress.countOfResourcesCompleted),
431
- @"completedResourceSize" : @(pack.progress.countOfBytesCompleted),
432
- @"completedTileSize" : @(pack.progress.countOfTileBytesCompleted),
433
- @"completedTileCount" : @(pack.progress.countOfTilesCompleted),
434
- @"requiredResourceCount" : @(pack.progress.maximumResourcesExpected)
435
- };
436
- }
437
-
438
- - (MLRNEvent *)_makeProgressEvent:(NSString *)name pack:(MLNOfflinePack *)pack {
439
- return [MLRNEvent makeEvent:RCT_MLRN_OFFLINE_PROGRESS
440
- withPayload:[self _makeRegionStatusPayload:name pack:pack]];
441
- }
442
-
443
- - (MLRNEvent *)_makeErrorEvent:(NSString *)name type:(NSString *)type message:(NSString *)message {
444
- NSDictionary *payload = @{@"name" : name, @"message" : message};
445
- return [MLRNEvent makeEvent:type withPayload:payload];
446
- }
447
-
448
- - (NSArray<NSDictionary *> *)_convertPacksToJson:(NSArray<MLNOfflinePack *> *)packs {
449
- NSMutableArray<NSDictionary *> *jsonPacks = [NSMutableArray new];
450
-
451
- if (packs == nil) {
452
- return jsonPacks;
453
- }
454
-
455
- for (MLNOfflinePack *pack in packs) {
456
- [jsonPacks addObject:[self _convertPackToDict:pack]];
457
- }
458
-
459
- return jsonPacks;
460
- }
461
-
462
- - (NSDictionary *)_convertPackToDict:(MLNOfflinePack *)pack {
463
- // format bounds
464
- MLNTilePyramidOfflineRegion *region = (MLNTilePyramidOfflineRegion *)pack.region;
465
- if (region == nil) {
466
- return nil;
467
- }
468
-
469
- NSArray *jsonBounds = @[
470
- @[ @(region.bounds.ne.longitude), @(region.bounds.ne.latitude) ],
471
- @[ @(region.bounds.sw.longitude), @(region.bounds.sw.latitude) ]
472
- ];
473
-
474
- // format metadata
475
- NSDictionary *metadata = [self _unarchiveMetadata:pack];
476
- NSData *jsonMetadata = [NSJSONSerialization dataWithJSONObject:metadata options:0 error:nil];
477
- return @{
478
- @"metadata" : [[NSString alloc] initWithData:jsonMetadata encoding:NSUTF8StringEncoding],
479
- @"bounds" : jsonBounds
480
- };
481
- }
482
-
483
- - (MLNOfflinePack *)_getPackFromName:(NSString *)name {
484
- NSArray<MLNOfflinePack *> *packs = [[MLNOfflineStorage sharedOfflineStorage] packs];
485
-
486
- if (packs == nil) {
487
- return nil;
488
- }
489
-
490
- for (MLNOfflinePack *pack in packs) {
491
- NSDictionary *metadata = [self _unarchiveMetadata:pack];
492
-
493
- if ([name isEqualToString:metadata[@"name"]]) {
494
- return pack;
495
- }
496
- }
497
-
498
- return nil;
499
- }
500
-
501
- - (void)_sendEvent:(NSString *)eventName event:(MLRNEvent *)event {
502
- if (!hasListeners) {
503
- return;
504
- }
505
- [self sendEventWithName:eventName body:[event toJSON]];
506
- }
507
-
508
- - (BOOL)_shouldSendProgressEvent:(double)currentTimestamp pack:(MLNOfflinePack *)currentPack {
509
- if (lastPackState == -1) {
510
- return YES;
511
- }
512
-
513
- if (lastPackState != currentPack.state) {
514
- return YES;
515
- }
516
-
517
- if (currentTimestamp - lastPackTimestamp > eventThrottle) {
518
- return YES;
519
- }
520
-
521
- return NO;
522
- }
523
-
524
- @end
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.OfflineCreatePackOptions = void 0;
7
- var _makeNativeBounds = require("../../utils/makeNativeBounds.js");
8
- class OfflineCreatePackOptions {
9
- constructor(options) {
10
- this._assert(options);
11
- this.name = options.name;
12
- this.styleURL = options.styleURL;
13
- this.bounds = (0, _makeNativeBounds.makeNativeBounds)(...options.bounds);
14
- this.minZoom = options.minZoom;
15
- this.maxZoom = options.maxZoom;
16
- this.metadata = this._makeMetadata(options.metadata);
17
- }
18
- _assert(options) {
19
- if (!options.styleURL) {
20
- throw new Error("Style URL must be provided for creating an offline pack");
21
- }
22
- if (!options.name) {
23
- throw new Error("Name must be provided for creating an offline pack");
24
- }
25
- if (!options.bounds) {
26
- throw new Error("Bounds must be provided for creating an offline pack");
27
- }
28
- }
29
- _makeMetadata(metadata) {
30
- return JSON.stringify({
31
- ...metadata,
32
- name: this.name
33
- });
34
- }
35
- }
36
- exports.OfflineCreatePackOptions = OfflineCreatePackOptions;
37
- //# sourceMappingURL=OfflineCreatePackOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_makeNativeBounds","require","OfflineCreatePackOptions","constructor","options","_assert","name","styleURL","bounds","makeNativeBounds","minZoom","maxZoom","metadata","_makeMetadata","Error","JSON","stringify","exports"],"sourceRoot":"../../../../src","sources":["modules/offline/OfflineCreatePackOptions.ts"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAWO,MAAMC,wBAAwB,CAAC;EAQpCC,WAAWA,CAACC,OAAsC,EAAE;IAClD,IAAI,CAACC,OAAO,CAACD,OAAO,CAAC;IAErB,IAAI,CAACE,IAAI,GAAGF,OAAO,CAACE,IAAI;IACxB,IAAI,CAACC,QAAQ,GAAGH,OAAO,CAACG,QAAQ;IAChC,IAAI,CAACC,MAAM,GAAG,IAAAC,kCAAgB,EAAC,GAAGL,OAAO,CAACI,MAAM,CAAC;IACjD,IAAI,CAACE,OAAO,GAAGN,OAAO,CAACM,OAAO;IAC9B,IAAI,CAACC,OAAO,GAAGP,OAAO,CAACO,OAAO;IAC9B,IAAI,CAACC,QAAQ,GAAG,IAAI,CAACC,aAAa,CAACT,OAAO,CAACQ,QAAQ,CAAC;EACtD;EAEAP,OAAOA,CAACD,OAAsC,EAAQ;IACpD,IAAI,CAACA,OAAO,CAACG,QAAQ,EAAE;MACrB,MAAM,IAAIO,KAAK,CACb,yDACF,CAAC;IACH;IAEA,IAAI,CAACV,OAAO,CAACE,IAAI,EAAE;MACjB,MAAM,IAAIQ,KAAK,CAAC,oDAAoD,CAAC;IACvE;IAEA,IAAI,CAACV,OAAO,CAACI,MAAM,EAAE;MACnB,MAAM,IAAIM,KAAK,CAAC,sDAAsD,CAAC;IACzE;EACF;EAEAD,aAAaA,CAACD,QAA8B,EAAU;IACpD,OAAOG,IAAI,CAACC,SAAS,CAAC;MACpB,GAAGJ,QAAQ;MACXN,IAAI,EAAE,IAAI,CAACA;IACb,CAAC,CAAC;EACJ;AACF;AAACW,OAAA,CAAAf,wBAAA,GAAAA,wBAAA","ignoreList":[]}
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.makeNativeBounds = makeNativeBounds;
7
- var _helpers = require("@turf/helpers");
8
- function makeNativeBounds(ne, sw) {
9
- return JSON.stringify((0, _helpers.featureCollection)([(0, _helpers.point)(ne), (0, _helpers.point)(sw)]));
10
- }
11
- //# sourceMappingURL=makeNativeBounds.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_helpers","require","makeNativeBounds","ne","sw","JSON","stringify","featureCollection","point"],"sourceRoot":"../../../src","sources":["utils/makeNativeBounds.ts"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEO,SAASC,gBAAgBA,CAACC,EAAoB,EAAEC,EAAoB,EAAE;EAC3E,OAAOC,IAAI,CAACC,SAAS,CAAC,IAAAC,0BAAiB,EAAC,CAAC,IAAAC,cAAK,EAACL,EAAE,CAAC,EAAE,IAAAK,cAAK,EAACJ,EAAE,CAAC,CAAC,CAAC,CAAC;AAClE","ignoreList":[]}
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- import { makeNativeBounds } from "../../utils/makeNativeBounds.js";
4
- export class OfflineCreatePackOptions {
5
- constructor(options) {
6
- this._assert(options);
7
- this.name = options.name;
8
- this.styleURL = options.styleURL;
9
- this.bounds = makeNativeBounds(...options.bounds);
10
- this.minZoom = options.minZoom;
11
- this.maxZoom = options.maxZoom;
12
- this.metadata = this._makeMetadata(options.metadata);
13
- }
14
- _assert(options) {
15
- if (!options.styleURL) {
16
- throw new Error("Style URL must be provided for creating an offline pack");
17
- }
18
- if (!options.name) {
19
- throw new Error("Name must be provided for creating an offline pack");
20
- }
21
- if (!options.bounds) {
22
- throw new Error("Bounds must be provided for creating an offline pack");
23
- }
24
- }
25
- _makeMetadata(metadata) {
26
- return JSON.stringify({
27
- ...metadata,
28
- name: this.name
29
- });
30
- }
31
- }
32
- //# sourceMappingURL=OfflineCreatePackOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["makeNativeBounds","OfflineCreatePackOptions","constructor","options","_assert","name","styleURL","bounds","minZoom","maxZoom","metadata","_makeMetadata","Error","JSON","stringify"],"sourceRoot":"../../../../src","sources":["modules/offline/OfflineCreatePackOptions.ts"],"mappings":";;AAAA,SAASA,gBAAgB,QAAQ,iCAA8B;AAW/D,OAAO,MAAMC,wBAAwB,CAAC;EAQpCC,WAAWA,CAACC,OAAsC,EAAE;IAClD,IAAI,CAACC,OAAO,CAACD,OAAO,CAAC;IAErB,IAAI,CAACE,IAAI,GAAGF,OAAO,CAACE,IAAI;IACxB,IAAI,CAACC,QAAQ,GAAGH,OAAO,CAACG,QAAQ;IAChC,IAAI,CAACC,MAAM,GAAGP,gBAAgB,CAAC,GAAGG,OAAO,CAACI,MAAM,CAAC;IACjD,IAAI,CAACC,OAAO,GAAGL,OAAO,CAACK,OAAO;IAC9B,IAAI,CAACC,OAAO,GAAGN,OAAO,CAACM,OAAO;IAC9B,IAAI,CAACC,QAAQ,GAAG,IAAI,CAACC,aAAa,CAACR,OAAO,CAACO,QAAQ,CAAC;EACtD;EAEAN,OAAOA,CAACD,OAAsC,EAAQ;IACpD,IAAI,CAACA,OAAO,CAACG,QAAQ,EAAE;MACrB,MAAM,IAAIM,KAAK,CACb,yDACF,CAAC;IACH;IAEA,IAAI,CAACT,OAAO,CAACE,IAAI,EAAE;MACjB,MAAM,IAAIO,KAAK,CAAC,oDAAoD,CAAC;IACvE;IAEA,IAAI,CAACT,OAAO,CAACI,MAAM,EAAE;MACnB,MAAM,IAAIK,KAAK,CAAC,sDAAsD,CAAC;IACzE;EACF;EAEAD,aAAaA,CAACD,QAA8B,EAAU;IACpD,OAAOG,IAAI,CAACC,SAAS,CAAC;MACpB,GAAGJ,QAAQ;MACXL,IAAI,EAAE,IAAI,CAACA;IACb,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- import { featureCollection, point } from "@turf/helpers";
4
- export function makeNativeBounds(ne, sw) {
5
- return JSON.stringify(featureCollection([point(ne), point(sw)]));
6
- }
7
- //# sourceMappingURL=makeNativeBounds.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["featureCollection","point","makeNativeBounds","ne","sw","JSON","stringify"],"sourceRoot":"../../../src","sources":["utils/makeNativeBounds.ts"],"mappings":";;AAAA,SAASA,iBAAiB,EAAEC,KAAK,QAAQ,eAAe;AAExD,OAAO,SAASC,gBAAgBA,CAACC,EAAoB,EAAEC,EAAoB,EAAE;EAC3E,OAAOC,IAAI,CAACC,SAAS,CAACN,iBAAiB,CAAC,CAACC,KAAK,CAACE,EAAE,CAAC,EAAEF,KAAK,CAACG,EAAE,CAAC,CAAC,CAAC,CAAC;AAClE","ignoreList":[]}
@@ -1,20 +0,0 @@
1
- export interface OfflineCreatePackInputOptions {
2
- name: string;
3
- styleURL: string;
4
- bounds: [GeoJSON.Position, GeoJSON.Position];
5
- minZoom?: number;
6
- maxZoom?: number;
7
- metadata?: Record<string, any>;
8
- }
9
- export declare class OfflineCreatePackOptions {
10
- name: string;
11
- styleURL: string;
12
- bounds: string;
13
- minZoom?: number;
14
- maxZoom?: number;
15
- metadata: string;
16
- constructor(options: OfflineCreatePackInputOptions);
17
- _assert(options: OfflineCreatePackInputOptions): void;
18
- _makeMetadata(metadata?: Record<string, any>): string;
19
- }
20
- //# sourceMappingURL=OfflineCreatePackOptions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OfflineCreatePackOptions.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/offline/OfflineCreatePackOptions.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED,qBAAa,wBAAwB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;gBAEL,OAAO,EAAE,6BAA6B;IAWlD,OAAO,CAAC,OAAO,EAAE,6BAA6B,GAAG,IAAI;IAgBrD,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM;CAMtD"}
@@ -1,2 +0,0 @@
1
- export declare function makeNativeBounds(ne: GeoJSON.Position, sw: GeoJSON.Position): string;
2
- //# sourceMappingURL=makeNativeBounds.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"makeNativeBounds.d.ts","sourceRoot":"","sources":["../../../../../src/utils/makeNativeBounds.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE,EAAE,OAAO,CAAC,QAAQ,UAE1E"}
@@ -1,20 +0,0 @@
1
- export interface OfflineCreatePackInputOptions {
2
- name: string;
3
- styleURL: string;
4
- bounds: [GeoJSON.Position, GeoJSON.Position];
5
- minZoom?: number;
6
- maxZoom?: number;
7
- metadata?: Record<string, any>;
8
- }
9
- export declare class OfflineCreatePackOptions {
10
- name: string;
11
- styleURL: string;
12
- bounds: string;
13
- minZoom?: number;
14
- maxZoom?: number;
15
- metadata: string;
16
- constructor(options: OfflineCreatePackInputOptions);
17
- _assert(options: OfflineCreatePackInputOptions): void;
18
- _makeMetadata(metadata?: Record<string, any>): string;
19
- }
20
- //# sourceMappingURL=OfflineCreatePackOptions.d.ts.map