@rnmapbox/maps 10.0.1 → 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 +0 -3
- package/android/rctmgl/build.gradle +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTSource.kt +7 -6
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLOfflineModule.kt +29 -9
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/JSONObject.kt +1 -1
- package/ios/RCTMGL-v10/RCTMGLOfflineModule.swift +21 -11
- package/ios/RCTMGL-v10/RCTMGLShapeSource.swift +68 -24
- package/package.json +1 -1
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">→</span> Future of this repo: participate in the [discussion thread](https://github.com/rnmapbox/maps/discussions/1680)
|
|
25
|
-
|
|
26
24
|
#### <span style="color:red">→</span> Call for additional maintainers [discussion thread](https://github.com/rnmapbox/maps/discussions/1551)
|
|
27
25
|
|
|
28
|
-
#### <span style="color:red">→</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.
|
|
141
|
+
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:6.11.0'
|
|
142
142
|
implementation 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0'
|
|
143
143
|
}
|
|
144
144
|
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTSource.kt
CHANGED
|
@@ -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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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.
|
|
170
|
+
tileStore.getTileRegion(name) { expected ->
|
|
171
171
|
expected.value?.also {
|
|
172
|
-
val
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
|
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
|
|
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.
|
|
197
|
+
tileStore.tileRegion(forId: name) { result in
|
|
198
198
|
switch result {
|
|
199
|
-
case .success(let
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
|
216
|
+
Logger.log(level:.error, message: "Unable to fetch region for \(name)")
|
|
208
217
|
rejecter("RCTMGLOfflineModule.getPackStatus", error.localizedDescription, error)
|
|
209
218
|
}
|
|
210
219
|
}
|
|
@@ -486,7 +495,8 @@ class RCTMGLOfflineModule: RCTEventEmitter {
|
|
|
486
495
|
if let expires = region.expires {
|
|
487
496
|
result["expires"] = expires.toJSONString()
|
|
488
497
|
}
|
|
489
|
-
|
|
498
|
+
|
|
499
|
+
return result
|
|
490
500
|
}
|
|
491
501
|
return [:]
|
|
492
502
|
}
|
|
@@ -3,7 +3,25 @@ import Turf
|
|
|
3
3
|
|
|
4
4
|
@objc
|
|
5
5
|
class RCTMGLShapeSource : RCTMGLSource {
|
|
6
|
-
@objc var url : String?
|
|
6
|
+
@objc var url : String? {
|
|
7
|
+
didSet {
|
|
8
|
+
parseJSON(url) { [weak self] result in
|
|
9
|
+
guard let self = self else { return }
|
|
10
|
+
|
|
11
|
+
switch result {
|
|
12
|
+
case .success(let obj):
|
|
13
|
+
self.doUpdate { (style) in
|
|
14
|
+
logged("RCTMGLShapeSource.setUrl") {
|
|
15
|
+
try style.updateGeoJSONSource(withId: self.id, geoJSON: obj)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
case .failure(let error):
|
|
20
|
+
Logger.log(level: .error, message: ":: Error - update url failed \(error) \(error.localizedDescription)")
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
7
25
|
|
|
8
26
|
@objc var shape : String? {
|
|
9
27
|
didSet {
|
|
@@ -18,7 +36,7 @@ class RCTMGLShapeSource : RCTMGLSource {
|
|
|
18
36
|
}
|
|
19
37
|
}
|
|
20
38
|
}
|
|
21
|
-
|
|
39
|
+
|
|
22
40
|
@objc var cluster : NSNumber?
|
|
23
41
|
@objc var clusterRadius : NSNumber?
|
|
24
42
|
@objc var clusterMaxZoomLevel : NSNumber? {
|
|
@@ -35,12 +53,12 @@ class RCTMGLShapeSource : RCTMGLSource {
|
|
|
35
53
|
}
|
|
36
54
|
}
|
|
37
55
|
@objc var clusterProperties : [String: [Any]]?;
|
|
38
|
-
|
|
56
|
+
|
|
39
57
|
@objc var maxZoomLevel : NSNumber?
|
|
40
58
|
@objc var buffer : NSNumber?
|
|
41
59
|
@objc var tolerance : NSNumber?
|
|
42
60
|
@objc var lineMetrics : NSNumber?
|
|
43
|
-
|
|
61
|
+
|
|
44
62
|
override func sourceType() -> Source.Type {
|
|
45
63
|
return GeoJSONSource.self
|
|
46
64
|
}
|
|
@@ -48,7 +66,7 @@ class RCTMGLShapeSource : RCTMGLSource {
|
|
|
48
66
|
override func makeSource() -> Source
|
|
49
67
|
{
|
|
50
68
|
var result = GeoJSONSource()
|
|
51
|
-
|
|
69
|
+
|
|
52
70
|
if let shape = shape {
|
|
53
71
|
do {
|
|
54
72
|
result.data = try parse(shape)
|
|
@@ -57,52 +75,52 @@ class RCTMGLShapeSource : RCTMGLSource {
|
|
|
57
75
|
result.data = emptyShape()
|
|
58
76
|
}
|
|
59
77
|
}
|
|
60
|
-
|
|
78
|
+
|
|
61
79
|
if let url = url {
|
|
62
80
|
result.data = .url(URL(string: url)!)
|
|
63
81
|
}
|
|
64
|
-
|
|
82
|
+
|
|
65
83
|
if let cluster = cluster {
|
|
66
84
|
result.cluster = cluster.boolValue
|
|
67
85
|
}
|
|
68
|
-
|
|
86
|
+
|
|
69
87
|
if let clusterRadius = clusterRadius {
|
|
70
88
|
result.clusterRadius = clusterRadius.doubleValue
|
|
71
89
|
}
|
|
72
|
-
|
|
90
|
+
|
|
73
91
|
if let clusterMaxZoomLevel = clusterMaxZoomLevel {
|
|
74
92
|
result.clusterMaxZoom = clusterMaxZoomLevel.doubleValue
|
|
75
93
|
}
|
|
76
|
-
|
|
94
|
+
|
|
77
95
|
do {
|
|
78
96
|
if let clusterProperties = clusterProperties {
|
|
79
97
|
result.clusterProperties = try clusterProperties.mapValues { (params : [Any]) in
|
|
80
98
|
let data = try JSONSerialization.data(withJSONObject: params, options: .prettyPrinted)
|
|
81
99
|
let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
|
|
82
|
-
|
|
100
|
+
|
|
83
101
|
return decodedExpression
|
|
84
102
|
}
|
|
85
103
|
}
|
|
86
104
|
} catch {
|
|
87
105
|
Logger.log(level: .error, message: "RCTMGLShapeSource.parsing clusterProperties failed", error: error)
|
|
88
106
|
}
|
|
89
|
-
|
|
107
|
+
|
|
90
108
|
if let maxZoomLevel = maxZoomLevel {
|
|
91
109
|
result.maxzoom = maxZoomLevel.doubleValue
|
|
92
110
|
}
|
|
93
|
-
|
|
111
|
+
|
|
94
112
|
if let buffer = buffer {
|
|
95
113
|
result.buffer = buffer.doubleValue
|
|
96
114
|
}
|
|
97
|
-
|
|
115
|
+
|
|
98
116
|
if let tolerance = tolerance {
|
|
99
117
|
result.tolerance = tolerance.doubleValue
|
|
100
118
|
}
|
|
101
|
-
|
|
119
|
+
|
|
102
120
|
if let lineMetrics = lineMetrics {
|
|
103
121
|
result.lineMetrics = lineMetrics.boolValue
|
|
104
122
|
}
|
|
105
|
-
|
|
123
|
+
|
|
106
124
|
return result
|
|
107
125
|
}
|
|
108
126
|
|
|
@@ -112,11 +130,11 @@ class RCTMGLShapeSource : RCTMGLSource {
|
|
|
112
130
|
map.mapboxMap.style.sourceExists(withId: id) else {
|
|
113
131
|
return
|
|
114
132
|
}
|
|
115
|
-
|
|
133
|
+
|
|
116
134
|
let style = map.mapboxMap.style
|
|
117
135
|
update(style)
|
|
118
136
|
}
|
|
119
|
-
|
|
137
|
+
|
|
120
138
|
func updateSource(property: String, value: Any) {
|
|
121
139
|
doUpdate { style in
|
|
122
140
|
try! style.setSourceProperty(for: id, property: property, value: value)
|
|
@@ -124,6 +142,32 @@ class RCTMGLShapeSource : RCTMGLSource {
|
|
|
124
142
|
}
|
|
125
143
|
}
|
|
126
144
|
|
|
145
|
+
// MARK: - parseJSON(url)
|
|
146
|
+
|
|
147
|
+
extension RCTMGLShapeSource
|
|
148
|
+
{
|
|
149
|
+
func parseJSON(_ url: String?, completion: @escaping (Result<GeoJSONObject, Error>) -> Void) {
|
|
150
|
+
guard let url = url else { return }
|
|
151
|
+
|
|
152
|
+
DispatchQueue.global().async { [url] in
|
|
153
|
+
let result: Result<GeoJSONObject, Error>
|
|
154
|
+
|
|
155
|
+
do {
|
|
156
|
+
let data = try Data(contentsOf: URL(string: url)!)
|
|
157
|
+
let obj = try JSONDecoder().decode(GeoJSONObject.self, from: data)
|
|
158
|
+
|
|
159
|
+
result = .success(obj)
|
|
160
|
+
} catch {
|
|
161
|
+
result = .failure(error)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
DispatchQueue.main.async {
|
|
165
|
+
completion(result)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
127
171
|
// MARK: - parse(shape)
|
|
128
172
|
|
|
129
173
|
extension RCTMGLShapeSource
|
|
@@ -145,7 +189,7 @@ extension RCTMGLShapeSource
|
|
|
145
189
|
}
|
|
146
190
|
}
|
|
147
191
|
}
|
|
148
|
-
|
|
192
|
+
|
|
149
193
|
func parse(_ shape: String) throws -> Feature {
|
|
150
194
|
guard let data = shape.data(using: .utf8) else {
|
|
151
195
|
throw RCTMGLError.parseError("shape is not utf8")
|
|
@@ -163,8 +207,8 @@ extension RCTMGLShapeSource
|
|
|
163
207
|
return emptyGeoJSONObject()
|
|
164
208
|
case .feature(let feature):
|
|
165
209
|
return .feature(feature)
|
|
166
|
-
case .featureCollection(let
|
|
167
|
-
return .featureCollection(
|
|
210
|
+
case .featureCollection(let featureCollection):
|
|
211
|
+
return .featureCollection(featureCollection)
|
|
168
212
|
case .geometry(let geometry):
|
|
169
213
|
return .geometry(geometry)
|
|
170
214
|
case .url(_):
|
|
@@ -224,7 +268,7 @@ extension RCTMGLShapeSource
|
|
|
224
268
|
completion(.failure(RCTMGLError.failed("getClusterExpansionZoom: not a number")))
|
|
225
269
|
return
|
|
226
270
|
}
|
|
227
|
-
|
|
271
|
+
|
|
228
272
|
completion(.success(value.intValue))
|
|
229
273
|
case .failure(let error):
|
|
230
274
|
completion(.failure(error))
|
|
@@ -232,7 +276,7 @@ extension RCTMGLShapeSource
|
|
|
232
276
|
}
|
|
233
277
|
}
|
|
234
278
|
}
|
|
235
|
-
|
|
279
|
+
|
|
236
280
|
func getClusterLeaves(_ featureJSON: String,
|
|
237
281
|
number: uint,
|
|
238
282
|
offset: uint,
|
|
@@ -242,7 +286,7 @@ extension RCTMGLShapeSource
|
|
|
242
286
|
completion(.failure(RCTMGLError.failed("getClusterLeaves: no mapView")))
|
|
243
287
|
return
|
|
244
288
|
}
|
|
245
|
-
|
|
289
|
+
|
|
246
290
|
logged("RCTMGLShapeSource.getClusterLeaves", rejecter: { (_,_,error) in
|
|
247
291
|
completion(.failure(error!))
|
|
248
292
|
}) {
|