@rnmapbox/maps 10.1.11 → 10.1.12

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.
@@ -113,7 +113,7 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
113
113
  }
114
114
  }
115
115
  fun setStop(stop: CameraStop) {
116
- if (stop.ts != mCameraStop?.ts) {
116
+ if ((stop.ts != mCameraStop?.ts) || (mCameraStop == null)) {
117
117
  mCameraStop = stop
118
118
  stop.setCallback(mCameraCallback)
119
119
  if (mMapView != null) {
@@ -136,17 +136,17 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
136
136
  _updateViewportState()
137
137
  }
138
138
 
139
- fun setFollowZoomLevel(zoomLevel: Double) {
139
+ fun setFollowZoomLevel(zoomLevel: Double?) {
140
140
  mFollowZoomLevel = zoomLevel
141
141
  _updateViewportState();
142
142
  }
143
143
 
144
- fun setFollowPitch(pitch: Double) {
144
+ fun setFollowPitch(pitch: Double?) {
145
145
  mFollowPitch = pitch
146
146
  _updateViewportState();
147
147
  }
148
148
 
149
- fun setFollowHeading(heading: Double) {
149
+ fun setFollowHeading(heading: Double?) {
150
150
  mFollowHeading = heading
151
151
  _updateViewportState();
152
152
  }
@@ -10,6 +10,8 @@ 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
12
  import com.rnmapbox.rnmbx.utils.extensions.asBooleanOrNull
13
+ import com.rnmapbox.rnmbx.utils.extensions.asDoubleOrNull
14
+ import com.rnmapbox.rnmbx.utils.extensions.asStringOrNull
13
15
 
14
16
  class RNMBXCameraManager(private val mContext: ReactApplicationContext) :
15
17
  AbstractEventEmitter<RNMBXCamera?>(
@@ -71,22 +73,22 @@ class RNMBXCameraManager(private val mContext: ReactApplicationContext) :
71
73
 
72
74
  @ReactProp(name = "followUserMode")
73
75
  override fun setFollowUserMode(camera: RNMBXCamera, value: Dynamic) {
74
- camera.setFollowUserMode(value.asString())
76
+ camera.setFollowUserMode(value.asStringOrNull())
75
77
  }
76
78
 
77
79
  @ReactProp(name = "followZoomLevel")
78
80
  override fun setFollowZoomLevel(camera: RNMBXCamera, value: Dynamic) {
79
- camera.setFollowZoomLevel(value.asDouble())
81
+ camera.setFollowZoomLevel(value.asDoubleOrNull())
80
82
  }
81
83
 
82
84
  @ReactProp(name = "followPitch")
83
85
  override fun setFollowPitch(camera: RNMBXCamera, value: Dynamic) {
84
- camera.setFollowPitch(value.asDouble())
86
+ camera.setFollowPitch(value.asDoubleOrNull())
85
87
  }
86
88
 
87
89
  @ReactProp(name = "followHeading")
88
90
  override fun setFollowHeading(camera: RNMBXCamera, value: Dynamic) {
89
- camera.setFollowHeading(value.asDouble())
91
+ camera.setFollowHeading(value.asDoubleOrNull())
90
92
  }
91
93
 
92
94
  @ReactProp(name = "followPadding")
@@ -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
- if (name != null) {
102
- imageNames[image] = name
103
- } else {
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 (style.hasStyleImage(name)) {
264
- style.getStyleImage(name)?.let { image ->
265
- images[part] = image.toImageHolder()
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
- subscribe(imageManager, part, name)
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
- JsonArray array = ConvertUtils.toJsonArray(rawExpressions);
27
- String jsonString = new Gson().toJson(array);
28
- return Expression.fromRaw(jsonString);
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) {
@@ -91,7 +91,7 @@ object Logger {
91
91
  }
92
92
  }
93
93
 
94
- fun e(tag: String, msg: String, tr: Throwable) {
94
+ @JvmStatic fun e(tag: String, msg: String, tr: Throwable) {
95
95
  if (logLevel <= Log.ERROR) {
96
96
  logger.e(tag, msg, tr)
97
97
  }
@@ -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
  }
@@ -68,7 +68,7 @@ public class RNMBXNativeUserLocation: UIView, RNMBXMapComponent {
68
68
  case nil:
69
69
  _puckBearing = nil
70
70
  default:
71
- Logger.error("RNMBXNativeUserLocation puckBearing is uncrecognized: \(optional: value)")
71
+ Logger.error("RNMBXNativeUserLocation puckBearing is unrecognized: \(optional: value)")
72
72
  _puckBearing = nil
73
73
  }
74
74
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rnmapbox/maps",
3
3
  "description": "A Mapbox react native module for creating custom maps",
4
- "version": "10.1.11",
4
+ "version": "10.1.12",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },