@rnmapbox/maps 10.0.2 → 10.0.3-beta.0

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/README.md CHANGED
@@ -21,11 +21,8 @@ _A community-supported, open-source React Native library for building maps with
21
21
 
22
22
  ---
23
23
  ## News & Discussions
24
- #### <span style="color:red">&rarr;</span> Future of this repo: participate in the [discussion thread](https://github.com/rnmapbox/maps/discussions/1680)
25
-
26
24
  #### <span style="color:red">&rarr;</span> Call for additional maintainers [discussion thread](https://github.com/rnmapbox/maps/discussions/1551)
27
25
 
28
- #### <span style="color:red">&rarr;</span> This README is for the unreleased 10* branch. Please see [v8 branch](https://github.com/rnmapbox/maps/tree/v8) for documentation on 8.* releases
29
26
  ---
30
27
 
31
28
  <table>
@@ -138,7 +138,7 @@ dependencies {
138
138
  }
139
139
  else if (safeExtGet("RNMapboxMapsImpl", defaultMapboxMapsImpl) == "mapbox") {
140
140
  implementation "com.mapbox.maps:android:${safeExtGet("RNMapboxMapsVersion", defaultMapboxMapsVersion)}"
141
- implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:6.10.0'
141
+ implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:6.11.0'
142
142
  implementation 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0'
143
143
  }
144
144
  }
@@ -110,13 +110,14 @@ abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(co
110
110
 
111
111
  fun addToMap(existings: Boolean, style: Style, mapView: RCTMGLMapView) {
112
112
  mSource = null
113
- if (existings) {
114
- val existingSource = getSourceAs(style, iD)
115
- if (existingSource != null) {
116
- mSource = existingSource
117
- } else {
118
- Logger.w(LOG_TAG, "Source $iD was makred as existing but was not found in style")
113
+ val existingSource = getSourceAs(style, iD)
114
+ if (existingSource != null) {
115
+ mSource = existingSource
116
+ if (!existings) {
117
+ Logger.w(LOG_TAG, "Source $iD was not marked as existing but found in style, it's deprecated: https://github.com/rnmapbox/maps/wiki/Deprecated-ExistingSourceLayer")
119
118
  }
119
+ } else {
120
+ Logger.w(LOG_TAG, "Source $iD was marked as existing but was not found in style, it's deprecated: https://github.com/rnmapbox/maps/wiki/Deprecated-ExistingSourceLayer")
120
121
  }
121
122
  if (mSource == null) {
122
123
  mSource = makeSource()
@@ -167,19 +167,26 @@ class RCTMGLOfflineModule(private val mReactContext: ReactApplicationContext) :
167
167
  promise.reject(Error("Pack: $name not found"))
168
168
  return
169
169
  }
170
- tileStore.getTileRegionMetadata(name) { expected ->
170
+ tileStore.getTileRegion(name) { expected ->
171
171
  expected.value?.also {
172
- val pack = TileRegionPack(
173
- name= name,
174
- metadata= it.toJSONObject() ?: JSONObject()
175
- )
176
- tileRegionPacks[name] = pack
177
- promise.resolve(_makeRegionStatusPayload(pack))
172
+ val region = it
173
+ tileStore.getTileRegionMetadata(name) { expected ->
174
+ expected.value?.also {
175
+ val pack = TileRegionPack(
176
+ name= name,
177
+ progress= toProgress(region),
178
+ metadata= toJSONObjectSupportingLegacyMetadata(it) ?: JSONObject()
179
+ )
180
+ tileRegionPacks[name] = pack
181
+ promise.resolve(_makeRegionStatusPayload(pack))
182
+ } ?: run {
183
+ promise.reject(LOG_TAG, expected.error!!.message)
184
+ }
185
+ }
178
186
  } ?: run {
179
187
  promise.reject(LOG_TAG, expected.error!!.message)
180
188
  }
181
189
  }
182
-
183
190
  }
184
191
 
185
192
  @ReactMethod
@@ -370,7 +377,7 @@ class RCTMGLOfflineModule(private val mReactContext: ReactApplicationContext) :
370
377
  writableArrayOf(
371
378
  *results.map { (id,geometry_region_metadata) ->
372
379
  val (geometry, region, metadata) = geometry_region_metadata
373
- val metadataJSON = metadata?.toJSONObject()
380
+ val metadataJSON = if (metadata != null) { toJSONObjectSupportingLegacyMetadata(metadata) } else { null }
374
381
  val ret = convertRegionToJSON(region, geometry, metadataJSON)
375
382
  val pack = tileRegionPacks[region.id] ?: TileRegionPack(
376
383
  name= region.id,
@@ -607,6 +614,19 @@ class RCTMGLOfflineModule(private val mReactContext: ReactApplicationContext) :
607
614
  )
608
615
  }
609
616
 
617
+ private fun toJSONObjectSupportingLegacyMetadata(value: Value): JSONObject? {
618
+ // see https://github.com/rnmapbox/maps/issues/2803
619
+ try {
620
+ return value.toJSONObject()
621
+ } catch (err: org.json.JSONException) {
622
+ try {
623
+ return JSONObject(value.toString());
624
+ } catch (_: org.json.JSONException) {
625
+ throw err;
626
+ }
627
+ }
628
+ }
629
+
610
630
  companion object {
611
631
  const val REACT_CLASS = "RCTMGLOfflineModule"
612
632
  const val LOG_TAG = REACT_CLASS
@@ -13,7 +13,7 @@ import org.json.JSONObject
13
13
 
14
14
  fun JSONObject.toGeometry(): Geometry? {
15
15
  when (this.optString("type")) {
16
- "polygon" -> return Polygon.fromJson(this.toString())
16
+ "polygon", "Polygon" -> return Polygon.fromJson(this.toString())
17
17
  else -> {
18
18
  Logger.w("JSONObject", "Unexpected geometry: ${this.toString()}")
19
19
  return null
@@ -189,22 +189,31 @@ class RCTMGLOfflineModule: RCTEventEmitter {
189
189
  func getPackStatus(_ name: String,
190
190
  resolver: @escaping RCTPromiseResolveBlock,
191
191
  rejecter: @escaping RCTPromiseRejectBlock) {
192
- guard let pack = tileRegionPacks[name] else {
192
+ guard tileRegionPacks[name] != nil else {
193
193
  rejecter("RCTMGLOfflineModule.getPackStatus", "pack \(name) not found", nil)
194
194
  return
195
195
  }
196
196
 
197
- tileStore.tileRegionMetadata(forId: name) { result in
197
+ tileStore.tileRegion(forId: name) { result in
198
198
  switch result {
199
- case .success(let metadata):
200
- var pack = TileRegionPack(
201
- name: name,
202
- metadata: logged("RCTMGLOfflineModule.getPackStatus") { metadata as? [String:Any] } ?? [:]
203
- )
204
- self.tileRegionPacks[name] = pack
205
- resolver(self._makeRegionStatusPayload(pack: pack))
199
+ case .success(let region):
200
+ self.tileStore.tileRegionMetadata(forId: name) { result in
201
+ switch result {
202
+ case .success(let metadata):
203
+ var pack = TileRegionPack(
204
+ name: name,
205
+ progress: self.toProgress(region: region),
206
+ metadata: logged("RCTMGLOfflineModule.getPackStatus") { metadata as? [String:Any] } ?? [:]
207
+ )
208
+ self.tileRegionPacks[name] = pack
209
+ resolver(self._makeRegionStatusPayload(pack: pack))
210
+ case .failure(let error):
211
+ Logger.log(level:.error, message: "Unable to fetch metadata for \(name)")
212
+ rejecter("RCTMGLOfflineModule.getPackStatus", error.localizedDescription, error)
213
+ }
214
+ }
206
215
  case .failure(let error):
207
- Logger.log(level:.error, message: "Unable to fetch metadata for \(name)")
216
+ Logger.log(level:.error, message: "Unable to fetch region for \(name)")
208
217
  rejecter("RCTMGLOfflineModule.getPackStatus", error.localizedDescription, error)
209
218
  }
210
219
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rnmapbox/maps",
3
3
  "description": "A Mapbox react native module for creating custom maps",
4
- "version": "10.0.2",
4
+ "version": "10.0.3-beta.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },