@rnmapbox/maps 10.0.1 → 10.0.2
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.
|
@@ -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
|
}) {
|