@rnmapbox/maps 10.3.0-beta.0 → 10.3.0-rc.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 +3 -6
- package/android/install.md +3 -29
- package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotation.kt +14 -1
- package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotationManager.kt +11 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/RNMBXStyleFactory.kt +95 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/events/MapSteadyEvent.kt +8 -2
- package/android/src/main/java/com/rnmapbox/rnmbx/events/RNMBXCameraGestureObserver.kt +3 -5
- package/android/src/main/java/com/rnmapbox/rnmbx/events/RNMBXCameraGestureObserverManager.kt +1 -1
- package/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXSnapshotModule.kt +56 -18
- package/ios/RNMBX/README.md +1 -1
- package/ios/RNMBX/RNMBXBackgroundLayer.swift +1 -1
- package/ios/RNMBX/RNMBXCalloutComponentView.mm +10 -0
- package/ios/RNMBX/RNMBXCamera.swift +9 -9
- package/ios/RNMBX/RNMBXCameraModule.mm +5 -5
- package/ios/RNMBX/RNMBXCircleLayer.swift +1 -1
- package/ios/RNMBX/RNMBXFillExtrusionLayer.swift +1 -1
- package/ios/RNMBX/RNMBXFillLayer.swift +1 -1
- package/ios/RNMBX/RNMBXHeatmapLayer.swift +1 -1
- package/ios/RNMBX/RNMBXHillshadeLayer.swift +1 -1
- package/ios/RNMBX/RNMBXLayer.swift +2 -2
- package/ios/RNMBX/RNMBXLineLayer.swift +1 -1
- package/ios/RNMBX/RNMBXMapView.swift +18 -1
- package/ios/RNMBX/RNMBXMapViewComponentView.mm +3 -0
- package/ios/RNMBX/RNMBXModelLayer.swift +1 -1
- package/ios/RNMBX/RNMBXPointAnnotation.swift +25 -3
- package/ios/RNMBX/RNMBXPointAnnotationComponentView.mm +1 -0
- package/ios/RNMBX/RNMBXRasterLayer.swift +1 -1
- package/ios/RNMBX/RNMBXRasterParticleLayer.swift +1 -1
- package/ios/RNMBX/RNMBXSkyLayer.swift +1 -1
- package/ios/RNMBX/RNMBXSnapshotModule.swift +3 -1
- package/ios/RNMBX/RNMBXStyle.swift +59 -1
- package/ios/RNMBX/RNMBXSymbolLayer.swift +1 -1
- package/ios/install.md +2 -15
- package/lib/commonjs/plugin/install.md +2 -19
- package/lib/module/components/UserLocation.js +2 -1
- package/lib/module/components/UserLocation.js.map +1 -1
- package/lib/module/specs/RNMBXPointAnnotationNativeComponent.ts +1 -0
- package/lib/module/utils/MapboxStyles.js +9 -0
- package/lib/module/utils/MapboxStyles.js.map +1 -1
- package/lib/module/utils/styleMap.js +6 -0
- package/lib/module/utils/styleMap.js.map +1 -1
- package/lib/typescript/scripts/autogenHelpers/generateCodeWithEjs.d.mts.map +1 -1
- package/lib/typescript/src/components/UserLocation.d.ts.map +1 -1
- package/lib/typescript/src/specs/RNMBXPointAnnotationNativeComponent.d.ts +1 -0
- package/lib/typescript/src/specs/RNMBXPointAnnotationNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/utils/MapboxStyles.d.ts +36 -10
- package/lib/typescript/src/utils/MapboxStyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/styleMap.d.ts.map +1 -1
- package/package.json +3 -3
- package/plugin/install.md +2 -19
- package/src/components/UserLocation.tsx +3 -2
- package/src/specs/RNMBXPointAnnotationNativeComponent.ts +1 -0
- package/src/utils/MapboxStyles.ts +40 -10
- package/src/utils/styleMap.ts +6 -0
package/README.md
CHANGED
|
@@ -56,11 +56,8 @@ _A community-supported, open-source React Native library for building maps with
|
|
|
56
56
|
|
|
57
57
|
---
|
|
58
58
|
|
|
59
|
-
### Supported Implementations
|
|
60
|
-
|
|
61
|
-
We default to Mapbox (v10).
|
|
62
|
-
|
|
63
|
-
_See [iOS](ios/install.md) & [Android](android/install.md) setup guide for using v11 beta_
|
|
59
|
+
### Supported Implementations
|
|
60
|
+
We support Mapbox Maps SDK v11. See [iOS](ios/install.md) & [Android](android/install.md) setup guides.
|
|
64
61
|
|
|
65
62
|
|
|
66
63
|
|
|
@@ -74,7 +71,7 @@ _See [iOS](ios/install.md) & [Android](android/install.md) setup guide for using
|
|
|
74
71
|
|
|
75
72
|
- [node](https://nodejs.org)
|
|
76
73
|
- [npm](https://www.npmjs.com/)
|
|
77
|
-
- [React Native](https://facebook.github.io/react-native/) (0.
|
|
74
|
+
- [React Native](https://facebook.github.io/react-native/) (0.79+)
|
|
78
75
|
|
|
79
76
|
|
|
80
77
|
## Installation
|
package/android/install.md
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Supported mapbox libraries
|
|
4
4
|
|
|
5
|
-
We
|
|
6
|
-
Next release will be 11.* only so we recommend updatign to 11.*
|
|
5
|
+
We support Mapbox Maps SDK v11.
|
|
7
6
|
|
|
8
7
|
### Adding mapbox maven repo
|
|
9
8
|
|
|
@@ -27,39 +26,14 @@ allprojects {
|
|
|
27
26
|
|
|
28
27
|
### Using non default mapbox version
|
|
29
28
|
|
|
30
|
-
*Warning*: If you set a custom version, make sure you revisit
|
|
29
|
+
*Warning*: If you set a custom version, make sure you revisit any time you update @rnmapbox/maps. Setting it to an earlier version than what we expect will likely result in a build error.
|
|
31
30
|
|
|
32
31
|
Set `RNMapboxMapsVersion` in `android/build.gradle > buildscript > ext` section
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
```groovy
|
|
36
|
-
buildscript {
|
|
37
|
-
ext {
|
|
38
|
-
RNMapboxMapsVersion = '11.4.1'
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
you can also customize all the libraries, should it be neccesary
|
|
44
|
-
|
|
45
|
-
```groovy
|
|
46
|
-
buildscript {
|
|
47
|
-
ext {
|
|
48
|
-
// ...
|
|
49
|
-
RNMapboxMapsLibs = { // optional - only required if you want to customize it
|
|
50
|
-
implementation 'com.mapbox.maps:android:10.6.0'
|
|
51
|
-
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:5.4.1'
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Using v11
|
|
58
|
-
|
|
59
33
|
```groovy
|
|
60
34
|
buildscript {
|
|
61
35
|
ext {
|
|
62
|
-
RNMapboxMapsVersion = '11.
|
|
36
|
+
RNMapboxMapsVersion = '11.16.2'
|
|
63
37
|
}
|
|
64
38
|
}
|
|
65
39
|
```
|
package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotation.kt
CHANGED
|
@@ -36,7 +36,7 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
|
|
|
36
36
|
private val mTitle: String? = null
|
|
37
37
|
private val mSnippet: String? = null
|
|
38
38
|
private var mAnchor: Array<Float>? = null
|
|
39
|
-
private
|
|
39
|
+
private var mIsSelected = false
|
|
40
40
|
private var mDraggable = false
|
|
41
41
|
private var mChildView: View? = null
|
|
42
42
|
private var mChildBitmap: Bitmap? = null
|
|
@@ -187,7 +187,19 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
fun setReactSelected(selected: Boolean) {
|
|
191
|
+
if (selected && !mIsSelected) {
|
|
192
|
+
pointAnnotations?.let {
|
|
193
|
+
it.deselectSelectedAnnotation()
|
|
194
|
+
it.selectAnnotation(this)
|
|
195
|
+
}
|
|
196
|
+
} else if (!selected && mIsSelected) {
|
|
197
|
+
pointAnnotations?.deselectAnnotation(this)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
190
201
|
fun doSelect(shouldSendEvent: Boolean) {
|
|
202
|
+
mIsSelected = true
|
|
191
203
|
if (calloutView != null) {
|
|
192
204
|
makeCallout()
|
|
193
205
|
}
|
|
@@ -197,6 +209,7 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
|
|
|
197
209
|
}
|
|
198
210
|
|
|
199
211
|
fun doDeselect() {
|
|
212
|
+
mIsSelected = false
|
|
200
213
|
mManager.handleEvent(makeEvent(false))
|
|
201
214
|
mCalloutSymbol?.let { mCalloutSymbol ->
|
|
202
215
|
pointAnnotations?.delete(mCalloutSymbol)
|
|
@@ -78,6 +78,17 @@ class RNMBXPointAnnotationManager(reactApplicationContext: ReactApplicationConte
|
|
|
78
78
|
annotation.setAnchor(mapValue.getDouble("x").toFloat(), mapValue.getDouble("y").toFloat())
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
override fun setSelected(
|
|
82
|
+
annotation: RNMBXPointAnnotation,
|
|
83
|
+
value: Dynamic
|
|
84
|
+
) {
|
|
85
|
+
if (value.isNull) {
|
|
86
|
+
Logger.e("RNMBXPointAnnotationManager", "selected value is null")
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
annotation.setReactSelected(value.asBoolean())
|
|
90
|
+
}
|
|
91
|
+
|
|
81
92
|
@ReactProp(name = "draggable")
|
|
82
93
|
override fun setDraggable(annotation: RNMBXPointAnnotation, draggable: Dynamic) {
|
|
83
94
|
annotation.setDraggable(draggable.asBoolean())
|
|
@@ -175,6 +175,14 @@ object RNMBXStyleFactory {
|
|
|
175
175
|
setLineGradient(layer, styleValue)
|
|
176
176
|
"lineTrimOffset" ->
|
|
177
177
|
setLineTrimOffset(layer, styleValue)
|
|
178
|
+
"lineBorderWidth" ->
|
|
179
|
+
setLineBorderWidth(layer, styleValue)
|
|
180
|
+
"lineBorderWidthTransition" ->
|
|
181
|
+
setLineBorderWidthTransition(layer, styleValue)
|
|
182
|
+
"lineBorderColor" ->
|
|
183
|
+
setLineBorderColor(layer, styleValue)
|
|
184
|
+
"lineBorderColorTransition" ->
|
|
185
|
+
setLineBorderColorTransition(layer, styleValue)
|
|
178
186
|
"lineZOffset" ->
|
|
179
187
|
setLineZOffset(layer, styleValue)
|
|
180
188
|
"lineElevationReference" ->
|
|
@@ -795,6 +803,8 @@ object RNMBXStyleFactory {
|
|
|
795
803
|
val styleValue = style.getStyleValueForKey(styleKey)
|
|
796
804
|
|
|
797
805
|
when (styleKey) {
|
|
806
|
+
"modelAllowDensityReduction" ->
|
|
807
|
+
setModelAllowDensityReduction(layer, styleValue)
|
|
798
808
|
"visibility" ->
|
|
799
809
|
setVisibility(layer, styleValue)
|
|
800
810
|
"modelId" ->
|
|
@@ -847,6 +857,8 @@ object RNMBXStyleFactory {
|
|
|
847
857
|
setModelHeightBasedEmissiveStrengthMultiplierTransition(layer, styleValue)
|
|
848
858
|
"modelCutoffFadeRange" ->
|
|
849
859
|
setModelCutoffFadeRange(layer, styleValue)
|
|
860
|
+
"modelElevationReference" ->
|
|
861
|
+
setModelElevationReference(layer, styleValue)
|
|
850
862
|
}
|
|
851
863
|
} catch (e: MapboxStyleException) {
|
|
852
864
|
Logger.e(LOG_TAG, "Failed to update: $styleKey ${e.message}")
|
|
@@ -1619,6 +1631,58 @@ object RNMBXStyleFactory {
|
|
|
1619
1631
|
}
|
|
1620
1632
|
}
|
|
1621
1633
|
|
|
1634
|
+
fun setLineBorderWidth(layer: LineLayer, styleValue: RNMBXStyleValue ) {
|
|
1635
|
+
if (styleValue.isExpression()) {
|
|
1636
|
+
val expression = styleValue.getExpression()
|
|
1637
|
+
if (expression != null) {
|
|
1638
|
+
layer.lineBorderWidth(expression)
|
|
1639
|
+
} else {
|
|
1640
|
+
Logger.e("RNMBXLine", "Expression for lineBorderWidth is null")
|
|
1641
|
+
}
|
|
1642
|
+
} else {
|
|
1643
|
+
val value = styleValue.getDouble(VALUE_KEY)
|
|
1644
|
+
if (value != null) {
|
|
1645
|
+
layer.lineBorderWidth(value)
|
|
1646
|
+
} else {
|
|
1647
|
+
Logger.e("RNMBXLine", "value for lineBorderWidth is null")
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
|
|
1653
|
+
fun setLineBorderWidthTransition(layer: LineLayer, styleValue: RNMBXStyleValue) {
|
|
1654
|
+
val transition = styleValue.transition
|
|
1655
|
+
if (transition != null) {
|
|
1656
|
+
layer.lineBorderWidthTransition(transition);
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
fun setLineBorderColor(layer: LineLayer, styleValue: RNMBXStyleValue ) {
|
|
1661
|
+
if (styleValue.isExpression()) {
|
|
1662
|
+
val expression = styleValue.getExpression()
|
|
1663
|
+
if (expression != null) {
|
|
1664
|
+
layer.lineBorderColor(expression)
|
|
1665
|
+
} else {
|
|
1666
|
+
Logger.e("RNMBXLine", "Expression for lineBorderColor is null")
|
|
1667
|
+
}
|
|
1668
|
+
} else {
|
|
1669
|
+
val value = styleValue.getInt(VALUE_KEY)
|
|
1670
|
+
if (value != null) {
|
|
1671
|
+
layer.lineBorderColor(value)
|
|
1672
|
+
} else {
|
|
1673
|
+
Logger.e("RNMBXLine", "value for lineBorderColor is null")
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
|
|
1679
|
+
fun setLineBorderColorTransition(layer: LineLayer, styleValue: RNMBXStyleValue) {
|
|
1680
|
+
val transition = styleValue.transition
|
|
1681
|
+
if (transition != null) {
|
|
1682
|
+
layer.lineBorderColorTransition(transition);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1622
1686
|
fun setLineZOffset(layer: LineLayer, styleValue: RNMBXStyleValue ) {
|
|
1623
1687
|
if (styleValue.isExpression()) {
|
|
1624
1688
|
val expression = styleValue.getExpression()
|
|
@@ -4673,6 +4737,24 @@ object RNMBXStyleFactory {
|
|
|
4673
4737
|
}
|
|
4674
4738
|
}
|
|
4675
4739
|
|
|
4740
|
+
fun setModelAllowDensityReduction(layer: ModelLayer, styleValue: RNMBXStyleValue ) {
|
|
4741
|
+
if (styleValue.isExpression()) {
|
|
4742
|
+
val expression = styleValue.getExpression()
|
|
4743
|
+
if (expression != null) {
|
|
4744
|
+
layer.modelAllowDensityReduction(expression)
|
|
4745
|
+
} else {
|
|
4746
|
+
Logger.e("RNMBXModel", "Expression for modelAllowDensityReduction is null")
|
|
4747
|
+
}
|
|
4748
|
+
} else {
|
|
4749
|
+
val value = styleValue.getBoolean(VALUE_KEY)
|
|
4750
|
+
if (value != null) {
|
|
4751
|
+
layer.modelAllowDensityReduction(value)
|
|
4752
|
+
} else {
|
|
4753
|
+
Logger.e("RNMBXModel", "value for modelAllowDensityReduction is null")
|
|
4754
|
+
}
|
|
4755
|
+
}
|
|
4756
|
+
}
|
|
4757
|
+
|
|
4676
4758
|
fun setVisibility(layer: ModelLayer, styleValue: RNMBXStyleValue ) {
|
|
4677
4759
|
layer.visibility(Visibility.valueOf(styleValue.getEnumName()));
|
|
4678
4760
|
}
|
|
@@ -5022,6 +5104,19 @@ object RNMBXStyleFactory {
|
|
|
5022
5104
|
}
|
|
5023
5105
|
}
|
|
5024
5106
|
|
|
5107
|
+
fun setModelElevationReference(layer: ModelLayer, styleValue: RNMBXStyleValue ) {
|
|
5108
|
+
if (styleValue.isExpression()) {
|
|
5109
|
+
val expression = styleValue.getExpression()
|
|
5110
|
+
if (expression != null) {
|
|
5111
|
+
layer.modelElevationReference(expression)
|
|
5112
|
+
} else {
|
|
5113
|
+
Logger.e("RNMBXModel", "Expression for modelElevationReference is null")
|
|
5114
|
+
}
|
|
5115
|
+
} else {
|
|
5116
|
+
layer.modelElevationReference(ModelElevationReference.valueOf(styleValue.getEnumName()))
|
|
5117
|
+
}
|
|
5118
|
+
}
|
|
5119
|
+
|
|
5025
5120
|
fun setVisibility(layer: BackgroundLayer, styleValue: RNMBXStyleValue ) {
|
|
5026
5121
|
layer.visibility(Visibility.valueOf(styleValue.getEnumName()));
|
|
5027
5122
|
}
|
|
@@ -7,7 +7,7 @@ import com.facebook.react.bridge.WritableMap
|
|
|
7
7
|
/**
|
|
8
8
|
* Direct event for CameraGestureObserver -> onMapSteady
|
|
9
9
|
* JS registrationName: onMapSteady
|
|
10
|
-
* Native event name (key):
|
|
10
|
+
* Native event name (key): onMapSteady
|
|
11
11
|
*/
|
|
12
12
|
class MapSteadyEvent(
|
|
13
13
|
view: View?,
|
|
@@ -16,7 +16,7 @@ class MapSteadyEvent(
|
|
|
16
16
|
private val lastGestureType: String?
|
|
17
17
|
) : AbstractEvent(view, "mapSteady") {
|
|
18
18
|
override val key: String
|
|
19
|
-
get() = "
|
|
19
|
+
get() = "onMapSteady"
|
|
20
20
|
|
|
21
21
|
override val payload: WritableMap
|
|
22
22
|
get() = Arguments.createMap().apply {
|
|
@@ -34,6 +34,12 @@ class MapSteadyEvent(
|
|
|
34
34
|
putDouble("timestamp", System.currentTimeMillis().toDouble())
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
override fun toJSON(): WritableMap {
|
|
38
|
+
val map = Arguments.createMap()
|
|
39
|
+
map.merge(payload)
|
|
40
|
+
return map
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
override fun canCoalesce(): Boolean {
|
|
38
44
|
// Do not coalesce - each steady/timeout event is significant
|
|
39
45
|
return false
|
|
@@ -37,7 +37,6 @@ class RNMBXCameraGestureObserver(
|
|
|
37
37
|
private var lastTransitionEndedAtMs: Double? = null
|
|
38
38
|
private var quietRunnable: Runnable? = null
|
|
39
39
|
private var timeoutRunnable: Runnable? = null
|
|
40
|
-
private var emittedForCurrentActivity: Boolean = false
|
|
41
40
|
|
|
42
41
|
private val quietMs: Double get() = quietPeriodMs ?: 200.0
|
|
43
42
|
private val maxMs: Double? get() = maxIntervalMs
|
|
@@ -84,9 +83,9 @@ class RNMBXCameraGestureObserver(
|
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
private fun scheduleQuietCheck() {
|
|
86
|
+
cancelQuietTimer()
|
|
87
87
|
val delay = quietMs
|
|
88
88
|
if (delay <= 0) {
|
|
89
|
-
cancelQuietTimer()
|
|
90
89
|
maybeEmitSteady()
|
|
91
90
|
return
|
|
92
91
|
}
|
|
@@ -99,8 +98,10 @@ class RNMBXCameraGestureObserver(
|
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
private fun scheduleTimeout() {
|
|
101
|
+
if (timeoutRunnable != null) return
|
|
102
102
|
val delay = maxMs ?: return
|
|
103
103
|
val runnable = Runnable {
|
|
104
|
+
timeoutRunnable = null
|
|
104
105
|
emitTimeout()
|
|
105
106
|
}
|
|
106
107
|
timeoutRunnable = scheduleTimer(delay, runnable)
|
|
@@ -108,7 +109,6 @@ class RNMBXCameraGestureObserver(
|
|
|
108
109
|
|
|
109
110
|
private fun markActivity(gestureType: String? = null) {
|
|
110
111
|
if (gestureType != null) lastGestureType = gestureType
|
|
111
|
-
emittedForCurrentActivity = false
|
|
112
112
|
scheduleQuietCheck()
|
|
113
113
|
scheduleTimeout()
|
|
114
114
|
}
|
|
@@ -122,7 +122,6 @@ class RNMBXCameraGestureObserver(
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
private fun emitSteady(idleDurationMs: Double) {
|
|
125
|
-
if (emittedForCurrentActivity) return
|
|
126
125
|
cancelQuietTimer()
|
|
127
126
|
cancelTimeoutTimer()
|
|
128
127
|
val gesture = lastGestureType
|
|
@@ -131,7 +130,6 @@ class RNMBXCameraGestureObserver(
|
|
|
131
130
|
MapSteadyEvent.make(this, "steady", idleDurationMs, gesture)
|
|
132
131
|
)
|
|
133
132
|
lastGestureType = null
|
|
134
|
-
emittedForCurrentActivity = true
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
private fun emitTimeout() {
|
package/android/src/main/java/com/rnmapbox/rnmbx/events/RNMBXCameraGestureObserverManager.kt
CHANGED
|
@@ -65,7 +65,7 @@ class RNMBXCameraGestureObserverManager(private val mContext: ReactApplicationCo
|
|
|
65
65
|
|
|
66
66
|
// Map the native event name to the JS registration name for direct events
|
|
67
67
|
override fun customEvents(): Map<String, String> = mapOf(
|
|
68
|
-
"
|
|
68
|
+
"onMapSteady" to "onMapSteady"
|
|
69
69
|
)
|
|
70
70
|
|
|
71
71
|
companion object {
|
|
@@ -8,10 +8,13 @@ import com.facebook.react.bridge.ReactMethod
|
|
|
8
8
|
import com.facebook.react.bridge.ReadableMap
|
|
9
9
|
import com.facebook.react.module.annotations.ReactModule
|
|
10
10
|
import com.mapbox.geojson.Feature
|
|
11
|
+
import com.mapbox.geojson.FeatureCollection
|
|
11
12
|
import com.mapbox.geojson.Point
|
|
12
13
|
import com.mapbox.maps.CameraOptions
|
|
14
|
+
import com.mapbox.maps.EdgeInsets
|
|
13
15
|
import com.mapbox.maps.MapSnapshotOptions
|
|
14
16
|
import com.mapbox.maps.Size
|
|
17
|
+
import com.mapbox.maps.SnapshotOverlayOptions
|
|
15
18
|
import com.mapbox.maps.Snapshotter
|
|
16
19
|
import com.rnmapbox.rnmbx.modules.RNMBXModule.Companion.getAccessToken
|
|
17
20
|
import com.rnmapbox.rnmbx.modules.RNMBXSnapshotModule
|
|
@@ -43,30 +46,38 @@ class RNMBXSnapshotModule(private val mContext: ReactApplicationContext) :
|
|
|
43
46
|
// FileSource.getInstance(mContext).activate();
|
|
44
47
|
mContext.runOnUiQueueThread {
|
|
45
48
|
val snapshotterID = UUID.randomUUID().toString()
|
|
46
|
-
val
|
|
49
|
+
val showLogo = if (jsOptions.hasKey("withLogo")) jsOptions.getBoolean("withLogo") else true
|
|
50
|
+
val overlayOptions = SnapshotOverlayOptions(showLogo = showLogo)
|
|
51
|
+
val snapshotter = Snapshotter(mContext, getOptions(jsOptions), overlayOptions)
|
|
47
52
|
snapshotter.setStyleUri(jsOptions.getString("styleURL")!!)
|
|
48
|
-
|
|
53
|
+
try {
|
|
54
|
+
snapshotter.setCamera(getCameraOptions(jsOptions, snapshotter))
|
|
55
|
+
} catch (e: IllegalArgumentException) {
|
|
56
|
+
promise.reject(REACT_CLASS, e.message, e)
|
|
57
|
+
return@runOnUiQueueThread
|
|
58
|
+
}
|
|
49
59
|
mSnapshotterMap[snapshotterID] = snapshotter
|
|
50
|
-
|
|
60
|
+
|
|
61
|
+
snapshotter.start(null) { image, error ->
|
|
51
62
|
try {
|
|
52
63
|
if (image == null) {
|
|
53
64
|
Log.w(REACT_CLASS, "Snapshot failed: $error")
|
|
54
65
|
promise.reject(REACT_CLASS, "Snapshot failed: $error")
|
|
55
66
|
mSnapshotterMap.remove(snapshotterID)
|
|
56
67
|
} else {
|
|
57
|
-
val
|
|
68
|
+
val mapboxImage = image.toMapboxImage()
|
|
58
69
|
var result: String? = null
|
|
59
70
|
result = if (jsOptions.getBoolean("writeToDisk")) {
|
|
60
|
-
BitmapUtils.createImgTempFile(mContext,
|
|
71
|
+
BitmapUtils.createImgTempFile(mContext, mapboxImage)
|
|
61
72
|
} else {
|
|
62
|
-
BitmapUtils.createImgBase64(
|
|
73
|
+
BitmapUtils.createImgBase64(mapboxImage)
|
|
63
74
|
}
|
|
64
75
|
if (result == null) {
|
|
65
76
|
promise.reject(
|
|
66
77
|
REACT_CLASS,
|
|
67
78
|
"Could not generate snapshot, please check Android logs for more info."
|
|
68
79
|
)
|
|
69
|
-
return@
|
|
80
|
+
return@start
|
|
70
81
|
}
|
|
71
82
|
promise.resolve(result)
|
|
72
83
|
mSnapshotterMap.remove(snapshotterID)
|
|
@@ -79,17 +90,44 @@ class RNMBXSnapshotModule(private val mContext: ReactApplicationContext) :
|
|
|
79
90
|
}
|
|
80
91
|
}
|
|
81
92
|
|
|
82
|
-
private fun getCameraOptions(jsOptions: ReadableMap): CameraOptions {
|
|
83
|
-
val
|
|
84
|
-
|
|
85
|
-
val
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
.
|
|
90
|
-
.
|
|
91
|
-
.
|
|
92
|
-
|
|
93
|
+
private fun getCameraOptions(jsOptions: ReadableMap, snapshotter: Snapshotter): CameraOptions {
|
|
94
|
+
val pitch = jsOptions.getDouble("pitch")
|
|
95
|
+
val heading = jsOptions.getDouble("heading")
|
|
96
|
+
val zoomLevel = jsOptions.getDouble("zoomLevel")
|
|
97
|
+
|
|
98
|
+
// Check if centerCoordinate is provided
|
|
99
|
+
if (jsOptions.hasKey("centerCoordinate") && !jsOptions.isNull("centerCoordinate")) {
|
|
100
|
+
val centerPoint = Feature.fromJson(jsOptions.getString("centerCoordinate")!!)
|
|
101
|
+
val point = centerPoint.geometry() as Point?
|
|
102
|
+
return CameraOptions.Builder()
|
|
103
|
+
.center(point)
|
|
104
|
+
.pitch(pitch)
|
|
105
|
+
.bearing(heading)
|
|
106
|
+
.zoom(zoomLevel)
|
|
107
|
+
.build()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Check if bounds is provided
|
|
111
|
+
if (jsOptions.hasKey("bounds") && !jsOptions.isNull("bounds")) {
|
|
112
|
+
val boundsJson = jsOptions.getString("bounds")!!
|
|
113
|
+
val featureCollection = FeatureCollection.fromJson(boundsJson)
|
|
114
|
+
val coords = featureCollection.features()?.mapNotNull { feature ->
|
|
115
|
+
feature.geometry() as? Point
|
|
116
|
+
} ?: emptyList()
|
|
117
|
+
|
|
118
|
+
if (coords.isEmpty()) {
|
|
119
|
+
throw IllegalArgumentException("bounds contains no valid coordinates")
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return snapshotter.cameraForCoordinates(
|
|
123
|
+
coords,
|
|
124
|
+
EdgeInsets(0.0, 0.0, 0.0, 0.0),
|
|
125
|
+
heading,
|
|
126
|
+
pitch
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
throw IllegalArgumentException("neither centerCoordinate nor bounds provided")
|
|
93
131
|
}
|
|
94
132
|
|
|
95
133
|
private fun getOptions(jsOptions: ReadableMap): MapSnapshotOptions {
|
package/ios/RNMBX/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
iOS
|
|
1
|
+
iOS native code
|
|
@@ -30,7 +30,7 @@ public class RNMBXBackgroundLayer: RNMBXLayer {
|
|
|
30
30
|
styler.backgroundLayer(
|
|
31
31
|
layer: &styleLayer,
|
|
32
32
|
reactStyle: reactStyle,
|
|
33
|
-
oldReactStyle:
|
|
33
|
+
oldReactStyle: oldReactStyle,
|
|
34
34
|
applyUpdater: { (updater) in logged("RNMBXBackgroundLayer.addStyles") {
|
|
35
35
|
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
|
|
36
36
|
}},
|
|
@@ -45,6 +45,16 @@ using namespace facebook::react;
|
|
|
45
45
|
return concreteComponentDescriptorProvider<RNMBXCalloutComponentDescriptor>();
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
|
|
49
|
+
{
|
|
50
|
+
[_view insertSubview:childComponentView atIndex:index];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
|
|
54
|
+
{
|
|
55
|
+
[childComponentView removeFromSuperview];
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
|
|
49
59
|
{
|
|
50
60
|
const auto &newProps = static_cast<const RNMBXCalloutProps &>(*props);
|
|
@@ -595,14 +595,14 @@ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
|
|
|
595
595
|
return super.removeFromMap(map, mapView: mapView, reason: reason)
|
|
596
596
|
}
|
|
597
597
|
|
|
598
|
-
@objc public func moveBy(x: Double, y: Double, animationMode:
|
|
598
|
+
@objc public func moveBy(x: Double, y: Double, animationMode: Double, animationDuration: Double, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
599
599
|
withMapView { mapView in
|
|
600
600
|
let contentFrame = mapView.bounds.inset(by: mapView.safeAreaInsets)
|
|
601
601
|
let centerPoint = CGPoint(x: contentFrame.midX, y: contentFrame.midY)
|
|
602
602
|
let endCameraPoint = CGPoint(x: centerPoint.x + x, y: centerPoint.y + y)
|
|
603
603
|
let cameraOptions = mapView.mapboxMap.dragCameraOptions(from: centerPoint, to: endCameraPoint)
|
|
604
604
|
|
|
605
|
-
let duration =
|
|
605
|
+
let duration = animationDuration / 1000
|
|
606
606
|
|
|
607
607
|
if (duration == 0.0) {
|
|
608
608
|
mapView.mapboxMap.setCamera(to: cameraOptions)
|
|
@@ -611,7 +611,7 @@ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
|
|
|
611
611
|
}
|
|
612
612
|
|
|
613
613
|
var curve: UIView.AnimationCurve = .linear
|
|
614
|
-
if let m =
|
|
614
|
+
if let m = CameraMode(rawValue: Int(animationMode)) {
|
|
615
615
|
curve = m == CameraMode.ease ? .easeInOut : .linear
|
|
616
616
|
}
|
|
617
617
|
|
|
@@ -622,18 +622,18 @@ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
|
|
|
622
622
|
@objc public func scaleBy(
|
|
623
623
|
x: Double,
|
|
624
624
|
y: Double,
|
|
625
|
-
scaleFactor:
|
|
626
|
-
animationMode:
|
|
627
|
-
animationDuration:
|
|
625
|
+
scaleFactor: Double,
|
|
626
|
+
animationMode: Double,
|
|
627
|
+
animationDuration: Double,
|
|
628
628
|
resolve: @escaping RCTPromiseResolveBlock,
|
|
629
629
|
reject: @escaping RCTPromiseRejectBlock
|
|
630
630
|
) {
|
|
631
631
|
withMapView { mapView in
|
|
632
632
|
let currentZoom = mapView.cameraState.zoom
|
|
633
|
-
let newZoom = currentZoom + log2(scaleFactor
|
|
633
|
+
let newZoom = currentZoom + log2(scaleFactor)
|
|
634
634
|
let anchor = CGPoint(x: x, y: y)
|
|
635
635
|
let cameraOptions = CameraOptions(anchor: anchor, zoom: newZoom)
|
|
636
|
-
let duration =
|
|
636
|
+
let duration = animationDuration / 1000
|
|
637
637
|
|
|
638
638
|
if (duration == 0.0) {
|
|
639
639
|
mapView.mapboxMap.setCamera(to: cameraOptions)
|
|
@@ -642,7 +642,7 @@ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
|
|
|
642
642
|
}
|
|
643
643
|
|
|
644
644
|
var curve: UIView.AnimationCurve = .linear
|
|
645
|
-
if let m =
|
|
645
|
+
if let m = CameraMode(rawValue: Int(animationMode)) {
|
|
646
646
|
curve = m == CameraMode.ease ? .easeInOut : .linear
|
|
647
647
|
}
|
|
648
648
|
|
|
@@ -53,8 +53,8 @@ RCT_EXPORT_METHOD(updateCameraStop:(nonnull NSNumber *)viewRef
|
|
|
53
53
|
RCT_EXPORT_METHOD(moveBy:(nonnull NSNumber *)viewRef
|
|
54
54
|
x:(double)x
|
|
55
55
|
y:(double)y
|
|
56
|
-
animationMode:(
|
|
57
|
-
animationDuration:(
|
|
56
|
+
animationMode:(double)animationMode
|
|
57
|
+
animationDuration:(double)animationDuration
|
|
58
58
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
59
59
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
60
60
|
[self withCamera:viewRef block:^(RNMBXCamera *camera) {
|
|
@@ -65,9 +65,9 @@ RCT_EXPORT_METHOD(moveBy:(nonnull NSNumber *)viewRef
|
|
|
65
65
|
RCT_EXPORT_METHOD(scaleBy:(nonnull NSNumber *)viewRef
|
|
66
66
|
x:(double)x
|
|
67
67
|
y:(double)y
|
|
68
|
-
animationMode:(
|
|
69
|
-
animationDuration:(
|
|
70
|
-
scaleFactor:(
|
|
68
|
+
animationMode:(double)animationMode
|
|
69
|
+
animationDuration:(double)animationDuration
|
|
70
|
+
scaleFactor:(double)scaleFactor
|
|
71
71
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
72
72
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
73
73
|
[self withCamera:viewRef block:^(RNMBXCamera *camera) {
|
|
@@ -80,7 +80,7 @@ public class RNMBXCircleLayer: RNMBXVectorLayer {
|
|
|
80
80
|
styler.circleLayer(
|
|
81
81
|
layer: &styleLayer,
|
|
82
82
|
reactStyle: reactStyle,
|
|
83
|
-
oldReactStyle:
|
|
83
|
+
oldReactStyle: oldReactStyle,
|
|
84
84
|
applyUpdater: { (updater) in logged("RNMBXCircleLayer.updateLayer") {
|
|
85
85
|
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
|
|
86
86
|
}},
|
|
@@ -78,7 +78,7 @@ public class RNMBXFillExtrusionLayer: RNMBXVectorLayer {
|
|
|
78
78
|
styler.fillExtrusionLayer(
|
|
79
79
|
layer: &styleLayer,
|
|
80
80
|
reactStyle: reactStyle,
|
|
81
|
-
oldReactStyle:
|
|
81
|
+
oldReactStyle: oldReactStyle,
|
|
82
82
|
applyUpdater: { (updater) in logged("RNMBXFillExtrusionLayer.updateLayer") {
|
|
83
83
|
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
|
|
84
84
|
}},
|
|
@@ -80,7 +80,7 @@ public class RNMBXFillLayer: RNMBXVectorLayer {
|
|
|
80
80
|
styler.fillLayer(
|
|
81
81
|
layer: &styleLayer,
|
|
82
82
|
reactStyle: reactStyle,
|
|
83
|
-
oldReactStyle:
|
|
83
|
+
oldReactStyle: oldReactStyle,
|
|
84
84
|
applyUpdater: { (updater) in logged("RNMBXFillLayer.updateLayer") {
|
|
85
85
|
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout FillLayer) in updater(&layer) }
|
|
86
86
|
}},
|
|
@@ -34,7 +34,7 @@ public class RNMBXHeatmapLayer: RNMBXVectorLayer {
|
|
|
34
34
|
styler.heatmapLayer(
|
|
35
35
|
layer: &styleLayer,
|
|
36
36
|
reactStyle: reactStyle,
|
|
37
|
-
oldReactStyle:
|
|
37
|
+
oldReactStyle: oldReactStyle,
|
|
38
38
|
applyUpdater: { (updater) in logged("RNMBXHeatmapLayer.updateLayer") {
|
|
39
39
|
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout HeatmapLayer) in updater(&layer) }
|
|
40
40
|
}},
|
|
@@ -73,7 +73,7 @@ public class RNMBXHillshadeLayer: RNMBXLayer {
|
|
|
73
73
|
styler.hillshadeLayer(
|
|
74
74
|
layer: &styleLayer,
|
|
75
75
|
reactStyle: reactStyle,
|
|
76
|
-
oldReactStyle:
|
|
76
|
+
oldReactStyle: oldReactStyle,
|
|
77
77
|
applyUpdater:{ (updater) in logged("RNMBXHillshadeLayer.updateLayer") {
|
|
78
78
|
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
|
|
79
79
|
}},
|
|
@@ -19,10 +19,10 @@ public class RNMBXLayer : UIView, RNMBXMapComponent, RNMBXSourceConsumer {
|
|
|
19
19
|
didSet { self.optionsChanged() }
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var oldReactStyle: Dictionary<String, Any>? = nil
|
|
23
23
|
@objc public var reactStyle : Dictionary<String, Any>? = nil {
|
|
24
24
|
willSet {
|
|
25
|
-
|
|
25
|
+
oldReactStyle = reactStyle
|
|
26
26
|
}
|
|
27
27
|
didSet {
|
|
28
28
|
DispatchQueue.main.async {
|