@rnmapbox/maps 10.1.42 → 10.1.43
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/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt +40 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt +65 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/utils/extensions/Map.kt +11 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/utils/writeableMapArrayOf.kt +35 -0
- package/android/src/main/mapbox-v11-compat/v10/com/rnmapbox/rnmbx/v11compat/MapboxMap.kt +26 -1
- package/android/src/main/mapbox-v11-compat/v11/com/rnmapbox/rnmbx/v11compat/MapboxMap.kt +28 -1
- package/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeMapViewModuleSpec.java +13 -0
- package/ios/RNMBX/RNMBXCameraViewManager.m +3 -0
- package/ios/RNMBX/RNMBXCameraViewManager.swift +10 -8
- package/ios/RNMBX/RNMBXCircleLayerComponentView.mm +1 -1
- package/ios/RNMBX/RNMBXCircleLayerViewManager.m +2 -0
- package/ios/RNMBX/RNMBXCircleLayerViewManager.swift +2 -0
- package/ios/RNMBX/RNMBXMapViewManager.m +2 -0
- package/ios/RNMBX/RNMBXMapViewManager.swift +321 -178
- package/ios/RNMBX/RNMBXMapViewModule.h +3 -2
- package/ios/RNMBX/RNMBXMapViewModule.mm +28 -19
- package/ios/RNMBX/RNMBXShapeSourceViewManager.m +2 -0
- package/ios/RNMBX/RNMBXShapeSourceViewManager.swift +52 -47
- package/ios/RNMBX/ShapeAnimators/RNMBXMovePointShapeAnimatorModule.mm +2 -2
- package/ios/RNMBX/ShapeAnimators/RNMBXMovePointShapeAnimatorModule.swift +1 -1
- package/ios/RNMBX/Utils/RNMBXViewResolver.h +45 -0
- package/ios/RNMBX/Utils/RNMBXViewResolver.mm +134 -0
- package/lib/commonjs/components/Images.js +1 -1
- package/lib/commonjs/components/Images.js.map +1 -1
- package/lib/commonjs/components/MapView.js +60 -3
- package/lib/commonjs/components/MapView.js.map +1 -1
- package/lib/commonjs/specs/NativeMapViewModule.js.map +1 -1
- package/lib/module/components/Images.js +1 -1
- package/lib/module/components/Images.js.map +1 -1
- package/lib/module/components/MapView.js +59 -2
- package/lib/module/components/MapView.js.map +1 -1
- package/lib/module/specs/NativeMapViewModule.js.map +1 -1
- package/lib/typescript/src/components/MapView.d.ts +35 -0
- package/lib/typescript/src/components/MapView.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeMapViewModule.d.ts +3 -0
- package/lib/typescript/src/specs/NativeMapViewModule.d.ts.map +1 -1
- package/package.json +133 -2
- package/rnmapbox-maps.podspec +2 -1
- package/setup-jest.js +3 -0
- package/src/components/Images.tsx +1 -1
- package/src/components/MapView.tsx +92 -2
- package/src/specs/NativeMapViewModule.ts +20 -0
|
@@ -1,230 +1,373 @@
|
|
|
1
1
|
import MapboxMaps
|
|
2
2
|
|
|
3
3
|
#if RNMBX_11
|
|
4
|
-
extension QueriedSourceFeature {
|
|
5
|
-
|
|
6
|
-
}
|
|
4
|
+
extension QueriedSourceFeature {
|
|
5
|
+
var feature: Feature { return self.queriedFeature.feature }
|
|
6
|
+
}
|
|
7
7
|
#endif
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
#if !RCT_NEW_ARCH_ENABLED
|
|
10
|
+
|
|
11
|
+
@objc(RNMBXMapViewManager)
|
|
12
|
+
open class RNMBXMapViewManager: RCTViewManager {
|
|
11
13
|
@objc
|
|
12
14
|
override public static func requiresMainQueueSetup() -> Bool {
|
|
13
|
-
|
|
15
|
+
return false
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
|
|
16
18
|
func defaultFrame() -> CGRect {
|
|
17
|
-
|
|
19
|
+
return UIScreen.main.bounds
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
|
|
20
22
|
override open func view() -> UIView! {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
let result = RNMBXMapView(
|
|
24
|
+
frame: self.defaultFrame(), eventDispatcher: self.bridge.eventDispatcher())
|
|
25
|
+
return result
|
|
23
26
|
}
|
|
24
|
-
}
|
|
27
|
+
}
|
|
28
|
+
#else
|
|
29
|
+
@objc(RNMBXMapViewManager)
|
|
30
|
+
open class RNMBXMapViewManager: NSObject {
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
#endif
|
|
25
34
|
|
|
26
35
|
// MARK: - react methods
|
|
27
36
|
|
|
28
37
|
extension RNMBXMapViewManager {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@objc public static func setSourceVisibility(_ view: RNMBXMapView,
|
|
50
|
-
visible: Bool,
|
|
51
|
-
sourceId: String,
|
|
52
|
-
sourceLayerId: String?,
|
|
53
|
-
resolver: @escaping RCTPromiseResolveBlock,
|
|
54
|
-
rejecter: @escaping RCTPromiseRejectBlock) -> Void {
|
|
55
|
-
view.setSourceVisibility(visible, sourceId: sourceId, sourceLayerId:sourceLayerId)
|
|
56
|
-
resolver(nil)
|
|
38
|
+
@objc public static func takeSnap(
|
|
39
|
+
_ view: RNMBXMapView,
|
|
40
|
+
writeToDisk: Bool,
|
|
41
|
+
resolver: @escaping RCTPromiseResolveBlock
|
|
42
|
+
) {
|
|
43
|
+
let uri = view.takeSnap(writeToDisk: writeToDisk)
|
|
44
|
+
resolver(["uri": uri.absoluteString])
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@objc public static func queryTerrainElevation(
|
|
48
|
+
_ view: RNMBXMapView,
|
|
49
|
+
coordinates: [NSNumber],
|
|
50
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
51
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
52
|
+
) {
|
|
53
|
+
let result = view.queryTerrainElevation(coordinates: coordinates)
|
|
54
|
+
if let result = result {
|
|
55
|
+
resolver(["data": NSNumber(value: result)])
|
|
56
|
+
} else {
|
|
57
|
+
resolver(nil)
|
|
57
58
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@objc public static func setSourceVisibility(
|
|
62
|
+
_ view: RNMBXMapView,
|
|
63
|
+
visible: Bool,
|
|
64
|
+
sourceId: String,
|
|
65
|
+
sourceLayerId: String?,
|
|
66
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
67
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
68
|
+
) {
|
|
69
|
+
view.setSourceVisibility(visible, sourceId: sourceId, sourceLayerId: sourceLayerId)
|
|
70
|
+
resolver(nil)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@objc public static func getCenter(
|
|
74
|
+
_ view: RNMBXMapView, resolver: @escaping RCTPromiseResolveBlock,
|
|
75
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
76
|
+
) {
|
|
77
|
+
view.withMapboxMap { map in
|
|
78
|
+
resolver([
|
|
79
|
+
"center": [
|
|
80
|
+
map.cameraState.center.longitude,
|
|
81
|
+
map.cameraState.center.latitude,
|
|
82
|
+
]
|
|
83
|
+
])
|
|
66
84
|
}
|
|
85
|
+
}
|
|
67
86
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
@objc public static func getCoordinateFromView(
|
|
88
|
+
_ view: RNMBXMapView,
|
|
89
|
+
atPoint point: CGPoint,
|
|
90
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
91
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
92
|
+
) {
|
|
93
|
+
view.withMapboxMap { map in
|
|
94
|
+
let coordinates = map.coordinate(for: point)
|
|
95
|
+
resolver(["coordinateFromView": [coordinates.longitude, coordinates.latitude]])
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@objc public static func getPointInView(
|
|
101
|
+
_ view: RNMBXMapView,
|
|
102
|
+
atCoordinate coordinate: [NSNumber],
|
|
103
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
104
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
105
|
+
) {
|
|
106
|
+
view.withMapboxMap { map in
|
|
107
|
+
let coordinate = CLLocationCoordinate2DMake(
|
|
108
|
+
coordinate[1].doubleValue, coordinate[0].doubleValue)
|
|
109
|
+
let point = map.point(for: coordinate)
|
|
110
|
+
resolver(["pointInView": [(point.x), (point.y)]])
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@objc public static func setHandledMapChangedEvents(
|
|
115
|
+
_ view: RNMBXMapView,
|
|
116
|
+
events: [String],
|
|
117
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
118
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
119
|
+
) {
|
|
120
|
+
view.handleMapChangedEvents = Set(
|
|
121
|
+
events.compactMap {
|
|
122
|
+
RNMBXEvent.EventType(rawValue: $0)
|
|
123
|
+
})
|
|
124
|
+
resolver(nil)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@objc public static func getZoom(
|
|
128
|
+
_ view: RNMBXMapView,
|
|
129
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
130
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
131
|
+
) {
|
|
132
|
+
view.withMapboxMap { map in
|
|
133
|
+
resolver(["zoom": map.cameraState.zoom])
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@objc public static func getVisibleBounds(
|
|
138
|
+
_ view: RNMBXMapView,
|
|
139
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
140
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
141
|
+
) {
|
|
142
|
+
view.withMapboxMap { map in
|
|
143
|
+
resolver(["visibleBounds": map.coordinateBounds(for: view.bounds).toArray()])
|
|
144
|
+
}
|
|
145
|
+
}
|
|
91
146
|
|
|
92
|
-
@objc public static func setHandledMapChangedEvents(
|
|
93
|
-
_ view: RNMBXMapView,
|
|
94
|
-
events: [String],
|
|
95
|
-
resolver: @escaping RCTPromiseResolveBlock,
|
|
96
|
-
rejecter: @escaping RCTPromiseRejectBlock) {
|
|
97
|
-
view.handleMapChangedEvents = Set(events.compactMap {
|
|
98
|
-
RNMBXEvent.EventType(rawValue: $0)
|
|
99
|
-
})
|
|
100
|
-
resolver(nil);
|
|
101
|
-
}
|
|
102
147
|
|
|
103
|
-
@objc public static func
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
148
|
+
@objc public static func setFeatureState(
|
|
149
|
+
_ view: RNMBXMapView,
|
|
150
|
+
featureId: String,
|
|
151
|
+
state: [String : Any],
|
|
152
|
+
sourceId: String,
|
|
153
|
+
sourceLayerId: String?,
|
|
154
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
155
|
+
rejecter: @escaping RCTPromiseRejectBlock) {
|
|
156
|
+
view.withMapboxMap { map in
|
|
157
|
+
#if RNMBX_11
|
|
158
|
+
map.setFeatureState(
|
|
159
|
+
sourceId: sourceId,
|
|
160
|
+
sourceLayerId: sourceLayerId,
|
|
161
|
+
featureId: featureId,
|
|
162
|
+
state: state
|
|
163
|
+
) { result in
|
|
164
|
+
switch result {
|
|
165
|
+
case .success: resolver(nil)
|
|
166
|
+
case .failure(let error): rejecter("setFeatureState", "failed to set feature state", error)
|
|
167
|
+
}
|
|
109
168
|
}
|
|
169
|
+
#else
|
|
170
|
+
map.setFeatureState(
|
|
171
|
+
sourceId: sourceId,
|
|
172
|
+
sourceLayerId: sourceLayerId,
|
|
173
|
+
featureId: featureId,
|
|
174
|
+
state: state
|
|
175
|
+
)
|
|
176
|
+
resolver(nil)
|
|
177
|
+
#endif
|
|
178
|
+
}
|
|
110
179
|
}
|
|
111
180
|
|
|
112
|
-
@objc public static func
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
181
|
+
@objc public static func getFeatureState(
|
|
182
|
+
_ view: RNMBXMapView,
|
|
183
|
+
featureId: String,
|
|
184
|
+
sourceId: String,
|
|
185
|
+
sourceLayerId: String?,
|
|
186
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
187
|
+
rejecter: @escaping RCTPromiseRejectBlock) {
|
|
188
|
+
view.withMapboxMap { map in
|
|
189
|
+
map.getFeatureState(
|
|
190
|
+
sourceId: sourceId,
|
|
191
|
+
sourceLayerId: sourceLayerId,
|
|
192
|
+
featureId: featureId
|
|
193
|
+
) { result in
|
|
194
|
+
switch (result) {
|
|
195
|
+
case .success(let featureState):
|
|
196
|
+
resolver(["featureState": featureState])
|
|
197
|
+
case .failure(let error):
|
|
198
|
+
rejecter("getFeatureState", "failed to get feature state", error)
|
|
199
|
+
}
|
|
118
200
|
}
|
|
201
|
+
}
|
|
119
202
|
}
|
|
120
203
|
|
|
204
|
+
@objc public static func removeFeatureState(
|
|
205
|
+
_ view: RNMBXMapView,
|
|
206
|
+
featureId: String,
|
|
207
|
+
stateKey: String?,
|
|
208
|
+
sourceId: String,
|
|
209
|
+
sourceLayerId: String?,
|
|
210
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
211
|
+
rejecter: @escaping RCTPromiseRejectBlock) {
|
|
212
|
+
view.withMapboxMap { map in
|
|
213
|
+
#if RNMBX_11
|
|
214
|
+
map.removeFeatureState(
|
|
215
|
+
sourceId: sourceId,
|
|
216
|
+
sourceLayerId: sourceLayerId,
|
|
217
|
+
featureId: featureId,
|
|
218
|
+
stateKey: stateKey
|
|
219
|
+
) { result in
|
|
220
|
+
switch result {
|
|
221
|
+
case .success: resolver(nil)
|
|
222
|
+
case .failure(let error): rejecter("removeFeatureState", "failed to remove feature state", error)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
#else
|
|
226
|
+
map.removeFeatureState(
|
|
227
|
+
sourceId: sourceId,
|
|
228
|
+
sourceLayerId: sourceLayerId,
|
|
229
|
+
featureId: featureId,
|
|
230
|
+
stateKey: stateKey
|
|
231
|
+
)
|
|
232
|
+
resolver(nil)
|
|
233
|
+
#endif
|
|
234
|
+
}
|
|
235
|
+
}
|
|
121
236
|
}
|
|
122
237
|
|
|
123
238
|
// MARK: - queryRenderedFeatures
|
|
124
239
|
|
|
125
240
|
extension RNMBXMapViewManager {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
241
|
+
@objc public static func queryRenderedFeaturesAtPoint(
|
|
242
|
+
_ view: RNMBXMapView,
|
|
243
|
+
atPoint point: [NSNumber],
|
|
244
|
+
withFilter filter: [Any]?,
|
|
245
|
+
withLayerIDs layerIDs: [String]?,
|
|
246
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
247
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
248
|
+
) {
|
|
249
|
+
view.withMapboxMap { map in
|
|
250
|
+
let point = CGPoint(x: CGFloat(point[0].floatValue), y: CGFloat(point[1].floatValue))
|
|
251
|
+
|
|
252
|
+
logged("queryRenderedFeaturesAtPoint.option", rejecter: rejecter) {
|
|
253
|
+
let options = try RenderedQueryOptions(
|
|
254
|
+
layerIds: (layerIDs ?? []).isEmpty ? nil : layerIDs, filter: filter?.asExpression())
|
|
255
|
+
|
|
256
|
+
map.queryRenderedFeatures(with: point, options: options) { result in
|
|
257
|
+
switch result {
|
|
258
|
+
case .success(let features):
|
|
259
|
+
resolver([
|
|
260
|
+
"data": [
|
|
261
|
+
"type": "FeatureCollection",
|
|
262
|
+
"features": features.compactMap { queriedFeature in
|
|
263
|
+
logged("queryRenderedFeaturesAtPoint.feature.toJSON") {
|
|
264
|
+
try queriedFeature.feature.toJSON()
|
|
149
265
|
}
|
|
150
|
-
}
|
|
151
|
-
|
|
266
|
+
},
|
|
267
|
+
]
|
|
268
|
+
])
|
|
269
|
+
case .failure(let error):
|
|
270
|
+
rejecter("queryRenderedFeaturesAtPoint", "failed to query features", error)
|
|
152
271
|
}
|
|
272
|
+
}
|
|
153
273
|
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
154
276
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
277
|
+
@objc public static func queryRenderedFeaturesInRect(
|
|
278
|
+
_ map: RNMBXMapView,
|
|
279
|
+
withBBox bbox: [NSNumber],
|
|
280
|
+
withFilter filter: [Any]?,
|
|
281
|
+
withLayerIDs layerIDs: [String]?,
|
|
282
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
283
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
284
|
+
) {
|
|
285
|
+
let top = bbox.isEmpty ? 0.0 : CGFloat(bbox[0].floatValue)
|
|
286
|
+
let right = bbox.isEmpty ? 0.0 : CGFloat(bbox[1].floatValue)
|
|
287
|
+
let bottom = bbox.isEmpty ? 0.0 : CGFloat(bbox[2].floatValue)
|
|
288
|
+
let left = bbox.isEmpty ? 0.0 : CGFloat(bbox[3].floatValue)
|
|
289
|
+
let rect =
|
|
290
|
+
bbox.isEmpty
|
|
291
|
+
? CGRect(x: 0.0, y: 0.0, width: map.bounds.size.width, height: map.bounds.size.height)
|
|
292
|
+
: CGRect(
|
|
293
|
+
x: [left, right].min()!, y: [top, bottom].min()!, width: abs(right - left),
|
|
294
|
+
height: abs(bottom - top))
|
|
295
|
+
logged("queryRenderedFeaturesInRect.option", rejecter: rejecter) {
|
|
296
|
+
let options = try RenderedQueryOptions(
|
|
297
|
+
layerIds: layerIDs?.isEmpty ?? true ? nil : layerIDs, filter: filter?.asExpression())
|
|
298
|
+
map.mapboxMap.queryRenderedFeatures(with: rect, options: options) { result in
|
|
299
|
+
switch result {
|
|
300
|
+
case .success(let features):
|
|
301
|
+
resolver([
|
|
302
|
+
"data": [
|
|
303
|
+
"type": "FeatureCollection",
|
|
304
|
+
"features": features.compactMap { queriedFeature in
|
|
305
|
+
logged("queryRenderedFeaturesInRect.queriedfeature.map") {
|
|
306
|
+
try queriedFeature.feature.toJSON()
|
|
179
307
|
}
|
|
180
|
-
}
|
|
181
|
-
|
|
308
|
+
},
|
|
309
|
+
]
|
|
310
|
+
])
|
|
311
|
+
case .failure(let error):
|
|
312
|
+
rejecter("queryRenderedFeaturesInRect", "failed to query features", error)
|
|
182
313
|
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
183
317
|
|
|
184
|
-
|
|
318
|
+
@objc public static func querySourceFeatures(
|
|
185
319
|
_ map: RNMBXMapView,
|
|
186
320
|
withSourceId sourceId: String,
|
|
187
321
|
withFilter filter: [Any]?,
|
|
188
322
|
withSourceLayerIds sourceLayerIds: [String]?,
|
|
189
323
|
resolver: @escaping RCTPromiseResolveBlock,
|
|
190
|
-
rejecter: @escaping RCTPromiseRejectBlock
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
324
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
325
|
+
) {
|
|
326
|
+
let sourceLayerIds = sourceLayerIds?.isEmpty ?? true ? nil : sourceLayerIds
|
|
327
|
+
logged("querySourceFeatures.option", rejecter: rejecter) {
|
|
328
|
+
let options = SourceQueryOptions(
|
|
329
|
+
sourceLayerIds: sourceLayerIds, filter: filter ?? Exp(arguments: []))
|
|
330
|
+
map.mapboxMap.querySourceFeatures(for: sourceId, options: options) { result in
|
|
331
|
+
switch result {
|
|
332
|
+
case .success(let features):
|
|
333
|
+
resolver([
|
|
334
|
+
"data": [
|
|
335
|
+
"type": "FeatureCollection",
|
|
336
|
+
"features": features.compactMap { queriedFeature in
|
|
337
|
+
logged("querySourceFeatures.queriedfeature.map") {
|
|
338
|
+
try queriedFeature.feature.toJSON()
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
] as [String: Any]
|
|
342
|
+
])
|
|
343
|
+
case .failure(let error):
|
|
344
|
+
rejecter(
|
|
345
|
+
"querySourceFeatures",
|
|
346
|
+
"failed to query source features: \(error.localizedDescription)", error)
|
|
205
347
|
}
|
|
206
348
|
}
|
|
207
349
|
}
|
|
350
|
+
}
|
|
208
351
|
|
|
209
|
-
|
|
210
|
-
|
|
352
|
+
static func clearData(_ view: RNMBXMapView, completion: @escaping (Error?) -> Void) {
|
|
353
|
+
#if RNMBX_11
|
|
211
354
|
MapboxMap.clearData(completion: completion)
|
|
212
|
-
|
|
355
|
+
#else
|
|
213
356
|
view.mapboxMap.clearData(completion: completion)
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
357
|
+
#endif
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
@objc public static func clearData(
|
|
361
|
+
_ mapView: RNMBXMapView,
|
|
362
|
+
resolver: @escaping RCTPromiseResolveBlock,
|
|
363
|
+
rejecter: @escaping RCTPromiseRejectBlock
|
|
364
|
+
) {
|
|
365
|
+
self.clearData(mapView) { error in
|
|
366
|
+
if let error = error {
|
|
367
|
+
rejecter("clearData", "failed to clearData: \(error.localizedDescription)", error)
|
|
368
|
+
} else {
|
|
369
|
+
resolver(nil)
|
|
370
|
+
}
|
|
229
371
|
}
|
|
372
|
+
}
|
|
230
373
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#import <Foundation/Foundation.h>
|
|
2
2
|
#import <UIKit/UIKit.h>
|
|
3
|
+
#import "RNMBXViewResolver.h"
|
|
3
4
|
|
|
4
5
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
5
6
|
#import "rnmapbox_maps_specs.h"
|
|
@@ -9,9 +10,9 @@
|
|
|
9
10
|
|
|
10
11
|
@interface RNMBXMapViewModule : NSObject
|
|
11
12
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
12
|
-
<NativeMapViewModuleSpec>
|
|
13
|
+
<NativeMapViewModuleSpec, RNMBXViewResolverDelegate>
|
|
13
14
|
#else
|
|
14
|
-
<RCTBridgeModule>
|
|
15
|
+
<RCTBridgeModule, RNMBXViewResolverDelegate>
|
|
15
16
|
#endif
|
|
16
17
|
|
|
17
18
|
@end
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#endif // RCT_NEW_ARCH_ENABLED
|
|
9
9
|
|
|
10
10
|
#import "rnmapbox_maps-Swift.pre.h"
|
|
11
|
+
#import "RNMBXViewResolver.h"
|
|
11
12
|
|
|
12
13
|
@implementation RNMBXMapViewModule
|
|
13
14
|
|
|
@@ -27,26 +28,16 @@ RCT_EXPORT_MODULE();
|
|
|
27
28
|
|
|
28
29
|
- (void)withMapView:(nonnull NSNumber*)viewRef block:(void (^)(RNMBXMapView *))block reject:(RCTPromiseRejectBlock)reject methodName:(NSString *)methodName
|
|
29
30
|
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
39
|
-
RNMBXMapView *view = [uiManager viewForReactTag:viewRef];
|
|
40
|
-
#endif // RCT_NEW_ARCH_ENABLED
|
|
41
|
-
if (view != nil) {
|
|
42
|
-
block(view);
|
|
43
|
-
} else {
|
|
44
|
-
reject(methodName, [NSString stringWithFormat:@"Unknown reactTag: %@", viewRef], nil);
|
|
45
|
-
}
|
|
46
|
-
}];
|
|
31
|
+
[RNMBXViewResolver withViewRef:viewRef
|
|
32
|
+
delegate:self
|
|
33
|
+
expectedClass:[RNMBXMapView class]
|
|
34
|
+
block:^(UIView *view) {
|
|
35
|
+
block((RNMBXMapView *)view);
|
|
36
|
+
}
|
|
37
|
+
reject:reject
|
|
38
|
+
methodName:methodName];
|
|
47
39
|
}
|
|
48
40
|
|
|
49
|
-
|
|
50
41
|
RCT_EXPORT_METHOD(takeSnap:(nonnull NSNumber*)viewRef writeToDisk:(BOOL)writeToDisk resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
51
42
|
{
|
|
52
43
|
[self withMapView:viewRef block:^(RNMBXMapView *view) {
|
|
@@ -72,7 +63,7 @@ RCT_EXPORT_METHOD(getCoordinateFromView:(nonnull NSNumber*)viewRef atPoint:(NSAr
|
|
|
72
63
|
[self withMapView:viewRef block:^(RNMBXMapView *view) {
|
|
73
64
|
NSNumber* a = [atPoint objectAtIndex:0];
|
|
74
65
|
NSNumber* b = [atPoint objectAtIndex:1];
|
|
75
|
-
|
|
66
|
+
|
|
76
67
|
[RNMBXMapViewManager getCoordinateFromView:view atPoint:CGPointMake(a.floatValue, b.floatValue) resolver:resolve rejecter:reject];
|
|
77
68
|
} reject:reject methodName:@"getCoordinateFromView"];
|
|
78
69
|
}
|
|
@@ -133,6 +124,24 @@ RCT_EXPORT_METHOD(setSourceVisibility:(nonnull NSNumber*)viewRef visible:(BOOL)v
|
|
|
133
124
|
} reject:reject methodName:@"setSourceVisibility"];
|
|
134
125
|
}
|
|
135
126
|
|
|
127
|
+
RCT_EXPORT_METHOD(setFeatureState:(nonnull NSNumber*)viewRef featureId:(nonnull NSString *)featureId state:(nonnull NSDictionary<NSString*,id> *)state sourceId:(NSString *)sourceId sourceLayerId:(NSString *)sourceLayerId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
128
|
+
[self withMapView:viewRef block:^(RNMBXMapView *view) {
|
|
129
|
+
[RNMBXMapViewManager setFeatureState:view featureId:featureId state:state sourceId:sourceId sourceLayerId:sourceLayerId resolver:resolve rejecter:reject];
|
|
130
|
+
} reject:reject methodName:@"setFeatureState"];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
RCT_EXPORT_METHOD(getFeatureState:(nonnull NSNumber*)viewRef featureId:(nonnull NSString *)featureId sourceId:(nonnull NSString *)sourceId sourceLayerId:(NSString *)sourceLayerId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
134
|
+
[self withMapView:viewRef block:^(RNMBXMapView *view) {
|
|
135
|
+
[RNMBXMapViewManager getFeatureState:view featureId:featureId sourceId:sourceId sourceLayerId:sourceLayerId resolver:resolve rejecter:reject];
|
|
136
|
+
} reject:reject methodName:@"getFeatureState"];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
RCT_EXPORT_METHOD(removeFeatureState:(nonnull NSNumber*)viewRef featureId:(nonnull NSString *)featureId stateKey:(NSString*)stateKey sourceId:(NSString *)sourceId sourceLayerId:(NSString *)sourceLayerId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
140
|
+
[self withMapView:viewRef block:^(RNMBXMapView *view) {
|
|
141
|
+
[RNMBXMapViewManager removeFeatureState:view featureId:featureId stateKey:stateKey sourceId:sourceId sourceLayerId:sourceLayerId resolver:resolve rejecter:reject];
|
|
142
|
+
} reject:reject methodName:@"removeFeatureState"];
|
|
143
|
+
}
|
|
144
|
+
|
|
136
145
|
RCT_EXPORT_METHOD(querySourceFeatures:(nonnull NSNumber*)viewRef sourceId:(NSString*)sourceId withFilter:(NSArray<id>*)withFilter withSourceLayerIDs:(NSArray<NSString*>*)withSourceLayerIDs resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
137
146
|
[self withMapView:viewRef block:^(RNMBXMapView *view) {
|
|
138
147
|
[RNMBXMapViewManager querySourceFeatures:view withSourceId:sourceId withFilter:withFilter withSourceLayerIds:withSourceLayerIDs resolver:resolve rejecter:reject];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#if !RCT_NEW_ARCH_ENABLED
|
|
1
2
|
#import <React/RCTBridgeModule.h>
|
|
2
3
|
#import <React/RCTViewManager.h>
|
|
3
4
|
|
|
@@ -24,3 +25,4 @@ RCT_EXPORT_VIEW_PROPERTY(hitbox, NSDictionary)
|
|
|
24
25
|
RCT_REMAP_VIEW_PROPERTY(onMapboxShapeSourcePress, onPress, RCTBubblingEventBlock)
|
|
25
26
|
|
|
26
27
|
@end
|
|
28
|
+
#endif
|