@rnmapbox/maps 10.1.4 → 10.1.6

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 (46) hide show
  1. package/README.md +1 -1
  2. package/android/build.gradle +16 -1
  3. package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotation.kt +30 -28
  4. package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotationCoordinator.kt +168 -0
  5. package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCamera.kt +5 -3
  6. package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCameraManager.kt +2 -2
  7. package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt +17 -175
  8. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/RNMBXStyleValue.kt +1 -1
  9. package/android/src/main/java/com/rnmapbox/rnmbx/utils/extensions/Dynamic.kt +8 -0
  10. package/android/src/main/java/com/rnmapbox/rnmbx/utils/extensions/ReadableMap.kt +14 -0
  11. package/android/src/test/kotlin/com/rnmapbox/rnmbx/components/styles/RNMBXStyleValueTest.kt +47 -0
  12. package/ios/RNMBX/RNMBXAtmosphere.swift +4 -4
  13. package/ios/RNMBX/RNMBXCamera.swift +7 -7
  14. package/ios/RNMBX/RNMBXCustomLocationProvider.swift +3 -3
  15. package/ios/RNMBX/RNMBXImages.swift +3 -3
  16. package/ios/RNMBX/RNMBXInteractiveElement.swift +3 -3
  17. package/ios/RNMBX/RNMBXLayer.swift +3 -3
  18. package/ios/RNMBX/RNMBXLight.swift +3 -3
  19. package/ios/RNMBX/RNMBXLogging.swift +6 -6
  20. package/ios/RNMBX/RNMBXMapView.swift +7 -2
  21. package/ios/RNMBX/RNMBXMapViewManager.m +2 -0
  22. package/ios/RNMBX/RNMBXMapViewManager.swift +2 -2
  23. package/ios/RNMBX/RNMBXMarkerView.swift +4 -6
  24. package/ios/RNMBX/RNMBXModels.swift +3 -3
  25. package/ios/RNMBX/RNMBXModule.swift +10 -5
  26. package/ios/RNMBX/RNMBXNativeUserLocation.swift +3 -3
  27. package/ios/RNMBX/RNMBXPointAnnotation.swift +2 -2
  28. package/ios/RNMBX/RNMBXSource.swift +2 -2
  29. package/ios/RNMBX/RNMBXStyleImport.swift +3 -3
  30. package/ios/RNMBX/RNMBXTerrain.swift +3 -3
  31. package/ios/RNMBX/RNMBXViewport.swift +3 -3
  32. package/lib/commonjs/RNMBXModule.js +8 -0
  33. package/lib/commonjs/RNMBXModule.js.map +1 -1
  34. package/lib/commonjs/components/MapView.js +5 -1
  35. package/lib/commonjs/components/MapView.js.map +1 -1
  36. package/lib/module/RNMBXModule.js +8 -0
  37. package/lib/module/RNMBXModule.js.map +1 -1
  38. package/lib/module/components/MapView.js +5 -1
  39. package/lib/module/components/MapView.js.map +1 -1
  40. package/lib/typescript/src/RNMBXModule.d.ts.map +1 -1
  41. package/lib/typescript/src/components/MapView.d.ts +5 -0
  42. package/lib/typescript/src/components/MapView.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/rnmapbox-maps.podspec +13 -7
  45. package/src/RNMBXModule.ts +12 -0
  46. package/src/components/MapView.tsx +14 -5
package/README.md CHANGED
@@ -74,7 +74,7 @@ _See [iOS](ios/install.md) & [Android](android/install.md) setup guide for using
74
74
 
75
75
  - [node](https://nodejs.org)
76
76
  - [npm](https://www.npmjs.com/)
77
- - [React Native](https://facebook.github.io/react-native/) (0.64+)
77
+ - [React Native](https://facebook.github.io/react-native/) (0.70+, older versions from 0.64+ might or might not work)
78
78
 
79
79
 
80
80
  ## Installation
@@ -43,7 +43,11 @@ if (safeExtGet("RNMapboxMapsImpl", defaultMapboxMapsImpl) == "mapbox") {
43
43
  }
44
44
 
45
45
  android {
46
- namespace = "com.rnmapbox.rnmbx"
46
+ def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
47
+ // Check AGP version for backward compatibility reasons
48
+ if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
49
+ namespace = "com.rnmapbox.rnmbx"
50
+ }
47
51
  if (safeExtGet("RNMapboxMapsImpl", defaultMapboxMapsImpl) == "maplibre") {
48
52
  msg = '@rnmapbox/maps: Maplibre implementation has been removed, set RNMapboxMapsImpl to mapbox- see https://github.com/rnmapbox/maps/wiki/Deprecated-RNMapboxImpl-Maplibre#android'
49
53
  logger.error(msg)
@@ -161,4 +165,15 @@ dependencies {
161
165
  implementation "com.squareup.okhttp3:okhttp:4.9.0"
162
166
  implementation "com.squareup.okhttp3:okhttp-urlconnection:4.9.0"
163
167
  }
168
+
169
+ testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
170
+ testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
171
+ testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
172
+ testImplementation 'org.jetbrains.kotlin:kotlin-test'
173
+ testImplementation "org.mockito.kotlin:mockito-kotlin:5.2.1"
164
174
  }
175
+
176
+
177
+ tasks.withType(Test).configureEach {
178
+ useJUnitPlatform()
179
+ }
@@ -25,6 +25,8 @@ import java.util.*
25
25
  import com.rnmapbox.rnmbx.v11compat.annotation.*;
26
26
 
27
27
  class RNMBXPointAnnotation(private val mContext: Context, private val mManager: RNMBXPointAnnotationManager) : AbstractMapFeature(mContext), View.OnLayoutChangeListener {
28
+
29
+ var pointAnnotations: RNMBXPointAnnotationCoordinator? = null
28
30
  var annotation: PointAnnotation? = null
29
31
  private set
30
32
  private var mMap: MapboxMap? = null
@@ -79,6 +81,7 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
79
81
  override fun addToMap(mapView: RNMBXMapView) {
80
82
  super.addToMap(mapView)
81
83
  mMap = mapView.getMapboxMap()
84
+ pointAnnotations = mapView.pointAnnotations
82
85
  makeMarker()
83
86
  if (mChildView != null) {
84
87
  if (!mChildView!!.isAttachedToWindow) {
@@ -96,16 +99,13 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
96
99
  }
97
100
 
98
101
  override fun removeFromMap(mapView: RNMBXMapView, reason: RemovalReason): Boolean {
99
- val map = (if (mMapView != null) mMapView else mapView) ?: return true
100
- if (annotation != null) {
101
- map.pointAnnotationManager?.delete(annotation!!)
102
- }
103
- if (mChildView != null) {
104
- map.offscreenAnnotationViewContainer?.removeView(mChildView)
105
- }
106
- if (calloutView != null) {
107
- map.offscreenAnnotationViewContainer?.removeView(calloutView)
108
- }
102
+ val map = mMapView ?: mapView
103
+
104
+ annotation?.let { map.pointAnnotations?.delete(it) }
105
+
106
+ mChildView?.let { map.offscreenAnnotationViewContainer?.removeView(it) }
107
+ calloutView?.let { map.offscreenAnnotationViewContainer?.removeView(it)}
108
+
109
109
  return super.removeFromMap(mapView, reason)
110
110
  }
111
111
 
@@ -138,33 +138,36 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
138
138
  val latLng: LatLng?
139
139
  get() = mCoordinate?.let { GeoJSONUtils.toLatLng(it) }
140
140
  val mapboxID: AnnotationID
141
- get() = if (annotation == null) INVALID_ANNOTATION_ID else annotation!!.id
141
+ get() = annotation?.id ?: INVALID_ANNOTATION_ID
142
+
143
+ val calloutMapboxID: AnnotationID
144
+ get() = mCalloutSymbol?.id ?: INVALID_ANNOTATION_ID
142
145
 
143
146
  fun setCoordinate(point: Point) {
144
147
  mCoordinate = point
145
148
  annotation?.let {
146
149
  it.point = point
147
- mMapView?.pointAnnotationManager?.update(it)
150
+ pointAnnotations?.update(it)
148
151
  }
149
152
  mCalloutSymbol?.let {
150
153
  it.point = point
151
- mMapView?.pointAnnotationManager?.update(it)
154
+ pointAnnotations?.update(it)
152
155
  }
153
156
  }
154
157
 
155
158
  fun setAnchor(x: Float, y: Float) {
156
159
  mAnchor = arrayOf(x, y)
157
- if (annotation != null) {
160
+ annotation?.let { annotation ->
158
161
  updateAnchor()
159
- mMapView?.pointAnnotationManager?.update(annotation!!)
162
+ pointAnnotations?.update(annotation)
160
163
  }
161
164
  }
162
165
 
163
166
  fun setDraggable(draggable: Boolean) {
164
167
  mDraggable = draggable
165
- annotation?.let {
166
- it.isDraggable = draggable
167
- mMapView?.pointAnnotationManager?.update(it)
168
+ annotation?.let { annotation ->
169
+ annotation.isDraggable = draggable
170
+ pointAnnotations?.update(annotation)
168
171
  }
169
172
  }
170
173
 
@@ -179,8 +182,8 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
179
182
 
180
183
  fun doDeselect() {
181
184
  mManager.handleEvent(makeEvent(false))
182
- if (mCalloutSymbol != null) {
183
- mMapView?.pointAnnotationManager?.delete(mCalloutSymbol!!)
185
+ mCalloutSymbol?.let { mCalloutSymbol ->
186
+ pointAnnotations?.delete(mCalloutSymbol)
184
187
  }
185
188
  }
186
189
 
@@ -207,19 +210,18 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
207
210
  .withIconSize(1.0)
208
211
  .withSymbolSortKey(10.0)
209
212
  }
210
- mMapView?.pointAnnotationManager?.let { annotationManager ->
211
- options?.let {
212
- annotation = annotationManager.create(options)
213
- updateOptions()
214
- }
213
+ annotation = null
214
+ options?.let {
215
+ annotation = pointAnnotations?.create(it)
216
+ updateOptions()
215
217
  }
216
218
  }
217
219
 
218
220
  private fun updateOptions() {
219
- if (annotation != null) {
221
+ annotation?.let {
220
222
  updateIconImage()
221
223
  updateAnchor()
222
- mMapView?.pointAnnotationManager?.update(annotation!!)
224
+ pointAnnotations?.update(it)
223
225
  }
224
226
  }
225
227
 
@@ -268,7 +270,7 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
268
270
  .withDraggable(false)
269
271
  }
270
272
  }
271
- val symbolManager = mMapView?.pointAnnotationManager
273
+ val symbolManager = pointAnnotations
272
274
  if (symbolManager != null && options != null) {
273
275
  mCalloutSymbol = symbolManager.create(options)
274
276
  }
@@ -0,0 +1,168 @@
1
+ package com.rnmapbox.rnmbx.components.annotation
2
+
3
+ import com.mapbox.maps.MapView
4
+ import com.mapbox.maps.plugin.annotation.Annotation
5
+ import com.mapbox.maps.plugin.annotation.AnnotationConfig
6
+ import com.mapbox.maps.plugin.annotation.annotations
7
+ import com.mapbox.maps.plugin.annotation.generated.OnPointAnnotationClickListener
8
+ import com.mapbox.maps.plugin.annotation.generated.OnPointAnnotationDragListener
9
+ import com.mapbox.maps.plugin.annotation.generated.PointAnnotation
10
+ import com.mapbox.maps.plugin.annotation.generated.PointAnnotationManager
11
+ import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
12
+ import com.mapbox.maps.plugin.annotation.generated.createPointAnnotationManager
13
+ import com.rnmapbox.rnmbx.components.annotation.RNMBXPointAnnotation
14
+ import com.rnmapbox.rnmbx.utils.Logger
15
+
16
+ class RNMBXPointAnnotationCoordinator(val mapView: MapView) {
17
+ val manager: PointAnnotationManager;
18
+ var annotationClicked = false
19
+ var annotationDragged = false
20
+
21
+ var selected: RNMBXPointAnnotation? = null
22
+
23
+ val annotations: MutableMap<String, RNMBXPointAnnotation> = hashMapOf()
24
+ val callouts: MutableMap<String, RNMBXPointAnnotation> = hashMapOf()
25
+
26
+ init {
27
+ manager = mapView.annotations.createPointAnnotationManager(AnnotationConfig(layerId = "RNMBX-mapview-annotations"))
28
+ manager.addClickListener(OnPointAnnotationClickListener { pointAnnotation ->
29
+ onAnnotationClick(pointAnnotation)
30
+ false
31
+ })
32
+ }
33
+
34
+ fun getAndClearAnnotationClicked(): Boolean {
35
+ if (annotationClicked) {
36
+ annotationClicked = false
37
+ return true
38
+ }
39
+ return false
40
+ }
41
+
42
+ fun getAndClearAnnotationDragged(): Boolean {
43
+ if (annotationDragged) {
44
+ annotationDragged = false
45
+ return true
46
+ }
47
+ return false
48
+ }
49
+
50
+ fun lookupForClick(point: PointAnnotation): RNMBXPointAnnotation? {
51
+ for (annotation in annotations.values) {
52
+ if (point.id == annotation.mapboxID) {
53
+ return annotation;
54
+ }
55
+ if (point.id == annotation.calloutMapboxID) {
56
+ return null;
57
+ }
58
+ }
59
+ Logger.e(LOG_TAG, "Failed to find RNMBXPointAnnotation for ${point.id}")
60
+ return null;
61
+ }
62
+
63
+ fun onAnnotationClick(pointAnnotation: RNMBXPointAnnotation) {
64
+ var oldSelected: RNMBXPointAnnotation? = selected
65
+ var newSelected: RNMBXPointAnnotation? = pointAnnotation
66
+
67
+ annotationClicked = true
68
+
69
+ if (newSelected == oldSelected) {
70
+ newSelected = null
71
+ }
72
+
73
+ manager.addDragListener(object : OnPointAnnotationDragListener {
74
+ override fun onAnnotationDragStarted(_annotation: Annotation<*>) {
75
+ annotationDragged = true;
76
+ var reactAnnotation: RNMBXPointAnnotation? = null
77
+ for (key in annotations.keys) {
78
+ val annotation = annotations[key]
79
+ val curMarkerID = annotation?.mapboxID
80
+ if (_annotation.id == curMarkerID) {
81
+ reactAnnotation = annotation
82
+ }
83
+ }
84
+ reactAnnotation?.let { it.onDragStart() }
85
+ }
86
+
87
+ override fun onAnnotationDrag(_annotation: Annotation<*>) {
88
+ var reactAnnotation: RNMBXPointAnnotation? = null
89
+ for (key in annotations.keys) {
90
+ val annotation = annotations[key]
91
+ val curMarkerID = annotation?.mapboxID
92
+ if (_annotation.id == curMarkerID) {
93
+ reactAnnotation = annotation
94
+ }
95
+ }
96
+ reactAnnotation?.let { it.onDrag() }
97
+ }
98
+
99
+ override fun onAnnotationDragFinished(_annotation: Annotation<*>) {
100
+ annotationDragged = false;
101
+ var reactAnnotation: RNMBXPointAnnotation? = null
102
+ for (key in annotations.keys) {
103
+ val annotation = annotations[key]
104
+ val curMarkerID = annotation?.mapboxID
105
+ if (_annotation.id == curMarkerID) {
106
+ reactAnnotation = annotation
107
+ }
108
+ }
109
+ reactAnnotation?.let { it.onDragEnd() }
110
+ }
111
+ })
112
+
113
+ oldSelected?.let { deselectAnnotation(it) }
114
+ newSelected?.let { selectAnnotation(it) }
115
+
116
+ }
117
+
118
+ fun onAnnotationClick(point: PointAnnotation) {
119
+ lookupForClick(point)?.let {
120
+ onAnnotationClick(it)
121
+ }
122
+ }
123
+
124
+ fun deselectSelectedAnnotation(): Boolean {
125
+ selected?.let {
126
+ deselectAnnotation(it)
127
+ return true
128
+ }
129
+ return false
130
+ }
131
+
132
+ fun selectAnnotation(annotation: RNMBXPointAnnotation) {
133
+ selected = annotation
134
+ annotation.doSelect(true)
135
+ }
136
+
137
+ fun deselectAnnotation(annotation: RNMBXPointAnnotation) {
138
+ selected = null
139
+ annotation.doDeselect()
140
+ }
141
+
142
+ fun remove(annotation: RNMBXPointAnnotation) {
143
+ if (annotation == selected) {
144
+ selected = null
145
+ }
146
+ annotations.remove(annotation.iD)
147
+ }
148
+
149
+ fun delete(annotation: PointAnnotation) {
150
+ manager.delete(annotation)
151
+ }
152
+
153
+ fun update(annotation: PointAnnotation) {
154
+ manager.update(annotation)
155
+ }
156
+
157
+ fun create(options: PointAnnotationOptions): PointAnnotation {
158
+ return manager.create(options)
159
+ }
160
+
161
+ fun add(annotation: RNMBXPointAnnotation) {
162
+ annotations[annotation.iD!!] = annotation
163
+ }
164
+
165
+ companion object {
166
+ const val LOG_TAG = "RNMBXPointAnnotationCoordinator";
167
+ }
168
+ }
@@ -59,7 +59,7 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
59
59
  private val mAnimated = false
60
60
  private val mHeading = 0.0
61
61
 
62
- private var mFollowUserLocation = false
62
+ private var mFollowUserLocation = defaultFollowUserLocation
63
63
  private var mFollowUserMode: String? = null
64
64
  private var mFollowZoomLevel : Double? = null
65
65
  private var mFollowPitch : Double? = null
@@ -126,8 +126,8 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
126
126
  _updateViewportState()
127
127
  }
128
128
 
129
- fun setFollowUserLocation(value: Boolean) {
130
- mFollowUserLocation = value
129
+ fun setFollowUserLocation(value: Boolean?) {
130
+ mFollowUserLocation = value ?: defaultFollowUserLocation
131
131
  _updateViewportState()
132
132
  }
133
133
 
@@ -559,5 +559,7 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
559
559
  const val minimumZoomLevelForUserTracking = 10.5
560
560
  const val defaultZoomLevelForUserTracking = 14.0
561
561
  const val LOG_TAG = "RNMBXCamera"
562
+
563
+ const val defaultFollowUserLocation = false
562
564
  }
563
565
  }
@@ -9,7 +9,7 @@ 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
-
12
+ import com.rnmapbox.rnmbx.utils.extensions.asBooleanOrNull
13
13
 
14
14
  class RNMBXCameraManager(private val mContext: ReactApplicationContext) :
15
15
  AbstractEventEmitter<RNMBXCamera?>(
@@ -66,7 +66,7 @@ class RNMBXCameraManager(private val mContext: ReactApplicationContext) :
66
66
 
67
67
  @ReactProp(name = "followUserLocation")
68
68
  override fun setFollowUserLocation(camera: RNMBXCamera, value: Dynamic) {
69
- camera.setFollowUserLocation(value.asBoolean())
69
+ camera.setFollowUserLocation(value.asBooleanOrNull())
70
70
  }
71
71
 
72
72
  @ReactProp(name = "followUserMode")
@@ -34,18 +34,10 @@ import com.mapbox.maps.extension.style.layers.properties.generated.ProjectionNam
34
34
  import com.mapbox.maps.extension.style.layers.properties.generated.Visibility
35
35
  import com.mapbox.maps.extension.style.projection.generated.Projection
36
36
  import com.mapbox.maps.extension.style.projection.generated.setProjection
37
- import com.mapbox.maps.plugin.annotation.Annotation
38
- import com.mapbox.maps.plugin.annotation.AnnotationConfig
39
- import com.mapbox.maps.plugin.annotation.annotations
40
- import com.mapbox.maps.plugin.annotation.generated.*
41
37
  import com.mapbox.maps.plugin.attribution.attribution
42
38
  import com.mapbox.maps.plugin.compass.compass
43
39
  import com.mapbox.maps.plugin.delegates.listeners.*
44
40
  import com.mapbox.maps.plugin.gestures.*
45
- import com.mapbox.maps.plugin.locationcomponent.DefaultLocationProvider
46
- import com.mapbox.maps.plugin.locationcomponent.LocationConsumer
47
- import com.mapbox.maps.plugin.locationcomponent.LocationProvider
48
- import com.mapbox.maps.plugin.locationcomponent.location
49
41
  import com.mapbox.maps.plugin.logo.logo
50
42
  import com.mapbox.maps.plugin.scalebar.scalebar
51
43
  import com.mapbox.maps.viewannotation.ViewAnnotationManager
@@ -72,11 +64,9 @@ import com.rnmapbox.rnmbx.events.MapClickEvent
72
64
  import com.rnmapbox.rnmbx.events.constants.EventTypes
73
65
  import com.rnmapbox.rnmbx.utils.*
74
66
  import com.rnmapbox.rnmbx.utils.extensions.toReadableArray
75
- import com.rnmapbox.rnmbx.v11compat.annotation.AnnotationID
76
- import com.rnmapbox.rnmbx.v11compat.annotation.INVALID_ANNOTATION_ID
77
67
  import java.util.*
78
68
 
79
- import com.mapbox.maps.MapboxMap.*;
69
+ import com.rnmapbox.rnmbx.components.annotation.RNMBXPointAnnotationCoordinator
80
70
  import com.rnmapbox.rnmbx.components.images.ImageManager
81
71
 
82
72
  import com.rnmapbox.rnmbx.v11compat.event.*
@@ -85,7 +75,6 @@ import com.rnmapbox.rnmbx.v11compat.mapboxmap.*
85
75
  import com.rnmapbox.rnmbx.v11compat.ornamentsettings.*
86
76
  import org.json.JSONException
87
77
  import org.json.JSONObject
88
- import java.util.*
89
78
 
90
79
  fun <T> MutableList<T>.removeIf21(predicate: (T) -> Boolean): Boolean {
91
80
  var removed = false
@@ -205,7 +194,7 @@ public class RNMBXMapViewFactory {
205
194
  }
206
195
 
207
196
  fun get(impl: String): Factory? {
208
- val (impl, options) = impl.split(":",limit=2);
197
+ val (impl, options) = impl.split(":",limit=2) + null;
209
198
  return factories.get(impl);
210
199
  }
211
200
  }
@@ -225,12 +214,12 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
225
214
 
226
215
  private val mSources: MutableMap<String, RNMBXSource<*>>
227
216
  private val mImages: MutableList<RNMBXImages>
228
- public val pointAnnotationManager: RNMBXPointAnnotationManager by lazy {
217
+ public val pointAnnotations: RNMBXPointAnnotationCoordinator by lazy {
229
218
  val gesturesPlugin: GesturesPlugin = mapView.gestures
230
219
  gesturesPlugin.removeOnMapClickListener(this)
231
220
  gesturesPlugin.removeOnMapLongClickListener(this)
232
221
 
233
- val result = RNMBXPointAnnotationManager(mapView)
222
+ val result = RNMBXPointAnnotationCoordinator(mapView)
234
223
 
235
224
  gesturesPlugin.addOnMapClickListener(this)
236
225
  gesturesPlugin.addOnMapLongClickListener(this)
@@ -445,7 +434,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
445
434
  feature = childView
446
435
  } else if (childView is RNMBXPointAnnotation) {
447
436
  val annotation = childView
448
- pointAnnotationManager.add(annotation)
437
+ pointAnnotations.add(annotation)
449
438
  feature = childView
450
439
  } else if (childView is RNMBXMarkerView) {
451
440
  feature = childView
@@ -481,7 +470,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
481
470
  mSources.remove(feature.iD)
482
471
  } else if (feature is RNMBXPointAnnotation) {
483
472
  val annotation = feature
484
- pointAnnotationManager.remove(annotation)
473
+ pointAnnotations.remove(annotation)
485
474
  } else if (feature is RNMBXImages) {
486
475
  mImages.remove(feature)
487
476
  }
@@ -729,13 +718,15 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
729
718
  )
730
719
  ) { features ->
731
720
  if (features.isValue) {
732
- if (features.value!!.size > 0) {
733
- val featuresList = ArrayList<Feature?>()
734
- for (i in features.value!!) {
735
- featuresList.add(i.feature)
721
+ features.value?.let { features ->
722
+ if (features.size > 0) {
723
+ val featuresList = ArrayList<Feature?>()
724
+ for (i in features) {
725
+ featuresList.add(i.feature)
726
+ }
727
+ hits[source.iD] = featuresList
728
+ hitTouchableSources.add(source)
736
729
  }
737
- hits[source.iD] = featuresList
738
- hitTouchableSources.add(source)
739
730
  }
740
731
  } else {
741
732
  Logger.e("handleTapInSources", features.error ?: "n/a")
@@ -747,11 +738,11 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
747
738
 
748
739
  override fun onMapClick(point: Point): Boolean {
749
740
  val _this = this
750
- if (pointAnnotationManager.getAndClearAnnotationClicked()) {
741
+ if (pointAnnotations.getAndClearAnnotationClicked()) {
751
742
  return true
752
743
  }
753
744
  if (deselectAnnotationOnTap) {
754
- if (pointAnnotationManager.deselectSelectedAnnotation()) {
745
+ if (pointAnnotations.deselectSelectedAnnotation()) {
755
746
  return true
756
747
  }
757
748
  }
@@ -783,7 +774,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
783
774
 
784
775
  override fun onMapLongClick(point: Point): Boolean {
785
776
  val _this = this
786
- if (pointAnnotationManager.getAndClearAnnotationDragged()) {
777
+ if (pointAnnotations.getAndClearAnnotationDragged()) {
787
778
  return true
788
779
  }
789
780
  val screenPoint = mMap?.pixelForCoordinate(point)
@@ -1565,154 +1556,5 @@ fun OrnamentSettings.setPosAndMargins(posAndMargins: ReadableMap?) {
1565
1556
  this.margins = margins
1566
1557
  }
1567
1558
 
1568
- class RNMBXPointAnnotationManager(val mapView: MapView) {
1569
- val manager: PointAnnotationManager;
1570
- var annotationClicked = false
1571
- var annotationDragged = false
1572
-
1573
- var selected: RNMBXPointAnnotation? = null
1574
-
1575
- val annotations: MutableMap<String, RNMBXPointAnnotation> = hashMapOf()
1576
-
1577
- init {
1578
- manager = mapView.annotations.createPointAnnotationManager(AnnotationConfig(layerId = "RNMBX-mapview-annotations"))
1579
- manager.addClickListener(OnPointAnnotationClickListener { pointAnnotation ->
1580
- onAnnotationClick(pointAnnotation)
1581
- false
1582
- })
1583
- }
1584
-
1585
- fun getAndClearAnnotationClicked(): Boolean {
1586
- if (annotationClicked) {
1587
- annotationClicked = false
1588
- return true
1589
- }
1590
- return false
1591
- }
1592
-
1593
- fun getAndClearAnnotationDragged(): Boolean {
1594
- if (annotationDragged) {
1595
- annotationDragged = false
1596
- return true
1597
- }
1598
- return false
1599
- }
1600
-
1601
- fun lookup(point: PointAnnotation): RNMBXPointAnnotation? {
1602
- for (annotation in annotations.values) {
1603
- if (point.id == annotation.mapboxID) {
1604
- return annotation;
1605
- }
1606
- }
1607
- Logger.e(LOG_TAG, "Failed to find RNMBXPointAnntoation for ${point.id}")
1608
- return null;
1609
- }
1610
-
1611
- fun onAnnotationClick(pointAnnotation: RNMBXPointAnnotation) {
1612
- var oldSelected: RNMBXPointAnnotation? = selected
1613
- var newSelected: RNMBXPointAnnotation? = pointAnnotation
1614
-
1615
- annotationClicked = true
1616
-
1617
- if (newSelected == oldSelected) {
1618
- newSelected = null
1619
- }
1620
-
1621
- manager.addDragListener(object : OnPointAnnotationDragListener {
1622
- override fun onAnnotationDragStarted(_annotation: Annotation<*>) {
1623
- annotationDragged = true;
1624
- var reactAnnotation: RNMBXPointAnnotation? = null
1625
- for (key in annotations.keys) {
1626
- val annotation = annotations[key]
1627
- val curMarkerID = annotation?.mapboxID
1628
- if (_annotation.id == curMarkerID) {
1629
- reactAnnotation = annotation
1630
- }
1631
- }
1632
- reactAnnotation?.let { it.onDragStart() }
1633
- }
1634
-
1635
- override fun onAnnotationDrag(_annotation: Annotation<*>) {
1636
- var reactAnnotation: RNMBXPointAnnotation? = null
1637
- for (key in annotations.keys) {
1638
- val annotation = annotations[key]
1639
- val curMarkerID = annotation?.mapboxID
1640
- if (_annotation.id == curMarkerID) {
1641
- reactAnnotation = annotation
1642
- }
1643
- }
1644
- reactAnnotation?.let { it.onDrag() }
1645
- }
1646
-
1647
- override fun onAnnotationDragFinished(_annotation: Annotation<*>) {
1648
- annotationDragged = false;
1649
- var reactAnnotation: RNMBXPointAnnotation? = null
1650
- for (key in annotations.keys) {
1651
- val annotation = annotations[key]
1652
- val curMarkerID = annotation?.mapboxID
1653
- if (_annotation.id == curMarkerID) {
1654
- reactAnnotation = annotation
1655
- }
1656
- }
1657
- reactAnnotation?.let { it.onDragEnd() }
1658
- }
1659
- })
1660
-
1661
- oldSelected?.let { deselectAnnotation(it) }
1662
- newSelected?.let { selectAnnotation(it) }
1663
-
1664
- }
1665
-
1666
- fun onAnnotationClick(point: PointAnnotation) {
1667
- lookup(point)?.let {
1668
- onAnnotationClick(it)
1669
- }
1670
- }
1671
-
1672
- fun deselectSelectedAnnotation(): Boolean {
1673
- selected?.let {
1674
- deselectAnnotation(it)
1675
- return true
1676
- }
1677
- return false
1678
- }
1679
-
1680
- fun selectAnnotation(annotation: RNMBXPointAnnotation) {
1681
- selected = annotation
1682
- annotation.doSelect(true)
1683
- }
1684
-
1685
- fun deselectAnnotation(annotation: RNMBXPointAnnotation) {
1686
- selected = null
1687
- annotation.doDeselect()
1688
- }
1689
-
1690
- fun remove(annotation: RNMBXPointAnnotation) {
1691
- if (annotation == selected) {
1692
- selected = null
1693
- }
1694
- annotations.remove(annotation.iD)
1695
- }
1696
-
1697
- fun delete(annotation: PointAnnotation) {
1698
- manager.delete(annotation)
1699
- }
1700
-
1701
- fun update(annotation: PointAnnotation) {
1702
- manager.update(annotation)
1703
- }
1704
-
1705
- fun create(options: PointAnnotationOptions): PointAnnotation {
1706
- return manager.create(options)
1707
- }
1708
-
1709
- fun add(annotation: RNMBXPointAnnotation) {
1710
- annotations[annotation.iD!!] = annotation
1711
- }
1712
-
1713
- companion object {
1714
- const val LOG_TAG = "RNMBXPointAnnotationManager";
1715
- }
1716
- }
1717
1559
 
1718
1560
 
@@ -40,7 +40,7 @@ class RNMBXStyleValue(config: ReadableMap) {
40
40
  }
41
41
 
42
42
  fun getEnumName(): String {
43
- return mPayload!!.getString("value")!!.toUpperCase().replace("-", "_")
43
+ return mPayload!!.getString("value")!!.uppercase().replace("-", "_")
44
44
  }
45
45
 
46
46
  fun getDouble(key: String?): Double {
@@ -54,4 +54,12 @@ fun Dynamic.toValue(): Value {
54
54
  ReadableType.Array -> asArray().toValue()
55
55
  ReadableType.Map -> asMap().toValue()
56
56
  }
57
+ }
58
+
59
+ fun Dynamic.asBooleanOrNull(): Boolean? {
60
+ return if (isNull) {
61
+ null
62
+ } else {
63
+ asBoolean()
64
+ }
57
65
  }