@rnmapbox/maps 10.3.0-beta.1 → 10.3.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.
Files changed (86) hide show
  1. package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt +55 -0
  2. package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContentManager.kt +7 -2
  3. package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewManager.kt +0 -2
  4. package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotation.kt +14 -1
  5. package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotationManager.kt +11 -0
  6. package/android/src/main/java/com/rnmapbox/rnmbx/components/location/RNMBXNativeUserLocationManager.kt +25 -24
  7. package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt +3 -2
  8. package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt +57 -39
  9. package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapViewManager.kt +0 -9
  10. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/RNMBXStyleFactory.kt +60 -0
  11. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/atmosphere/RNMBXAtmosphere.kt +4 -4
  12. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/atmosphere/RNMBXAtmosphereManager.kt +2 -1
  13. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/light/RNMBXLightManager.kt +2 -1
  14. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXSource.kt +2 -6
  15. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/terrain/RNMBXTerrainManager.kt +2 -1
  16. package/android/src/main/java/com/rnmapbox/rnmbx/events/FeatureClickEvent.java +5 -6
  17. package/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt +1 -0
  18. package/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXSnapshotModule.kt +56 -18
  19. package/android/src/main/java/com/rnmapbox/rnmbx/utils/ConvertUtils.kt +0 -30
  20. package/android/src/main/java/com/rnmapbox/rnmbx/utils/extensions/Dynamic.kt +3 -1
  21. package/android/src/main/java/com/rnmapbox/rnmbx/utils/extensions/ReadableArray.kt +16 -14
  22. package/ios/RNMBX/RNMBXBackgroundLayer.swift +1 -1
  23. package/ios/RNMBX/RNMBXCalloutComponentView.mm +10 -0
  24. package/ios/RNMBX/RNMBXCircleLayer.swift +1 -1
  25. package/ios/RNMBX/RNMBXFillExtrusionLayer.swift +1 -1
  26. package/ios/RNMBX/RNMBXFillLayer.swift +1 -1
  27. package/ios/RNMBX/RNMBXHeatmapLayer.swift +1 -1
  28. package/ios/RNMBX/RNMBXHillshadeLayer.swift +1 -1
  29. package/ios/RNMBX/RNMBXLayer.swift +2 -2
  30. package/ios/RNMBX/RNMBXLineLayer.swift +1 -1
  31. package/ios/RNMBX/RNMBXMapView.swift +18 -1
  32. package/ios/RNMBX/RNMBXMapViewComponentView.mm +3 -0
  33. package/ios/RNMBX/RNMBXMapViewModule.mm +1 -1
  34. package/ios/RNMBX/RNMBXModelLayer.swift +1 -1
  35. package/ios/RNMBX/RNMBXModule.swift +1 -0
  36. package/ios/RNMBX/RNMBXPointAnnotation.swift +25 -3
  37. package/ios/RNMBX/RNMBXPointAnnotationComponentView.mm +1 -0
  38. package/ios/RNMBX/RNMBXRasterLayer.swift +1 -1
  39. package/ios/RNMBX/RNMBXRasterParticleLayer.swift +1 -1
  40. package/ios/RNMBX/RNMBXSkyLayer.swift +1 -1
  41. package/ios/RNMBX/RNMBXSnapshotModule.swift +3 -1
  42. package/ios/RNMBX/RNMBXStyle.swift +36 -0
  43. package/ios/RNMBX/RNMBXSymbolLayer.swift +1 -1
  44. package/lib/module/Mapbox.native.js.map +1 -1
  45. package/lib/module/components/MapView.js +95 -113
  46. package/lib/module/components/MapView.js.map +1 -1
  47. package/lib/module/components/MarkerView.js +93 -76
  48. package/lib/module/components/MarkerView.js.map +1 -1
  49. package/lib/module/components/UserLocation.js +2 -1
  50. package/lib/module/components/UserLocation.js.map +1 -1
  51. package/lib/module/modules/offline/offlineManager.js +2 -12
  52. package/lib/module/modules/offline/offlineManager.js.map +1 -1
  53. package/lib/module/specs/RNMBXMarkerViewContentNativeComponent.ts +13 -1
  54. package/lib/module/specs/RNMBXPointAnnotationNativeComponent.ts +1 -0
  55. package/lib/module/utils/styleMap.js +4 -0
  56. package/lib/module/utils/styleMap.js.map +1 -1
  57. package/lib/typescript/scripts/autogenHelpers/generateCodeWithEjs.d.mts.map +1 -1
  58. package/lib/typescript/src/Mapbox.native.d.ts +1 -1
  59. package/lib/typescript/src/Mapbox.native.d.ts.map +1 -1
  60. package/lib/typescript/src/components/Camera.d.ts +2 -2
  61. package/lib/typescript/src/components/Camera.d.ts.map +1 -1
  62. package/lib/typescript/src/components/MapView.d.ts +53 -41
  63. package/lib/typescript/src/components/MapView.d.ts.map +1 -1
  64. package/lib/typescript/src/components/MarkerView.d.ts +10 -17
  65. package/lib/typescript/src/components/MarkerView.d.ts.map +1 -1
  66. package/lib/typescript/src/components/UserLocation.d.ts.map +1 -1
  67. package/lib/typescript/src/modules/offline/offlineManager.d.ts.map +1 -1
  68. package/lib/typescript/src/specs/RNMBXMarkerViewContentNativeComponent.d.ts +6 -0
  69. package/lib/typescript/src/specs/RNMBXMarkerViewContentNativeComponent.d.ts.map +1 -1
  70. package/lib/typescript/src/specs/RNMBXPointAnnotationNativeComponent.d.ts +1 -0
  71. package/lib/typescript/src/specs/RNMBXPointAnnotationNativeComponent.d.ts.map +1 -1
  72. package/lib/typescript/src/utils/MapboxStyles.d.ts +16 -0
  73. package/lib/typescript/src/utils/MapboxStyles.d.ts.map +1 -1
  74. package/lib/typescript/src/utils/styleMap.d.ts.map +1 -1
  75. package/package.json +1 -1
  76. package/setup-jest.js +1 -1
  77. package/src/Mapbox.native.ts +5 -1
  78. package/src/components/Camera.tsx +2 -2
  79. package/src/components/MapView.tsx +137 -154
  80. package/src/components/MarkerView.tsx +118 -95
  81. package/src/components/UserLocation.tsx +3 -2
  82. package/src/modules/offline/offlineManager.ts +2 -14
  83. package/src/specs/RNMBXMarkerViewContentNativeComponent.ts +13 -1
  84. package/src/specs/RNMBXPointAnnotationNativeComponent.ts +1 -0
  85. package/src/utils/MapboxStyles.ts +18 -0
  86. package/src/utils/styleMap.ts +4 -0
@@ -6,22 +6,18 @@ import com.mapbox.maps.extension.style.sources.addSource
6
6
  import com.rnmapbox.rnmbx.components.AbstractMapFeature
7
7
  import com.rnmapbox.rnmbx.components.mapview.RNMBXMapView
8
8
  import com.mapbox.maps.MapboxMap
9
- import com.rnmapbox.rnmbx.components.styles.sources.AbstractSourceConsumer
10
9
  import com.facebook.react.bridge.ReadableMap
11
- import com.rnmapbox.rnmbx.components.styles.sources.RNMBXSource
12
- import android.graphics.PointF
13
10
  import android.view.View
14
11
  import com.facebook.react.common.MapBuilder
15
12
  import com.mapbox.geojson.Feature
13
+ import com.mapbox.maps.ScreenCoordinate
16
14
  import com.mapbox.maps.Style
17
15
  import com.mapbox.maps.extension.style.StyleContract
18
16
  import com.mapbox.maps.extension.style.sources.Source
19
17
  import com.rnmapbox.rnmbx.components.RemovalReason
20
- import com.rnmapbox.rnmbx.components.styles.sources.RNMBXSource.OnPressEvent
21
18
  import com.rnmapbox.rnmbx.utils.LatLng
22
19
  import com.rnmapbox.rnmbx.utils.Logger
23
20
  import java.lang.ClassCastException
24
- import java.util.ArrayList
25
21
  import java.util.HashMap
26
22
 
27
23
  data class FeatureInfo(val feature: AbstractMapFeature?, var added: Boolean) {
@@ -221,7 +217,7 @@ abstract class RNMBXSource<T : Source?>(context: Context?) : AbstractMapFeature(
221
217
 
222
218
 
223
219
  abstract fun makeSource(): T
224
- class OnPressEvent(var features: List<Feature>, var latLng: LatLng, var screenPoint: PointF)
220
+ class OnPressEvent(var features: List<Feature>, var latLng: LatLng, var screenPoint: ScreenCoordinate)
225
221
 
226
222
  abstract fun onPress(event: OnPressEvent?)
227
223
 
@@ -2,6 +2,7 @@ package com.rnmapbox.rnmbx.components.styles.terrain
2
2
 
3
3
  import com.facebook.react.bridge.Dynamic
4
4
  import com.facebook.react.uimanager.ThemedReactContext
5
+ import com.rnmapbox.rnmbx.utils.extensions.asMapOrNull
5
6
  import com.facebook.react.uimanager.ViewGroupManager
6
7
  import com.facebook.react.uimanager.annotations.ReactProp
7
8
  import com.facebook.react.viewmanagers.RNMBXTerrainManagerInterface
@@ -23,7 +24,7 @@ class RNMBXTerrainManager : ViewGroupManager<RNMBXTerrain>(),
23
24
 
24
25
  @ReactProp(name = "reactStyle")
25
26
  override fun setReactStyle(terrain: RNMBXTerrain, reactStyle: Dynamic) {
26
- terrain.setReactStyle(reactStyle.asMap())
27
+ terrain.setReactStyle(reactStyle.asMapOrNull())
27
28
  }
28
29
 
29
30
  companion object {
@@ -1,16 +1,15 @@
1
1
  package com.rnmapbox.rnmbx.events;
2
2
 
3
- import android.graphics.PointF;
4
3
  import android.view.View;
5
4
 
6
5
  import com.facebook.react.bridge.Arguments;
7
6
  import com.facebook.react.bridge.WritableArray;
8
7
  import com.facebook.react.bridge.WritableMap;
9
8
  import com.mapbox.geojson.Feature;
9
+ import com.mapbox.maps.ScreenCoordinate;
10
10
  import com.rnmapbox.rnmbx.components.styles.sources.RNMBXSource;
11
11
  import com.rnmapbox.rnmbx.events.constants.EventKeys;
12
12
  import com.rnmapbox.rnmbx.events.constants.EventTypes;
13
- import com.rnmapbox.rnmbx.utils.ConvertUtils;
14
13
  import com.rnmapbox.rnmbx.utils.GeoJSONUtils;
15
14
  import com.rnmapbox.rnmbx.utils.LatLng;
16
15
 
@@ -24,9 +23,9 @@ public class FeatureClickEvent extends AbstractEvent {
24
23
  private String mEventKey;
25
24
  private List<Feature> mFeatures;
26
25
  private LatLng mLatLng;
27
- private PointF mPoint;
26
+ private ScreenCoordinate mPoint;
28
27
 
29
- public FeatureClickEvent(View view, String eventKey, String eventType, List<Feature> features, LatLng latLng, PointF point) {
28
+ public FeatureClickEvent(View view, String eventKey, String eventType, List<Feature> features, LatLng latLng, ScreenCoordinate point) {
30
29
  super(view, eventType);
31
30
  mFeatures = features;
32
31
  mEventKey = eventKey;
@@ -55,8 +54,8 @@ public class FeatureClickEvent extends AbstractEvent {
55
54
  map.putMap("coordinates", coordinates);
56
55
 
57
56
  WritableMap point = Arguments.createMap();
58
- point.putDouble("x", mPoint.x);
59
- point.putDouble("y", mPoint.y);
57
+ point.putDouble("x", mPoint.getX());
58
+ point.putDouble("y", mPoint.getY());
60
59
  map.putMap("point", point);
61
60
 
62
61
  return map;
@@ -114,6 +114,7 @@ class RNMBXModule(private val mReactContext: ReactApplicationContext) : ReactCon
114
114
  val locationModuleCallbackNames: MutableMap<String, String> = HashMap()
115
115
  locationModuleCallbackNames["Update"] = RNMBXLocationModule.LOCATION_UPDATE
116
116
  return MapBuilder.builder<String, Any>()
117
+ // Deprecated: means v10 or later, always true. Will be removed in next major version.
117
118
  .put("MapboxV10", true)
118
119
  .put("StyleURL", styleURLS)
119
120
  .put("EventTypes", eventTypes)
@@ -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 snapshotter = Snapshotter(mContext, getOptions(jsOptions))
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
- snapshotter.setCamera(getCameraOptions(jsOptions))
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
- snapshotter.startV11 { image,error ->
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 image = image.toMapboxImage()
68
+ val mapboxImage = image.toMapboxImage()
58
69
  var result: String? = null
59
70
  result = if (jsOptions.getBoolean("writeToDisk")) {
60
- BitmapUtils.createImgTempFile(mContext, image)
71
+ BitmapUtils.createImgTempFile(mContext, mapboxImage)
61
72
  } else {
62
- BitmapUtils.createImgBase64(image)
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@startV11
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 centerPoint =
84
- Feature.fromJson(jsOptions.getString("centerCoordinate")!!)
85
- val point = centerPoint.geometry() as Point?
86
- val cameraOptionsBuilder = CameraOptions.Builder()
87
- return cameraOptionsBuilder
88
- .center(point)
89
- .pitch(jsOptions.getDouble("pitch"))
90
- .bearing(jsOptions.getDouble("heading"))
91
- .zoom(jsOptions.getDouble("zoomLevel"))
92
- .build()
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 {
@@ -1,7 +1,5 @@
1
1
  package com.rnmapbox.rnmbx.utils
2
2
 
3
- import android.graphics.PointF
4
- import android.graphics.RectF
5
3
  import android.util.Log
6
4
  import com.facebook.react.bridge.Arguments
7
5
  import com.facebook.react.bridge.NoSuchKeyException
@@ -172,34 +170,6 @@ object ConvertUtils {
172
170
  return list
173
171
  }
174
172
 
175
- fun toPointF(array: ReadableArray?): PointF {
176
- val pointF = PointF()
177
-
178
- if (array == null) {
179
- return pointF
180
- }
181
-
182
- pointF.set(array.getDouble(0).toFloat(), array.getDouble(1).toFloat())
183
- return pointF
184
- }
185
-
186
- // returns null if array is null
187
- fun toRectF(array: ReadableArray?): RectF? {
188
- val rectF = RectF()
189
-
190
- if (array == null || array.size() == 0) {
191
- return null
192
- }
193
-
194
- rectF.set(
195
- array.getDouble(3).toFloat(),
196
- array.getDouble(0).toFloat(),
197
- array.getDouble(1).toFloat(),
198
- array.getDouble(2).toFloat()
199
- )
200
- return rectF
201
- }
202
-
203
173
  fun getDouble(key: String, map: ReadableMap, defaultValue: Double): Double {
204
174
  var value = defaultValue
205
175
 
@@ -107,4 +107,6 @@ fun Dynamic.asStringOrNull(): String? {
107
107
  } else {
108
108
  asString()
109
109
  }
110
- }
110
+ }
111
+
112
+ fun Dynamic.asMapOrNull(): ReadableMap? = if (isNull) null else asMap()
@@ -1,17 +1,15 @@
1
1
  package com.rnmapbox.rnmbx.utils.extensions
2
2
 
3
- import android.graphics.RectF
4
3
  import com.facebook.react.bridge.ReadableArray
5
4
  import com.facebook.react.bridge.ReadableType
6
5
  import com.google.gson.JsonArray
7
6
  import com.google.gson.JsonElement
8
7
  import com.mapbox.geojson.Point
8
+ import com.mapbox.maps.ScreenBox
9
9
  import com.mapbox.maps.ScreenCoordinate
10
- import com.rnmapbox.rnmbx.utils.ConvertUtils
11
10
  import com.rnmapbox.rnmbx.utils.Logger
12
- import org.json.JSONArray
13
- import java.lang.Float.max
14
- import java.lang.Float.min
11
+ import kotlin.math.max
12
+ import kotlin.math.min
15
13
 
16
14
  fun ReadableArray.toCoordinate() : Point {
17
15
  if (this.size() != 2) {
@@ -25,20 +23,24 @@ fun ReadableArray.toCoordinate() : Point {
25
23
 
26
24
  fun ReadableArray.toScreenCoordinate() : ScreenCoordinate {
27
25
  if (this.size() != 2) {
28
- Logger.e("ReadableArray.toCoordinate","Cannot convert $this to point, 2 coordinates are required")
26
+ Logger.e("ReadableArray.toScreenCoordinate","Cannot convert $this to point, 2 coordinates are required")
29
27
  }
30
28
  return ScreenCoordinate(getDouble(0), getDouble(1))
31
29
  }
32
30
 
33
- fun ReadableArray.toRectF() : RectF? {
34
- if (size() != 4) {
35
- return null;
31
+ fun ReadableArray.toScreenBox() : ScreenBox {
32
+ if (this.size() != 4) {
33
+ Logger.e("ReadableArray.toScreenBox","Cannot convert $this to box, 4 coordinates are required")
36
34
  }
37
- return RectF(
38
- min(getDouble(3).toFloat(), getDouble(1).toFloat()),
39
- min(getDouble(0).toFloat(), getDouble(2).toFloat()),
40
- max(getDouble(3).toFloat(), getDouble(1).toFloat()),
41
- max(getDouble(0).toFloat(), getDouble(2).toFloat())
35
+
36
+ val top = getDouble(0)
37
+ val left = getDouble(1)
38
+ val bottom = getDouble(2)
39
+ val right = getDouble(3)
40
+
41
+ return ScreenBox(
42
+ ScreenCoordinate(min(left, right), min(top, bottom)),
43
+ ScreenCoordinate(max(left, right), max(top, bottom))
42
44
  )
43
45
  }
44
46
 
@@ -30,7 +30,7 @@ public class RNMBXBackgroundLayer: RNMBXLayer {
30
30
  styler.backgroundLayer(
31
31
  layer: &styleLayer,
32
32
  reactStyle: reactStyle,
33
- oldReactStyle: oldReatStyle,
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);
@@ -80,7 +80,7 @@ public class RNMBXCircleLayer: RNMBXVectorLayer {
80
80
  styler.circleLayer(
81
81
  layer: &styleLayer,
82
82
  reactStyle: reactStyle,
83
- oldReactStyle: oldReatStyle,
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: oldReatStyle,
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: oldReatStyle,
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: oldReatStyle,
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: oldReatStyle,
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 oldReatStyle: Dictionary<String, Any>? = nil
22
+ var oldReactStyle: Dictionary<String, Any>? = nil
23
23
  @objc public var reactStyle : Dictionary<String, Any>? = nil {
24
24
  willSet {
25
- oldReatStyle = reactStyle
25
+ oldReactStyle = reactStyle
26
26
  }
27
27
  didSet {
28
28
  DispatchQueue.main.async {
@@ -79,7 +79,7 @@ public class RNMBXLineLayer: RNMBXVectorLayer {
79
79
  styler.lineLayer(
80
80
  layer: &styleLayer,
81
81
  reactStyle: reactStyle,
82
- oldReactStyle: oldReatStyle,
82
+ oldReactStyle: oldReactStyle,
83
83
  applyUpdater: { (updater) in logged("RNMBXLineLayer.updateLayer") {
84
84
  try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
85
85
  }},
@@ -236,7 +236,9 @@ open class RNMBXMapView: UIView, RCTInvalidating {
236
236
  }()
237
237
 
238
238
  lazy var calloutAnnotationManager : MapboxMaps.PointAnnotationManager = {
239
- return mapView.annotations.makePointAnnotationManager(id: "RNMBX-mapview-callouts")
239
+ let manager = mapView.annotations.makePointAnnotationManager(id: "RNMBX-mapview-callouts")
240
+ manager.iconAllowOverlap = true
241
+ return manager
240
242
  }()
241
243
 
242
244
  var _mapView: MapView! = nil
@@ -1893,6 +1895,20 @@ class RNMBXPointAnnotationManager : AnnotationInteractionDelegate {
1893
1895
  // onTap(annotations: annotations)
1894
1896
  }
1895
1897
 
1898
+ func selected(pointAnnotation: RNMBXPointAnnotation) {
1899
+ if (selected != nil) {
1900
+ deselectCurrentlySelected(deselectAnnotationOnTap: false)
1901
+ }
1902
+ pointAnnotation.doSelect()
1903
+ selected = pointAnnotation
1904
+ }
1905
+
1906
+ func unselected(pointAnnotation: RNMBXPointAnnotation) {
1907
+ if (selected == pointAnnotation) {
1908
+ deselectCurrentlySelected(deselectAnnotationOnTap: false)
1909
+ }
1910
+ }
1911
+
1896
1912
  func deselectCurrentlySelected(deselectAnnotationOnTap: Bool = false) -> Bool {
1897
1913
  if let selected = selected {
1898
1914
  selected.doDeselect(deselectAnnotationOnMapTap: deselectAnnotationOnTap)
@@ -2120,6 +2136,7 @@ class RNMBXPointAnnotationManager : AnnotationInteractionDelegate {
2120
2136
  )
2121
2137
 
2122
2138
  func add(_ annotation: PointAnnotation, _ rnmbxPointAnnotation: RNMBXPointAnnotation) {
2139
+ rnmbxPointAnnotation.manager = self
2123
2140
  manager.annotations.append(annotation)
2124
2141
  manager.refresh()
2125
2142
  annotations.setObject(rnmbxPointAnnotation, forKey: annotation.id as NSString)
@@ -120,6 +120,9 @@ using namespace facebook::react;
120
120
  }
121
121
 
122
122
  - (void)dispatchCameraChangedEvent:(NSDictionary*)event {
123
+ if (self->_eventEmitter == nullptr) {
124
+ return;
125
+ }
123
126
  const auto [type, json] = RNMBXStringifyEventData(event);
124
127
  std::dynamic_pointer_cast<const facebook::react::RNMBXMapViewEventEmitter>(self->_eventEmitter)->onCameraChanged({type, json});
125
128
  }
@@ -60,7 +60,7 @@ RCT_EXPORT_METHOD(getCoordinateFromView:(nonnull NSNumber*)viewRef atPoint:(NSAr
60
60
  NSNumber* a = [atPoint objectAtIndex:0];
61
61
  NSNumber* b = [atPoint objectAtIndex:1];
62
62
 
63
- [view getCoordinateFromViewWithAtPoint:CGPointMake(a.floatValue, b.floatValue) resolver:resolve rejecter:reject];
63
+ [view getCoordinateFromViewWithAtPoint:CGPointMake(a.doubleValue, b.doubleValue) resolver:resolve rejecter:reject];
64
64
  } reject:reject methodName:@"getCoordinateFromView"];
65
65
  }
66
66
 
@@ -79,7 +79,7 @@ public class RNMBXModelLayer: RNMBXVectorLayer {
79
79
  styler.modelLayer(
80
80
  layer: &styleLayer,
81
81
  reactStyle: reactStyle,
82
- oldReactStyle: oldReatStyle,
82
+ oldReactStyle: oldReactStyle,
83
83
  applyUpdater: { (updater) in logged("RNMBXModelLayer.updateLayer") {
84
84
  try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
85
85
  }},
@@ -23,6 +23,7 @@ class RNMBXModule : NSObject {
23
23
  @objc
24
24
  func constantsToExport() -> [AnyHashable: Any]! {
25
25
  return [
26
+ // Deprecated: means v10 or later, always true. Will be removed in next major version.
26
27
  "MapboxV10":true,
27
28
  "StyleURL":
28
29
  [
@@ -10,6 +10,8 @@ final class WeakRef<T: AnyObject> {
10
10
  }
11
11
  @objc
12
12
  public class RNMBXPointAnnotation : RNMBXInteractiveElement {
13
+ weak var manager: RNMBXPointAnnotationManager? = nil
14
+
13
15
  static let key = "RNMBXPointAnnotation"
14
16
  static var gid = 0;
15
17
 
@@ -31,7 +33,25 @@ public class RNMBXPointAnnotation : RNMBXInteractiveElement {
31
33
  @objc public var onDrag: RCTBubblingEventBlock? = nil
32
34
  @objc public var onDragEnd: RCTBubblingEventBlock? = nil
33
35
  @objc public var onSelected: RCTBubblingEventBlock? = nil
34
-
36
+
37
+ private var selected: Bool? = nil {
38
+ didSet {
39
+ update { annotation in
40
+ if let selected = selected {
41
+ annotation.isSelected = selected
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ @objc public func setReactSelected(_ _selected: Bool) {
48
+ if (_selected == true && self.selected != true) {
49
+ manager?.selected(pointAnnotation: self)
50
+ } else if (_selected == false && self.selected == true) {
51
+ manager?.unselected(pointAnnotation: self)
52
+ }
53
+ }
54
+
35
55
  @objc public var coordinate : String? {
36
56
  didSet {
37
57
  _updateCoordinate()
@@ -173,14 +193,16 @@ public class RNMBXPointAnnotation : RNMBXInteractiveElement {
173
193
  }
174
194
 
175
195
  func doSelect() {
196
+ self.selected = true
176
197
  let event = makeEvent(isSelect: true)
177
198
  if let onSelected = onSelected {
178
199
  onSelected(event.toJSON())
179
200
  }
180
201
  onSelect()
181
202
  }
182
-
203
+
183
204
  func doDeselect(deselectAnnotationOnMapTap: Bool = false) {
205
+ self.selected = false
184
206
  let event = makeEvent(isSelect: false, deselectAnnotationOnMapTap: deselectAnnotationOnMapTap)
185
207
  if let onDeselected = onDeselected {
186
208
  onDeselected(event.toJSON())
@@ -192,7 +214,7 @@ public class RNMBXPointAnnotation : RNMBXInteractiveElement {
192
214
  if let callout = callout,
193
215
  let calloutImage = _createViewSnapshot(view: callout),
194
216
  let point = point() {
195
-
217
+
196
218
  var calloutPtAnnotation = PointAnnotation(point: point)
197
219
  calloutId = calloutPtAnnotation.id
198
220
  let name = "rnviewcallout-\(gid())-\(calloutPtAnnotation.id)"
@@ -130,6 +130,7 @@ using namespace facebook::react;
130
130
  RNMBX_OPTIONAL_PROP_BOOL(draggable)
131
131
  RNMBX_OPTIONAL_PROP_NSString(id)
132
132
  RNMBX_OPTIONAL_PROP_NSDictionary(anchor)
133
+ RNMBX_REMAP_OPTIONAL_PROP_BOOL(selected, reactSelected)
133
134
 
134
135
  [super updateProps:props oldProps:oldProps];
135
136
  }
@@ -74,7 +74,7 @@ public class RNMBXRasterLayer: RNMBXLayer {
74
74
  styler.rasterLayer(
75
75
  layer: &styleLayer,
76
76
  reactStyle: reactStyle,
77
- oldReactStyle: oldReatStyle,
77
+ oldReactStyle: oldReactStyle,
78
78
  applyUpdater:{ (updater) in logged("RNMBXRasterLayer.updateLayer") {
79
79
  try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
80
80
  }},
@@ -73,7 +73,7 @@ public class RNMBXRasterParticleLayer: RNMBXLayer {
73
73
  styler.rasterParticleLayer(
74
74
  layer: &styleLayer,
75
75
  reactStyle: reactStyle,
76
- oldReactStyle: oldReatStyle,
76
+ oldReactStyle: oldReactStyle,
77
77
  applyUpdater:{ (updater) in logged("RNMBXRasterParticleLayer.updateLayer") {
78
78
  try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
79
79
  }},
@@ -54,7 +54,7 @@ public class RNMBXSkyLayer: RNMBXLayer {
54
54
  styler.skyLayer(
55
55
  layer: &styleLayer,
56
56
  reactStyle: reactStyle,
57
- oldReactStyle: oldReatStyle,
57
+ oldReactStyle: oldReactStyle,
58
58
  applyUpdater: { (updater) in logged("RNMBXSkyLayer.addStyles") {
59
59
  try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
60
60
  }},
@@ -93,10 +93,12 @@ class RNMBXSnapshotModule : NSObject {
93
93
  let height = jsOptions["height"] as? NSNumber else {
94
94
  throw RNMBXError.paramError("width, height: is not a number")
95
95
  }
96
- let mapSnapshotOptions = MapSnapshotOptions(
96
+ let showsLogo = jsOptions["withLogo"] as? Bool ?? true
97
+ var mapSnapshotOptions = MapSnapshotOptions(
97
98
  size: CGSize(width: width.doubleValue, height: height.doubleValue),
98
99
  pixelRatio: 1.0
99
100
  )
101
+ mapSnapshotOptions.showsLogo = showsLogo
100
102
 
101
103
  return mapSnapshotOptions
102
104
  }