@maplibre/maplibre-react-native 11.0.0-beta.14 → 11.0.0-beta.16

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.
@@ -91,7 +91,6 @@ open class MLRNMapView(
91
91
  OnMapReadyCallback,
92
92
  MapLibreMap.OnMapClickListener,
93
93
  MapLibreMap.OnMapLongClickListener,
94
- MapView.OnCameraIsChangingListener,
95
94
  MapView.OnCameraDidChangeListener,
96
95
  MapView.OnWillStartLoadingMapListener,
97
96
  MapView.OnDidFailLoadingMapListener,
@@ -347,7 +346,6 @@ open class MLRNMapView(
347
346
 
348
347
  setLifecycleListeners()
349
348
 
350
- addOnCameraIsChangingListener(this)
351
349
  addOnCameraDidChangeListener(this)
352
350
  addOnDidFailLoadingMapListener(this)
353
351
  addOnDidFinishLoadingMapListener(this)
@@ -417,6 +415,10 @@ open class MLRNMapView(
417
415
  handleMapChangedEvent("onRegionWillChange", true)
418
416
  }
419
417
 
418
+ mapLibreMap.addOnCameraMoveListener {
419
+ handleMapChangedEvent("onRegionIsChanging", true)
420
+ }
421
+
420
422
  mapLibreMap.addOnMoveListener(
421
423
  object : MapLibreMap.OnMoveListener {
422
424
  override fun onMoveBegin(detector: MoveGestureDetector) {
@@ -425,8 +427,7 @@ open class MLRNMapView(
425
427
  }
426
428
 
427
429
  override fun onMove(detector: MoveGestureDetector) {
428
- cameraChangeTracker.setReason(CameraChangeTracker.USER_GESTURE)
429
- handleMapChangedEvent("onRegionIsChanging", true)
430
+ // Handled by mapLibreMap.addOnCameraMoveListener
430
431
  }
431
432
 
432
433
  override fun onMoveEnd(detector: MoveGestureDetector) {
@@ -621,10 +622,6 @@ open class MLRNMapView(
621
622
  cameraChangeTracker.isAnimating = animated
622
623
  }
623
624
 
624
- override fun onCameraIsChanging() {
625
- handleMapChangedEvent("onRegionIsChanging", true)
626
- }
627
-
628
625
  override fun onWillStartLoadingMap() {
629
626
  handleMapChangedEvent("onWillStartLoadingMap")
630
627
  }
@@ -36,6 +36,8 @@ class MLRNOfflineModule(
36
36
  private val context: Context = reactContext.applicationContext
37
37
  private var progressEventThrottle = 300.0
38
38
 
39
+ private val regions = HashMap<String, OfflineRegion>()
40
+
39
41
  override fun initialize() {
40
42
  Handler(Looper.getMainLooper()).post {
41
43
  runMigrations()
@@ -72,12 +74,14 @@ class MLRNOfflineModule(
72
74
  metadataBytes,
73
75
  object : OfflineManager.CreateOfflineRegionCallback {
74
76
  override fun onCreate(offlineRegion: OfflineRegion) {
77
+ regions[packId] = offlineRegion
75
78
  val pack = fromOfflineRegion(offlineRegion)
76
79
  promise.resolve(pack)
77
80
  setOfflineRegionObserver(packId, offlineRegion)
78
81
  }
79
82
 
80
83
  override fun onError(error: String) {
84
+ promise.reject("createPack", error)
81
85
  emitOnError(makeErrorPayload(packId, error))
82
86
  Log.e(NAME, "createPack error: $error")
83
87
  }
@@ -165,6 +169,7 @@ class MLRNOfflineModule(
165
169
  offlineManager.resetDatabase(
166
170
  object : OfflineManager.FileSourceCallback {
167
171
  override fun onSuccess() {
172
+ clearRegions()
168
173
  promise.resolve(null)
169
174
  }
170
175
 
@@ -231,6 +236,7 @@ class MLRNOfflineModule(
231
236
  val hasRegion = region != null
232
237
 
233
238
  if (hasRegion) {
239
+ regions[id] = region
234
240
  setOfflineRegionObserver(id, region)
235
241
  }
236
242
 
@@ -254,7 +260,7 @@ class MLRNOfflineModule(
254
260
  offlineManager.listOfflineRegions(
255
261
  object : OfflineManager.ListOfflineRegionsCallback {
256
262
  override fun onList(offlineRegions: Array<OfflineRegion>?) {
257
- val region = getRegionById(id, offlineRegions)
263
+ val region = regions[id] ?: getRegionById(id, offlineRegions)
258
264
 
259
265
  if (region == null) {
260
266
  promise.resolve(null)
@@ -292,7 +298,7 @@ class MLRNOfflineModule(
292
298
  offlineManager.listOfflineRegions(
293
299
  object : OfflineManager.ListOfflineRegionsCallback {
294
300
  override fun onList(offlineRegions: Array<OfflineRegion>?) {
295
- val region = getRegionById(id, offlineRegions)
301
+ val region = regions[id] ?: getRegionById(id, offlineRegions)
296
302
 
297
303
  if (region == null) {
298
304
  promise.resolve(null)
@@ -304,6 +310,7 @@ class MLRNOfflineModule(
304
310
  region.delete(
305
311
  object : OfflineRegion.OfflineRegionDeleteCallback {
306
312
  override fun onDelete() {
313
+ regions.remove(id)
307
314
  promise.resolve(null)
308
315
  }
309
316
 
@@ -331,7 +338,7 @@ class MLRNOfflineModule(
331
338
  offlineManager.listOfflineRegions(
332
339
  object : OfflineManager.ListOfflineRegionsCallback {
333
340
  override fun onList(offlineRegions: Array<OfflineRegion>?) {
334
- val offlineRegion = getRegionById(id, offlineRegions)
341
+ val offlineRegion = regions[id] ?: getRegionById(id, offlineRegions)
335
342
 
336
343
  if (offlineRegion == null) {
337
344
  promise.reject("pauseRegionDownload", "Unknown offline region")
@@ -361,7 +368,8 @@ class MLRNOfflineModule(
361
368
  offlineManager.listOfflineRegions(
362
369
  object : OfflineManager.ListOfflineRegionsCallback {
363
370
  override fun onList(offlineRegions: Array<OfflineRegion>?) {
364
- val offlineRegion = getRegionById(id, offlineRegions)
371
+ val offlineRegion =
372
+ regions[id] ?: getRegionById(id, offlineRegions)?.also { regions[id] = it }
365
373
 
366
374
  if (offlineRegion == null) {
367
375
  promise.reject("resumeRegionDownload", "Unknown offline region")
@@ -631,8 +639,23 @@ class MLRNOfflineModule(
631
639
  return null
632
640
  }
633
641
 
642
+ override fun invalidate() {
643
+ Handler(Looper.getMainLooper()).post {
644
+ clearRegions()
645
+ }
646
+ super.invalidate()
647
+ }
648
+
634
649
  private fun activateFileSource() {
635
650
  val fileSource = FileSource.getInstance(context)
636
651
  fileSource.activate()
637
652
  }
653
+
654
+ private fun clearRegions() {
655
+ for (region in regions.values) {
656
+ region.setDownloadState(OfflineRegion.STATE_INACTIVE)
657
+ region.setObserver(null)
658
+ }
659
+ regions.clear()
660
+ }
638
661
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maplibre/maplibre-react-native",
3
3
  "description": "React Native library for creating maps with MapLibre Native for Android & iOS",
4
- "version": "11.0.0-beta.14",
4
+ "version": "11.0.0-beta.16",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": true