@rnmapbox/maps 10.1.21 → 10.1.22
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/build.gradle +14 -4
- package/ios/RNMBX/RNMBXMapView.swift +24 -10
- package/ios/RNMBX/RNMBXMapViewManager.swift +36 -58
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -13,6 +13,15 @@ def isNewArchitectureEnabled() {
|
|
|
13
13
|
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
def getKotlinVersion() {
|
|
18
|
+
return rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '1.6.21'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
def getCoroutinesVersion(kotlinVersion) {
|
|
22
|
+
return kotlinVersion >= '1.9' ? '1.8.0' : '1.6.4'
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
// expo plugin
|
|
17
26
|
if (rootProject.ext.has('expoRNMapboxMapsImpl')) {
|
|
18
27
|
rootProject.ext.set('RNMapboxMapsImpl', rootProject.ext.get('expoRNMapboxMapsImpl'))
|
|
@@ -21,6 +30,7 @@ if (rootProject.ext.has('expoRNMapboxMapsVersion')) {
|
|
|
21
30
|
rootProject.ext.set('RNMapboxMapsVersion', rootProject.ext.get('expoRNMapboxMapsVersion'))
|
|
22
31
|
}
|
|
23
32
|
|
|
33
|
+
project.ext.set("kotlinVersion", getKotlinVersion())
|
|
24
34
|
|
|
25
35
|
buildscript {
|
|
26
36
|
repositories {
|
|
@@ -28,8 +38,9 @@ buildscript {
|
|
|
28
38
|
mavenCentral()
|
|
29
39
|
}
|
|
30
40
|
|
|
41
|
+
def kotlinVersion = this.kotlinVersion
|
|
31
42
|
dependencies {
|
|
32
|
-
|
|
43
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
|
|
33
44
|
}
|
|
34
45
|
}
|
|
35
46
|
|
|
@@ -142,9 +153,8 @@ dependencies {
|
|
|
142
153
|
// React Native
|
|
143
154
|
implementation "com.facebook.react:react-native:+"
|
|
144
155
|
|
|
145
|
-
|
|
146
|
-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-
|
|
147
|
-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${safeExtGet('kotlinxCoroutinesAndroidVersion', '1.8.0')}"
|
|
156
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${safeExtGet('kotlinxCoroutinesCoreVersion', getCoroutinesVersion(getKotlinVersion()))}"
|
|
157
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${safeExtGet('kotlinxCoroutinesAndroidVersion', getCoroutinesVersion(getKotlinVersion()))}"
|
|
148
158
|
|
|
149
159
|
// Mapbox SDK
|
|
150
160
|
customizableDependencies('RNMapboxMapsLibs') {
|
|
@@ -171,7 +171,7 @@ open class RNMBXMapView: UIView {
|
|
|
171
171
|
}()
|
|
172
172
|
|
|
173
173
|
var _mapView: MapView! = nil
|
|
174
|
-
func createMapView() {
|
|
174
|
+
func createMapView() -> MapView {
|
|
175
175
|
if let mapViewImpl = mapViewImpl, let mapViewInstance = createAndAddMapViewImpl(mapViewImpl, self) {
|
|
176
176
|
_mapView = mapViewInstance
|
|
177
177
|
} else {
|
|
@@ -192,6 +192,7 @@ open class RNMBXMapView: UIView {
|
|
|
192
192
|
_mapView.gestures.delegate = self
|
|
193
193
|
setupEvents()
|
|
194
194
|
afterMapViewAdded()
|
|
195
|
+
return _mapView
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
func createAndAddMapViewImpl(_ impl: String, _ view: RNMBXMapView) -> MapView? {
|
|
@@ -203,17 +204,20 @@ open class RNMBXMapView: UIView {
|
|
|
203
204
|
}
|
|
204
205
|
}
|
|
205
206
|
|
|
207
|
+
@available(*, deprecated, renamed: "withMapView", message: "mapView can be nil if the map initialization has not finished, use withMapView instead")
|
|
206
208
|
public var mapView : MapView! {
|
|
207
209
|
get { return _mapView }
|
|
208
210
|
}
|
|
211
|
+
|
|
212
|
+
@available(*, deprecated, renamed: "withMapboxMap", message: "mapboxMap can be nil if the map initialization has not finished, use withMapboxMap instead")
|
|
209
213
|
var mapboxMap: MapboxMap! {
|
|
210
|
-
get { _mapView
|
|
214
|
+
get { _mapView?.mapboxMap }
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
@objc public func addToMap(_ subview: UIView) {
|
|
214
|
-
withMapView {
|
|
218
|
+
withMapView { mapView in
|
|
215
219
|
if let mapComponent = subview as? RNMBXMapComponent {
|
|
216
|
-
let style =
|
|
220
|
+
let style = mapView.mapboxMap.style
|
|
217
221
|
var addToMap = false
|
|
218
222
|
if mapComponent.waitForStyleLoad() {
|
|
219
223
|
if (self.styleLoaded) {
|
|
@@ -303,7 +307,7 @@ open class RNMBXMapView: UIView {
|
|
|
303
307
|
|
|
304
308
|
// MARK: - React Native properties
|
|
305
309
|
let changes : PropertyChanges<RNMBXMapView> = PropertyChanges()
|
|
306
|
-
var mapViewWaiters : [()->Void] = []
|
|
310
|
+
var mapViewWaiters : [(_: MapView)->Void] = []
|
|
307
311
|
|
|
308
312
|
enum Property : String {
|
|
309
313
|
case projection
|
|
@@ -363,14 +367,24 @@ open class RNMBXMapView: UIView {
|
|
|
363
367
|
changes.add(name: property.rawValue, update: property.apply)
|
|
364
368
|
}
|
|
365
369
|
|
|
366
|
-
func withMapView(callback: @escaping () -> Void) {
|
|
367
|
-
if
|
|
368
|
-
callback()
|
|
370
|
+
func withMapView(callback: @escaping (_: MapView) -> Void) {
|
|
371
|
+
if let mapView = _mapView {
|
|
372
|
+
callback(mapView)
|
|
369
373
|
} else {
|
|
370
374
|
mapViewWaiters.append(callback)
|
|
371
375
|
}
|
|
372
376
|
}
|
|
373
377
|
|
|
378
|
+
func withMapboxMap(callback: @escaping (_: MapboxMap) -> Void) {
|
|
379
|
+
if let mapboxMap = _mapView?.mapboxMap {
|
|
380
|
+
callback(mapboxMap)
|
|
381
|
+
} else {
|
|
382
|
+
mapViewWaiters.append { mapView in
|
|
383
|
+
callback(mapView.mapboxMap)
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
374
388
|
var projection: StyleProjection?
|
|
375
389
|
|
|
376
390
|
@objc public func setReactProjection(_ value: String?) {
|
|
@@ -698,9 +712,9 @@ open class RNMBXMapView: UIView {
|
|
|
698
712
|
|
|
699
713
|
@objc override public func didSetProps(_ props: [String]) {
|
|
700
714
|
if (_mapView == nil) {
|
|
701
|
-
createMapView()
|
|
715
|
+
let view = createMapView()
|
|
702
716
|
|
|
703
|
-
mapViewWaiters.forEach { $0() }
|
|
717
|
+
mapViewWaiters.forEach { $0(view) }
|
|
704
718
|
mapViewWaiters.removeAll()
|
|
705
719
|
}
|
|
706
720
|
changes.apply(self)
|
|
@@ -23,25 +23,6 @@ open class RNMBXMapViewManager: RCTViewManager {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
// MARK: helpers
|
|
27
|
-
|
|
28
|
-
extension RNMBXMapViewManager {
|
|
29
|
-
static func withMapboxMap(
|
|
30
|
-
_ view: RNMBXMapView,
|
|
31
|
-
name: String,
|
|
32
|
-
rejecter: @escaping RCTPromiseRejectBlock,
|
|
33
|
-
fn: @escaping (_: MapboxMap) -> Void) -> Void
|
|
34
|
-
{
|
|
35
|
-
guard let mapboxMap = view.mapboxMap else {
|
|
36
|
-
RNMBXLogError("MapboxMap is not yet available");
|
|
37
|
-
rejecter(name, "Map not loaded yet", nil)
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
fn(mapboxMap)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
26
|
// MARK: - react methods
|
|
46
27
|
|
|
47
28
|
extension RNMBXMapViewManager {
|
|
@@ -76,12 +57,12 @@ extension RNMBXMapViewManager {
|
|
|
76
57
|
}
|
|
77
58
|
|
|
78
59
|
@objc public static func getCenter(_ view: RNMBXMapView, resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
60
|
+
view.withMapboxMap { map in
|
|
61
|
+
resolver(["center": [
|
|
62
|
+
map.cameraState.center.longitude,
|
|
63
|
+
map.cameraState.center.latitude
|
|
64
|
+
]])
|
|
65
|
+
}
|
|
85
66
|
}
|
|
86
67
|
|
|
87
68
|
@objc public static func getCoordinateFromView(
|
|
@@ -89,10 +70,10 @@ extension RNMBXMapViewManager {
|
|
|
89
70
|
atPoint point: CGPoint,
|
|
90
71
|
resolver: @escaping RCTPromiseResolveBlock,
|
|
91
72
|
rejecter: @escaping RCTPromiseRejectBlock) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
73
|
+
view.withMapboxMap { map in
|
|
74
|
+
let coordinates = map.coordinate(for: point)
|
|
75
|
+
resolver(["coordinateFromView": [coordinates.longitude, coordinates.latitude]])
|
|
76
|
+
}
|
|
96
77
|
|
|
97
78
|
}
|
|
98
79
|
|
|
@@ -101,12 +82,11 @@ extension RNMBXMapViewManager {
|
|
|
101
82
|
atCoordinate coordinate: [NSNumber],
|
|
102
83
|
resolver: @escaping RCTPromiseResolveBlock,
|
|
103
84
|
rejecter: @escaping RCTPromiseRejectBlock) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
85
|
+
view.withMapboxMap { map in
|
|
86
|
+
let coordinate = CLLocationCoordinate2DMake(coordinate[1].doubleValue, coordinate[0].doubleValue)
|
|
87
|
+
let point = map.point(for: coordinate)
|
|
88
|
+
resolver(["pointInView": [(point.x), (point.y)]])
|
|
89
|
+
}
|
|
110
90
|
}
|
|
111
91
|
|
|
112
92
|
@objc public static func setHandledMapChangedEvents(
|
|
@@ -124,10 +104,9 @@ extension RNMBXMapViewManager {
|
|
|
124
104
|
_ view: RNMBXMapView,
|
|
125
105
|
resolver: @escaping RCTPromiseResolveBlock,
|
|
126
106
|
rejecter: @escaping RCTPromiseRejectBlock) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
107
|
+
view.withMapboxMap { map in
|
|
108
|
+
resolver(["zoom": map.cameraState.zoom])
|
|
109
|
+
}
|
|
131
110
|
}
|
|
132
111
|
|
|
133
112
|
@objc public static func getVisibleBounds(
|
|
@@ -148,27 +127,26 @@ extension RNMBXMapViewManager {
|
|
|
148
127
|
withLayerIDs layerIDs: [String]?,
|
|
149
128
|
resolver: @escaping RCTPromiseResolveBlock,
|
|
150
129
|
rejecter: @escaping RCTPromiseRejectBlock) -> Void {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
130
|
+
view.withMapboxMap { map in
|
|
131
|
+
let point = CGPoint(x: CGFloat(point[0].floatValue), y: CGFloat(point[1].floatValue))
|
|
132
|
+
|
|
133
|
+
logged("queryRenderedFeaturesAtPoint.option", rejecter: rejecter) {
|
|
134
|
+
let options = try RenderedQueryOptions(layerIds: (layerIDs ?? []).isEmpty ? nil : layerIDs, filter: filter?.asExpression())
|
|
135
|
+
|
|
136
|
+
map.queryRenderedFeatures(with: point, options: options) { result in
|
|
137
|
+
switch result {
|
|
138
|
+
case .success(let features):
|
|
139
|
+
resolver([
|
|
140
|
+
"data": ["type": "FeatureCollection", "features": features.compactMap { queriedFeature in
|
|
141
|
+
logged("queryRenderedFeaturesAtPoint.feature.toJSON") { try queriedFeature.feature.toJSON() }
|
|
142
|
+
}]
|
|
143
|
+
])
|
|
144
|
+
case .failure(let error):
|
|
145
|
+
rejecter("queryRenderedFeaturesAtPoint","failed to query features", error)
|
|
168
146
|
}
|
|
169
147
|
}
|
|
170
|
-
|
|
171
|
-
|
|
148
|
+
}
|
|
149
|
+
}
|
|
172
150
|
}
|
|
173
151
|
|
|
174
152
|
@objc public static func queryRenderedFeaturesInRect(
|