@rnmapbox/maps 10.1.11 → 10.1.13
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/RNMBXPackage.kt +13 -2
- package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/CameraStop.kt +0 -6
- package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCamera.kt +14 -9
- package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCameraManager.kt +8 -5
- package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCameraModule.kt +51 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXVIewportManager.kt +2 -1
- package/android/src/main/java/com/rnmapbox/rnmbx/components/location/RNMBXNativeUserLocation.kt +20 -23
- package/android/src/main/java/com/rnmapbox/rnmbx/utils/ExpressionParser.java +10 -4
- package/android/src/main/java/com/rnmapbox/rnmbx/utils/Logger.kt +1 -1
- package/android/src/main/java/com/rnmapbox/rnmbx/utils/extensions/Dynamic.kt +16 -0
- package/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXCameraModuleSpec.java +41 -0
- package/ios/RNMBX/RNMBXCamera.swift +49 -54
- package/ios/RNMBX/RNMBXCameraModule.h +18 -0
- package/ios/RNMBX/RNMBXCameraModule.mm +67 -0
- package/ios/RNMBX/RNMBXNativeUserLocation.swift +1 -1
- package/lib/commonjs/components/Camera.js +14 -15
- package/lib/commonjs/components/Camera.js.map +1 -1
- package/lib/commonjs/components/Viewport.js +2 -43
- package/lib/commonjs/components/Viewport.js.map +1 -1
- package/lib/commonjs/specs/NativeRNMBXCameraModule.js +10 -0
- package/lib/commonjs/specs/NativeRNMBXCameraModule.js.map +1 -0
- package/lib/commonjs/utils/NativeCommands.js +50 -0
- package/lib/commonjs/utils/NativeCommands.js.map +1 -0
- package/lib/module/components/Camera.js +15 -16
- package/lib/module/components/Camera.js.map +1 -1
- package/lib/module/components/Viewport.js +1 -42
- package/lib/module/components/Viewport.js.map +1 -1
- package/lib/module/specs/NativeRNMBXCameraModule.js +6 -0
- package/lib/module/specs/NativeRNMBXCameraModule.js.map +1 -0
- package/lib/module/utils/NativeCommands.js +43 -0
- package/lib/module/utils/NativeCommands.js.map +1 -0
- package/lib/typescript/src/components/Camera.d.ts.map +1 -1
- package/lib/typescript/src/components/Viewport.d.ts +0 -3
- package/lib/typescript/src/components/Viewport.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeRNMBXCameraModule.d.ts +27 -0
- package/lib/typescript/src/specs/NativeRNMBXCameraModule.d.ts.map +1 -0
- package/lib/typescript/src/utils/NativeCommands.d.ts +25 -0
- package/lib/typescript/src/utils/NativeCommands.d.ts.map +1 -0
- package/package.json +1 -1
- package/setup-jest.js +4 -0
- package/src/components/Camera.tsx +22 -10
- package/src/components/Viewport.tsx +2 -94
- package/src/specs/NativeRNMBXCameraModule.ts +36 -0
- package/src/utils/NativeCommands.ts +89 -0
|
@@ -13,6 +13,7 @@ import com.rnmapbox.rnmbx.components.annotation.RNMBXMarkerViewManager
|
|
|
13
13
|
import com.rnmapbox.rnmbx.components.annotation.RNMBXPointAnnotationManager
|
|
14
14
|
import com.rnmapbox.rnmbx.components.annotation.RNMBXPointAnnotationModule
|
|
15
15
|
import com.rnmapbox.rnmbx.components.camera.RNMBXCameraManager
|
|
16
|
+
import com.rnmapbox.rnmbx.components.camera.RNMBXCameraModule
|
|
16
17
|
import com.rnmapbox.rnmbx.components.camera.RNMBXViewport
|
|
17
18
|
import com.rnmapbox.rnmbx.components.camera.RNMBXViewportManager
|
|
18
19
|
import com.rnmapbox.rnmbx.components.camera.RNMBXViewportModule
|
|
@@ -96,6 +97,7 @@ class RNMBXPackage : TurboReactPackage() {
|
|
|
96
97
|
RNMBXSnapshotModule.REACT_CLASS -> return RNMBXSnapshotModule(reactApplicationContext)
|
|
97
98
|
RNMBXLogging.REACT_CLASS -> return RNMBXLogging(reactApplicationContext)
|
|
98
99
|
NativeMapViewModule.NAME -> return NativeMapViewModule(reactApplicationContext, getViewTagResolver(reactApplicationContext, s))
|
|
100
|
+
RNMBXCameraModule.NAME -> return RNMBXCameraModule(reactApplicationContext, getViewTagResolver(reactApplicationContext, s))
|
|
99
101
|
RNMBXViewportModule.NAME -> return RNMBXViewportModule(reactApplicationContext, getViewTagResolver(reactApplicationContext, s))
|
|
100
102
|
RNMBXShapeSourceModule.NAME -> return RNMBXShapeSourceModule(reactApplicationContext, getViewTagResolver(reactApplicationContext, s))
|
|
101
103
|
RNMBXImageModule.NAME -> return RNMBXImageModule(reactApplicationContext, getViewTagResolver(reactApplicationContext, s))
|
|
@@ -114,8 +116,8 @@ class RNMBXPackage : TurboReactPackage() {
|
|
|
114
116
|
val managers: MutableList<ViewManager<*, *>> = ArrayList()
|
|
115
117
|
|
|
116
118
|
// components
|
|
117
|
-
managers.add(RNMBXCameraManager(reactApplicationContext))
|
|
118
|
-
managers.add(RNMBXViewportManager(reactApplicationContext))
|
|
119
|
+
managers.add(RNMBXCameraManager(reactApplicationContext, getViewTagResolver(reactApplicationContext, "RNMBXCameraManager")))
|
|
120
|
+
managers.add(RNMBXViewportManager(reactApplicationContext, getViewTagResolver(reactApplicationContext, "RNMBXViewportManager")))
|
|
119
121
|
managers.add(RNMBXMapViewManager(reactApplicationContext, getViewTagResolver(reactApplicationContext, "RNMBXMapViewManager")))
|
|
120
122
|
managers.add(RNMBXStyleImportManager(reactApplicationContext))
|
|
121
123
|
managers.add(RNMBXModelsManager(reactApplicationContext))
|
|
@@ -245,6 +247,15 @@ class RNMBXPackage : TurboReactPackage() {
|
|
|
245
247
|
false, // isCxxModule
|
|
246
248
|
isTurboModule // isTurboModule
|
|
247
249
|
)
|
|
250
|
+
moduleInfos[RNMBXCameraModule.NAME] = ReactModuleInfo(
|
|
251
|
+
RNMBXCameraModule.NAME,
|
|
252
|
+
RNMBXCameraModule.NAME,
|
|
253
|
+
false, // canOverrideExistingModule
|
|
254
|
+
false, // needsEagerInit
|
|
255
|
+
false, // hasConstants
|
|
256
|
+
false, // isCxxModule
|
|
257
|
+
isTurboModule // isTurboModule
|
|
258
|
+
)
|
|
248
259
|
moduleInfos[RNMBXShapeSourceModule.NAME] = ReactModuleInfo(
|
|
249
260
|
RNMBXShapeSourceModule.NAME,
|
|
250
261
|
RNMBXShapeSourceModule.NAME,
|
|
@@ -31,8 +31,6 @@ class CameraStop {
|
|
|
31
31
|
private var mDuration = 2000
|
|
32
32
|
private var mCallback: Animator.AnimatorListener? = null
|
|
33
33
|
|
|
34
|
-
var ts: Int? = null
|
|
35
|
-
|
|
36
34
|
fun setBearing(bearing: Double) {
|
|
37
35
|
mBearing = bearing
|
|
38
36
|
}
|
|
@@ -156,10 +154,6 @@ class CameraStop {
|
|
|
156
154
|
): CameraStop {
|
|
157
155
|
val stop = CameraStop()
|
|
158
156
|
|
|
159
|
-
if (readableMap.hasKey("__updateTS")) {
|
|
160
|
-
stop.ts = readableMap.getInt("__updateTS")
|
|
161
|
-
}
|
|
162
|
-
|
|
163
157
|
if (readableMap.hasKey("pitch")) {
|
|
164
158
|
stop.setTilt(readableMap.getDouble("pitch"))
|
|
165
159
|
}
|
|
@@ -3,6 +3,7 @@ package com.rnmapbox.rnmbx.components.camera
|
|
|
3
3
|
import android.animation.Animator
|
|
4
4
|
import android.content.Context
|
|
5
5
|
import android.location.Location
|
|
6
|
+
import com.facebook.react.bridge.Dynamic
|
|
6
7
|
import com.facebook.react.bridge.ReadableMap
|
|
7
8
|
import com.mapbox.maps.plugin.gestures.gestures
|
|
8
9
|
import com.rnmapbox.rnmbx.location.LocationManager.Companion.getInstance
|
|
@@ -15,6 +16,7 @@ import com.mapbox.maps.plugin.locationcomponent.OnIndicatorBearingChangedListene
|
|
|
15
16
|
import com.mapbox.maps.plugin.locationcomponent.OnIndicatorPositionChangedListener
|
|
16
17
|
import com.facebook.react.bridge.WritableMap
|
|
17
18
|
import com.facebook.react.bridge.WritableNativeMap
|
|
19
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
18
20
|
import com.mapbox.maps.*
|
|
19
21
|
import com.mapbox.maps.plugin.locationcomponent.location
|
|
20
22
|
import com.mapbox.maps.plugin.viewport.ViewportStatus
|
|
@@ -113,15 +115,18 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
|
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
fun setStop(stop: CameraStop) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
stop.let { updateCamera(it) }
|
|
121
|
-
}
|
|
118
|
+
mCameraStop = stop
|
|
119
|
+
stop.setCallback(mCameraCallback)
|
|
120
|
+
if (mMapView != null) {
|
|
121
|
+
stop.let { updateCamera(it) }
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
fun updateCameraStop(map: ReadableMap) {
|
|
126
|
+
val stop = CameraStop.fromReadableMap(mContext, map, null)
|
|
127
|
+
setStop(stop)
|
|
128
|
+
}
|
|
129
|
+
|
|
125
130
|
fun setDefaultStop(stop: CameraStop?) {
|
|
126
131
|
mDefaultStop = stop
|
|
127
132
|
}
|
|
@@ -136,17 +141,17 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
|
|
|
136
141
|
_updateViewportState()
|
|
137
142
|
}
|
|
138
143
|
|
|
139
|
-
fun setFollowZoomLevel(zoomLevel: Double) {
|
|
144
|
+
fun setFollowZoomLevel(zoomLevel: Double?) {
|
|
140
145
|
mFollowZoomLevel = zoomLevel
|
|
141
146
|
_updateViewportState();
|
|
142
147
|
}
|
|
143
148
|
|
|
144
|
-
fun setFollowPitch(pitch: Double) {
|
|
149
|
+
fun setFollowPitch(pitch: Double?) {
|
|
145
150
|
mFollowPitch = pitch
|
|
146
151
|
_updateViewportState();
|
|
147
152
|
}
|
|
148
153
|
|
|
149
|
-
fun setFollowHeading(heading: Double) {
|
|
154
|
+
fun setFollowHeading(heading: Double?) {
|
|
150
155
|
mFollowHeading = heading
|
|
151
156
|
_updateViewportState();
|
|
152
157
|
}
|
|
@@ -9,9 +9,12 @@ import com.mapbox.geojson.FeatureCollection
|
|
|
9
9
|
import com.rnmapbox.rnmbx.components.AbstractEventEmitter
|
|
10
10
|
import com.rnmapbox.rnmbx.components.camera.CameraStop.Companion.fromReadableMap
|
|
11
11
|
import com.rnmapbox.rnmbx.utils.GeoJSONUtils.toLatLngBounds
|
|
12
|
+
import com.rnmapbox.rnmbx.utils.ViewTagResolver
|
|
12
13
|
import com.rnmapbox.rnmbx.utils.extensions.asBooleanOrNull
|
|
14
|
+
import com.rnmapbox.rnmbx.utils.extensions.asDoubleOrNull
|
|
15
|
+
import com.rnmapbox.rnmbx.utils.extensions.asStringOrNull
|
|
13
16
|
|
|
14
|
-
class RNMBXCameraManager(private val mContext: ReactApplicationContext) :
|
|
17
|
+
class RNMBXCameraManager(private val mContext: ReactApplicationContext, val viewTagResolver: ViewTagResolver) :
|
|
15
18
|
AbstractEventEmitter<RNMBXCamera?>(
|
|
16
19
|
mContext
|
|
17
20
|
), RNMBXCameraManagerInterface<RNMBXCamera> {
|
|
@@ -71,22 +74,22 @@ class RNMBXCameraManager(private val mContext: ReactApplicationContext) :
|
|
|
71
74
|
|
|
72
75
|
@ReactProp(name = "followUserMode")
|
|
73
76
|
override fun setFollowUserMode(camera: RNMBXCamera, value: Dynamic) {
|
|
74
|
-
camera.setFollowUserMode(value.
|
|
77
|
+
camera.setFollowUserMode(value.asStringOrNull())
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
@ReactProp(name = "followZoomLevel")
|
|
78
81
|
override fun setFollowZoomLevel(camera: RNMBXCamera, value: Dynamic) {
|
|
79
|
-
camera.setFollowZoomLevel(value.
|
|
82
|
+
camera.setFollowZoomLevel(value.asDoubleOrNull())
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
@ReactProp(name = "followPitch")
|
|
83
86
|
override fun setFollowPitch(camera: RNMBXCamera, value: Dynamic) {
|
|
84
|
-
camera.setFollowPitch(value.
|
|
87
|
+
camera.setFollowPitch(value.asDoubleOrNull())
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
@ReactProp(name = "followHeading")
|
|
88
91
|
override fun setFollowHeading(camera: RNMBXCamera, value: Dynamic) {
|
|
89
|
-
camera.setFollowHeading(value.
|
|
92
|
+
camera.setFollowHeading(value.asDoubleOrNull())
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
@ReactProp(name = "followPadding")
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
package com.rnmapbox.rnmbx.components.camera
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Callback
|
|
4
|
+
import com.facebook.react.bridge.Promise
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.bridge.ReadableArray
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap
|
|
8
|
+
import com.facebook.react.bridge.WritableMap
|
|
9
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
10
|
+
import com.rnmapbox.rnmbx.NativeRNMBXCameraModuleSpec
|
|
11
|
+
import com.rnmapbox.rnmbx.components.mapview.CommandResponse
|
|
12
|
+
import com.rnmapbox.rnmbx.utils.ViewTagResolver
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class RNMBXCameraModule(context: ReactApplicationContext, val viewTagResolver: ViewTagResolver) : NativeRNMBXCameraModuleSpec(context) {
|
|
16
|
+
private fun withViewportOnUIThread(
|
|
17
|
+
viewRef: Double?,
|
|
18
|
+
reject: Promise,
|
|
19
|
+
fn: (RNMBXCamera) -> Unit
|
|
20
|
+
) {
|
|
21
|
+
if (viewRef == null) {
|
|
22
|
+
reject.reject(Exception("viewRef is null"))
|
|
23
|
+
} else {
|
|
24
|
+
viewTagResolver.withViewResolved(viewRef.toInt(), reject, fn)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private fun createCommandResponse(promise: Promise): CommandResponse = object : CommandResponse {
|
|
29
|
+
override fun success(builder: (WritableMap) -> Unit) {
|
|
30
|
+
val payload: WritableMap = WritableNativeMap()
|
|
31
|
+
builder(payload)
|
|
32
|
+
|
|
33
|
+
promise.resolve(payload)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override fun error(message: String) {
|
|
37
|
+
promise.reject(Exception(message))
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
companion object {
|
|
42
|
+
const val NAME = "RNMBXCameraModule"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override fun updateCameraStop(viewRef: Double?, stop: ReadableMap, promise: Promise) {
|
|
46
|
+
withViewportOnUIThread(viewRef, promise) {
|
|
47
|
+
it.updateCameraStop(stop)
|
|
48
|
+
promise.resolve(null)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -12,8 +12,9 @@ import com.facebook.react.viewmanagers.RNMBXViewportManagerInterface
|
|
|
12
12
|
import com.rnmapbox.rnmbx.components.AbstractEventEmitter
|
|
13
13
|
import com.rnmapbox.rnmbx.events.constants.EventKeys
|
|
14
14
|
import com.rnmapbox.rnmbx.events.constants.eventMapOf
|
|
15
|
+
import com.rnmapbox.rnmbx.utils.ViewTagResolver
|
|
15
16
|
|
|
16
|
-
class RNMBXViewportManager(private val mContext: ReactApplicationContext) : AbstractEventEmitter<RNMBXViewport?>(
|
|
17
|
+
class RNMBXViewportManager(private val mContext: ReactApplicationContext, val viewTagResolver: ViewTagResolver) : AbstractEventEmitter<RNMBXViewport?>(
|
|
17
18
|
mContext
|
|
18
19
|
), RNMBXViewportManagerInterface<RNMBXViewport> {
|
|
19
20
|
|
package/android/src/main/java/com/rnmapbox/rnmbx/components/location/RNMBXNativeUserLocation.kt
CHANGED
|
@@ -46,6 +46,7 @@ enum class RenderMode {
|
|
|
46
46
|
class RNMBXNativeUserLocation(context: Context) : AbstractMapFeature(context), OnMapReadyCallback, Style.OnStyleLoaded {
|
|
47
47
|
private var mEnabled = true
|
|
48
48
|
private var mMap: MapboxMap? = null
|
|
49
|
+
private var mMBXMapView: RNMBXMapView? = null
|
|
49
50
|
private var mRenderMode : RenderMode = RenderMode.NORMAL;
|
|
50
51
|
private var mContext : Context = context
|
|
51
52
|
|
|
@@ -63,7 +64,7 @@ class RNMBXNativeUserLocation(context: Context) : AbstractMapFeature(context), O
|
|
|
63
64
|
SHADOW
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
private var imageNames = mutableMapOf<PuckImagePart, String
|
|
67
|
+
private var imageNames = mutableMapOf<PuckImagePart, String?>()
|
|
67
68
|
private var subscriptions = mutableMapOf<PuckImagePart, Subscription>()
|
|
68
69
|
private var images = mutableMapOf<PuckImagePart, ImageHolder>()
|
|
69
70
|
|
|
@@ -98,23 +99,10 @@ class RNMBXNativeUserLocation(context: Context) : AbstractMapFeature(context), O
|
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
private fun imageNameUpdated(image: PuckImagePart, name: String?) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
imageNames.remove(image)
|
|
105
|
-
}
|
|
106
|
-
subscriptions[image]?.let {
|
|
107
|
-
it.cancel()
|
|
108
|
-
}
|
|
109
|
-
subscriptions.remove(image)
|
|
110
|
-
|
|
111
|
-
if (name == null) {
|
|
112
|
-
imageUpdated(image, null)
|
|
113
|
-
return
|
|
102
|
+
imageNames[image] = name
|
|
103
|
+
mMBXMapView?.let {
|
|
104
|
+
_fetchImages(it)
|
|
114
105
|
}
|
|
115
|
-
|
|
116
|
-
imageManager?.let { subscribe(it, image, name) }
|
|
117
|
-
|
|
118
106
|
}
|
|
119
107
|
|
|
120
108
|
private fun imageUpdated(image: PuckImagePart, imageHolder: ImageHolder?) {
|
|
@@ -208,6 +196,7 @@ class RNMBXNativeUserLocation(context: Context) : AbstractMapFeature(context), O
|
|
|
208
196
|
mapView.getMapboxMap()
|
|
209
197
|
mapView.getMapAsync(this)
|
|
210
198
|
mMapView?.locationComponentManager?.showNativeUserLocation(true)
|
|
199
|
+
mMBXMapView = mapView
|
|
211
200
|
_fetchImages(mapView)
|
|
212
201
|
_apply()
|
|
213
202
|
}
|
|
@@ -216,6 +205,7 @@ class RNMBXNativeUserLocation(context: Context) : AbstractMapFeature(context), O
|
|
|
216
205
|
mEnabled = false
|
|
217
206
|
mMapView?.locationComponentManager?.showNativeUserLocation(false)
|
|
218
207
|
mMap?.getStyle(this)
|
|
208
|
+
mMBXMapView = null
|
|
219
209
|
return super.removeFromMap(mapView, reason)
|
|
220
210
|
}
|
|
221
211
|
|
|
@@ -244,7 +234,6 @@ class RNMBXNativeUserLocation(context: Context) : AbstractMapFeature(context), O
|
|
|
244
234
|
subscriptions.remove(image)
|
|
245
235
|
Logger.e("RNMBXNativeUserLocation", "subscribe: there is alread a subscription for image: $image")
|
|
246
236
|
}
|
|
247
|
-
|
|
248
237
|
subscriptions[image] = imageManager.subscribe(name, Resolver { _, imageData ->
|
|
249
238
|
imageUpdated(image, imageData.toImageHolder())
|
|
250
239
|
})
|
|
@@ -260,19 +249,27 @@ class RNMBXNativeUserLocation(context: Context) : AbstractMapFeature(context), O
|
|
|
260
249
|
private fun _fetchImages(map: RNMBXMapView) {
|
|
261
250
|
map.mapView?.getMapboxMap()?.getStyle()?.let { style ->
|
|
262
251
|
imageNames.forEach { (part,name) ->
|
|
263
|
-
if (
|
|
264
|
-
style.
|
|
265
|
-
|
|
252
|
+
if (name != null) {
|
|
253
|
+
if (style.hasStyleImage(name)) {
|
|
254
|
+
style.getStyleImage(name)?.let { image ->
|
|
255
|
+
images[part] = image.toImageHolder()
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
images.remove(part)
|
|
266
259
|
}
|
|
260
|
+
} else {
|
|
261
|
+
images.remove(part)
|
|
267
262
|
}
|
|
268
263
|
}
|
|
269
264
|
}
|
|
270
|
-
|
|
271
265
|
removeSubscriptions()
|
|
272
266
|
val imageManager = map.imageManager
|
|
273
267
|
this.imageManager = imageManager
|
|
268
|
+
_apply()
|
|
274
269
|
imageNames.forEach { (part,name) ->
|
|
275
|
-
|
|
270
|
+
if (name != null) {
|
|
271
|
+
subscribe(imageManager, part, name)
|
|
272
|
+
}
|
|
276
273
|
}
|
|
277
274
|
}
|
|
278
275
|
// endregion
|
|
@@ -6,12 +6,14 @@ import com.facebook.react.bridge.ReadableMap;
|
|
|
6
6
|
import com.google.gson.Gson;
|
|
7
7
|
import com.google.gson.JsonArray;
|
|
8
8
|
import com.mapbox.maps.extension.style.expressions.generated.Expression;
|
|
9
|
+
import com.rnmapbox.rnmbx.utils.Logger;
|
|
9
10
|
|
|
10
11
|
import java.util.Locale;
|
|
11
12
|
|
|
12
13
|
import javax.annotation.Nullable;
|
|
13
14
|
|
|
14
15
|
public class ExpressionParser {
|
|
16
|
+
static final String LOG_TAG = "RNMBXMapView";
|
|
15
17
|
static final String TYPE_STRING = "string";
|
|
16
18
|
static final String TYPE_ARRAY = "array";
|
|
17
19
|
static final String TYPE_NUMBER = "number";
|
|
@@ -22,10 +24,14 @@ public class ExpressionParser {
|
|
|
22
24
|
if (rawExpressions == null || rawExpressions.size() == 0) {
|
|
23
25
|
return null;
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
try {
|
|
28
|
+
JsonArray array = ConvertUtils.toJsonArray(rawExpressions);
|
|
29
|
+
String jsonString = new Gson().toJson(array);
|
|
30
|
+
return Expression.fromRaw(jsonString);
|
|
31
|
+
} catch (Exception e) {
|
|
32
|
+
Logger.e(LOG_TAG, "An error occurred while attempting to parse the expression", e);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
public static @Nullable Expression fromTyped(ReadableMap rawExpressions) {
|
|
@@ -62,4 +62,20 @@ fun Dynamic.asBooleanOrNull(): Boolean? {
|
|
|
62
62
|
} else {
|
|
63
63
|
asBoolean()
|
|
64
64
|
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fun Dynamic.asDoubleOrNull(): Double? {
|
|
68
|
+
return if (isNull) {
|
|
69
|
+
null
|
|
70
|
+
} else {
|
|
71
|
+
asDouble()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fun Dynamic.asStringOrNull(): String? {
|
|
76
|
+
return if (isNull) {
|
|
77
|
+
null
|
|
78
|
+
} else {
|
|
79
|
+
asString()
|
|
80
|
+
}
|
|
65
81
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateModuleJavaSpec.js
|
|
9
|
+
*
|
|
10
|
+
* @nolint
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
package com.rnmapbox.rnmbx;
|
|
14
|
+
|
|
15
|
+
import com.facebook.proguard.annotations.DoNotStrip;
|
|
16
|
+
import com.facebook.react.bridge.Promise;
|
|
17
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
18
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
19
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
20
|
+
import com.facebook.react.bridge.ReactModuleWithSpec;
|
|
21
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
22
|
+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
|
23
|
+
import javax.annotation.Nonnull;
|
|
24
|
+
import javax.annotation.Nullable;
|
|
25
|
+
|
|
26
|
+
public abstract class NativeRNMBXCameraModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
|
|
27
|
+
public static final String NAME = "RNMBXCameraModule";
|
|
28
|
+
|
|
29
|
+
public NativeRNMBXCameraModuleSpec(ReactApplicationContext reactContext) {
|
|
30
|
+
super(reactContext);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Override
|
|
34
|
+
public @Nonnull String getName() {
|
|
35
|
+
return NAME;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@ReactMethod
|
|
39
|
+
@DoNotStrip
|
|
40
|
+
public abstract void updateCameraStop(@Nullable Double viewRef, ReadableMap stops, Promise promise);
|
|
41
|
+
}
|
|
@@ -40,15 +40,16 @@ struct CameraUpdateItem {
|
|
|
40
40
|
if let center = camera.center {
|
|
41
41
|
try center.validate()
|
|
42
42
|
}
|
|
43
|
+
|
|
43
44
|
switch mode {
|
|
44
|
-
|
|
45
|
+
case .flight:
|
|
45
46
|
map.mapView.camera.fly(to: camera, duration: duration)
|
|
46
|
-
|
|
47
|
+
case .ease:
|
|
47
48
|
map.mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .easeInOut, completion: nil)
|
|
48
|
-
|
|
49
|
+
case .linear:
|
|
49
50
|
map.mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .linear, completion: nil)
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
default:
|
|
52
|
+
map.mapboxMap.setCamera(to: camera)
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
@@ -236,6 +237,10 @@ open class RNMBXCamera : RNMBXMapComponentBase {
|
|
|
236
237
|
map.viewport.idle()
|
|
237
238
|
}
|
|
238
239
|
|
|
240
|
+
@objc public func updateCameraStop(_ stop: [String: Any]) {
|
|
241
|
+
self.stop = stop
|
|
242
|
+
}
|
|
243
|
+
|
|
239
244
|
func _toCoordinateBounds(_ bounds: FeatureCollection) throws -> CoordinateBounds {
|
|
240
245
|
guard bounds.features.count == 2 else {
|
|
241
246
|
throw RNMBXError.paramError("Expected two Points in FeatureColletion")
|
|
@@ -259,14 +264,12 @@ open class RNMBXCamera : RNMBXMapComponentBase {
|
|
|
259
264
|
logged("RNMBXCamera._updateMaxBounds._toCoordinateBounds") {
|
|
260
265
|
options.bounds = try self._toCoordinateBounds(maxBounds)
|
|
261
266
|
}
|
|
267
|
+
} else {
|
|
268
|
+
options.bounds = nil
|
|
262
269
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if let maxZoomLevel = self.maxZoomLevel {
|
|
267
|
-
options.maxZoom = maxZoomLevel.CGFloat
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
+
options.minZoom = self.minZoomLevel?.CGFloat
|
|
271
|
+
options.maxZoom = self.maxZoomLevel?.CGFloat
|
|
272
|
+
|
|
270
273
|
logged("RNMBXCamera._updateMaxBounds") {
|
|
271
274
|
try map.mapboxMap.setCameraBounds(with: options)
|
|
272
275
|
}
|
|
@@ -371,11 +374,12 @@ open class RNMBXCamera : RNMBXMapComponentBase {
|
|
|
371
374
|
if (stop.isEmpty) {
|
|
372
375
|
return nil
|
|
373
376
|
}
|
|
377
|
+
|
|
374
378
|
var zoom: CGFloat?
|
|
375
379
|
if let z = stop["zoom"] as? Double {
|
|
376
380
|
zoom = CGFloat(z)
|
|
377
381
|
}
|
|
378
|
-
|
|
382
|
+
|
|
379
383
|
var pitch: CGFloat?
|
|
380
384
|
if let p = stop["pitch"] as? Double {
|
|
381
385
|
pitch = CGFloat(p)
|
|
@@ -386,20 +390,22 @@ open class RNMBXCamera : RNMBXMapComponentBase {
|
|
|
386
390
|
heading = CLLocationDirection(h)
|
|
387
391
|
}
|
|
388
392
|
|
|
389
|
-
|
|
393
|
+
var padding: UIEdgeInsets = UIEdgeInsets(
|
|
390
394
|
top: stop["paddingTop"] as? Double ?? 0,
|
|
391
395
|
left: stop["paddingLeft"] as? Double ?? 0,
|
|
392
396
|
bottom: stop["paddingBottom"] as? Double ?? 0,
|
|
393
397
|
right: stop["paddingRight"] as? Double ?? 0
|
|
394
398
|
)
|
|
395
|
-
|
|
396
|
-
var
|
|
397
|
-
|
|
398
|
-
|
|
399
|
+
|
|
400
|
+
var camera: CameraOptions?
|
|
401
|
+
|
|
402
|
+
if let feature = stop["centerCoordinate"] as? String {
|
|
399
403
|
let centerFeature : Turf.Feature? = logged("RNMBXCamera.toUpdateItem.decode.cc") { try
|
|
400
404
|
JSONDecoder().decode(Turf.Feature.self, from: feature.data(using: .utf8)!)
|
|
401
405
|
}
|
|
402
406
|
|
|
407
|
+
var center: LocationCoordinate2D?
|
|
408
|
+
|
|
403
409
|
switch centerFeature?.geometry {
|
|
404
410
|
case .point(let centerPoint):
|
|
405
411
|
center = centerPoint.coordinates
|
|
@@ -407,7 +413,16 @@ open class RNMBXCamera : RNMBXMapComponentBase {
|
|
|
407
413
|
Logger.log(level: .error, message: "RNMBXCamera.toUpdateItem: Unexpected geometry: \(String(describing: centerFeature?.geometry))")
|
|
408
414
|
return nil
|
|
409
415
|
}
|
|
410
|
-
|
|
416
|
+
|
|
417
|
+
camera = CameraOptions(
|
|
418
|
+
center: center,
|
|
419
|
+
padding: padding,
|
|
420
|
+
anchor: nil,
|
|
421
|
+
zoom: zoom,
|
|
422
|
+
bearing: heading,
|
|
423
|
+
pitch: pitch
|
|
424
|
+
)
|
|
425
|
+
} else if let feature = stop["bounds"] as? String {
|
|
411
426
|
let collection : Turf.FeatureCollection? = logged("RNMBXCamera.toUpdateItem.decode.bound") { try
|
|
412
427
|
JSONDecoder().decode(Turf.FeatureCollection.self, from: feature.data(using: .utf8)!) }
|
|
413
428
|
let features = collection?.features
|
|
@@ -436,55 +451,35 @@ open class RNMBXCamera : RNMBXMapComponentBase {
|
|
|
436
451
|
#else
|
|
437
452
|
let bounds = CoordinateBounds(southwest: sw, northeast: ne)
|
|
438
453
|
#endif
|
|
439
|
-
|
|
454
|
+
|
|
455
|
+
camera = map.mapboxMap.camera(
|
|
440
456
|
for: bounds,
|
|
441
457
|
padding: padding,
|
|
442
|
-
bearing: heading ?? map.cameraState.bearing,
|
|
443
|
-
pitch: pitch ?? map.cameraState.pitch
|
|
458
|
+
bearing: heading ?? map.mapboxMap.cameraState.bearing,
|
|
459
|
+
pitch: pitch ?? map.mapboxMap.cameraState.pitch
|
|
444
460
|
)
|
|
445
|
-
|
|
446
|
-
if let _center = camera.center, let _zoom = camera.zoom {
|
|
447
|
-
center = _center
|
|
448
|
-
zoom = _zoom
|
|
449
|
-
}
|
|
450
461
|
}
|
|
451
462
|
}
|
|
452
463
|
|
|
453
|
-
let
|
|
454
|
-
if let d = stop["duration"] as? Double {
|
|
455
|
-
return toSeconds(d)
|
|
456
|
-
}
|
|
464
|
+
guard let camera = camera else {
|
|
457
465
|
return nil
|
|
458
|
-
}()
|
|
459
|
-
|
|
460
|
-
let mode: CameraMode = {
|
|
461
|
-
if let m = stop["mode"] as? String, let m = CameraMode(rawValue: m) {
|
|
462
|
-
return m
|
|
463
|
-
}
|
|
464
|
-
return .flight
|
|
465
|
-
}()
|
|
466
|
-
|
|
467
|
-
if let z1 = minZoomLevel, let z2 = CGFloat(exactly: z1), zoom ?? 100 < z2 {
|
|
468
|
-
zoom = z2
|
|
469
466
|
}
|
|
470
467
|
|
|
471
|
-
|
|
472
|
-
|
|
468
|
+
var duration: TimeInterval?
|
|
469
|
+
if let d = stop["duration"] as? Double {
|
|
470
|
+
duration = toSeconds(d)
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
var mode: CameraMode = .flight
|
|
474
|
+
if let m = stop["mode"] as? String, let m = CameraMode(rawValue: m) {
|
|
475
|
+
mode = m
|
|
473
476
|
}
|
|
474
477
|
|
|
475
|
-
|
|
476
|
-
camera:
|
|
477
|
-
center: center,
|
|
478
|
-
padding: padding,
|
|
479
|
-
anchor: nil,
|
|
480
|
-
zoom: zoom,
|
|
481
|
-
bearing: heading,
|
|
482
|
-
pitch: pitch
|
|
483
|
-
),
|
|
478
|
+
return CameraUpdateItem(
|
|
479
|
+
camera: camera,
|
|
484
480
|
mode: mode,
|
|
485
481
|
duration: duration
|
|
486
482
|
)
|
|
487
|
-
return result
|
|
488
483
|
}
|
|
489
484
|
|
|
490
485
|
func _updateCamera() {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <UIKit/UIKit.h>
|
|
3
|
+
|
|
4
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
5
|
+
#import "rnmapbox_maps_specs.h"
|
|
6
|
+
#else
|
|
7
|
+
#import <React/RCTBridge.h>
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
@interface RNMBXCameraModule : NSObject
|
|
11
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
12
|
+
<NativeRNMBXCameraModuleSpec>
|
|
13
|
+
#else
|
|
14
|
+
<RCTBridgeModule>
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
@end
|
|
18
|
+
|