@rnmapbox/maps 10.1.0-rc.4 → 10.1.0-rc.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 (24) hide show
  1. package/README.md +1 -30
  2. package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotation.kt +33 -35
  3. package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt +173 -106
  4. package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapViewManager.kt +7 -0
  5. package/android/src/main/java/com/rnmapbox/rnmbx/utils/GeoJSONUtils.kt +5 -0
  6. package/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerDelegate.java +3 -0
  7. package/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerInterface.java +1 -0
  8. package/ios/RNMBX/RNMBXEvent.swift +2 -0
  9. package/ios/RNMBX/RNMBXMapView.swift +107 -69
  10. package/ios/RNMBX/RNMBXMapViewComponentView.mm +26 -20
  11. package/ios/RNMBX/RNMBXMapViewManager.m +1 -0
  12. package/ios/RNMBX/RNMBXMarkerViewContentComponentView.mm +15 -1
  13. package/ios/RNMBX/RNMBXPointAnnotation.swift +34 -1
  14. package/lib/commonjs/components/MapView.js.map +1 -1
  15. package/lib/commonjs/specs/RNMBXMapViewNativeComponent.js.map +1 -1
  16. package/lib/module/components/MapView.js.map +1 -1
  17. package/lib/module/specs/RNMBXMapViewNativeComponent.js.map +1 -1
  18. package/lib/typescript/src/components/MapView.d.ts +5 -0
  19. package/lib/typescript/src/components/MapView.d.ts.map +1 -1
  20. package/lib/typescript/src/specs/RNMBXMapViewNativeComponent.d.ts +1 -0
  21. package/lib/typescript/src/specs/RNMBXMapViewNativeComponent.d.ts.map +1 -1
  22. package/package.json +1 -1
  23. package/src/components/MapView.tsx +6 -0
  24. package/src/specs/RNMBXMapViewNativeComponent.ts +2 -0
package/README.md CHANGED
@@ -79,36 +79,7 @@ _See [iOS](ios/install.md) & [Android](android/install.md) setup guide for using
79
79
 
80
80
  ## Installation
81
81
 
82
- ### Step 1 - Install Package:
83
-
84
- #### Using `yarn`
85
- Install the latest source from git:
86
- ```sh
87
- yarn add @rnmapbox/maps
88
- ```
89
-
90
- #### Using `npm`
91
- Install the latest source from git:
92
- ```sh
93
- npm install --save @rnmapbox/maps
94
- ```
95
-
96
- #### Installing other versions
97
-
98
- - `@rnmapbox/maps` installs the latest release from npm
99
- - to install current `main` from github replace `@rnmapbox/maps` with `rnmapbox/maps#main`. To install specific version use `@rnmapbox/maps@10.0.4`
100
-
101
-
102
- #### Using `expo`
103
- Please follow the [Expo Guide](/plugin/install.md).
104
-
105
- ### Step 2 - Installation Guides:
106
-
107
- - [Android](/android/install.md)
108
- - [iOS](/ios/install.md)
109
- - [Expo](/plugin/install.md)
110
- - [Example](/example)
111
-
82
+ Check our [Installation insructions](https://rnmapbox.github.io/docs/install)
112
83
 
113
84
  ### Getting Started
114
85
  For more information, check out our [Getting Started](/docs/GettingStarted.md) section
@@ -6,12 +6,9 @@ import com.rnmapbox.rnmbx.components.AbstractMapFeature
6
6
  import com.mapbox.maps.plugin.annotation.generated.PointAnnotation
7
7
  import com.mapbox.maps.MapboxMap
8
8
  import com.rnmapbox.rnmbx.components.mapview.RNMBXMapView
9
- import com.rnmapbox.rnmbx.components.annotation.RNMBXCallout
10
9
  import com.rnmapbox.rnmbx.utils.GeoJSONUtils
11
10
  import com.rnmapbox.rnmbx.events.constants.EventTypes
12
11
  import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
13
- import com.mapbox.maps.plugin.annotation.generated.PointAnnotationManager
14
- import com.rnmapbox.rnmbx.components.annotation.RNMBXPointAnnotation
15
12
  import com.mapbox.maps.extension.style.layers.properties.generated.IconAnchor
16
13
  import com.rnmapbox.rnmbx.events.PointAnnotationClickEvent
17
14
  import android.graphics.PointF
@@ -28,7 +25,7 @@ import java.util.*
28
25
  import com.rnmapbox.rnmbx.v11compat.annotation.*;
29
26
 
30
27
  class RNMBXPointAnnotation(private val mContext: Context, private val mManager: RNMBXPointAnnotationManager) : AbstractMapFeature(mContext), View.OnLayoutChangeListener {
31
- var marker: PointAnnotation? = null
28
+ var annotation: PointAnnotation? = null
32
29
  private set
33
30
  private var mMap: MapboxMap? = null
34
31
  private val mHasChildren = false
@@ -100,8 +97,8 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
100
97
 
101
98
  override fun removeFromMap(mapView: RNMBXMapView, reason: RemovalReason): Boolean {
102
99
  val map = (if (mMapView != null) mMapView else mapView) ?: return true
103
- if (marker != null) {
104
- map.pointAnnotationManager?.delete(marker!!)
100
+ if (annotation != null) {
101
+ map.pointAnnotationManager?.delete(annotation!!)
105
102
  }
106
103
  if (mChildView != null) {
107
104
  map.offscreenAnnotationViewContainer?.removeView(mChildView)
@@ -141,37 +138,37 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
141
138
  val latLng: LatLng?
142
139
  get() = mCoordinate?.let { GeoJSONUtils.toLatLng(it) }
143
140
  val mapboxID: AnnotationID
144
- get() = if (marker == null) INVALID_ANNOTATION_ID else marker!!.id
141
+ get() = if (annotation == null) INVALID_ANNOTATION_ID else annotation!!.id
145
142
 
146
143
  fun setCoordinate(point: Point) {
147
144
  mCoordinate = point
148
- if (marker != null) {
149
- marker!!.point = point
150
- mMapView?.pointAnnotationManager?.update(marker!!)
145
+ annotation?.let {
146
+ it.point = point
147
+ mMapView?.pointAnnotationManager?.update(it)
151
148
  }
152
- if (mCalloutSymbol != null) {
153
- mCalloutSymbol!!.point = point
154
- mMapView?.pointAnnotationManager?.update(mCalloutSymbol!!)
149
+ mCalloutSymbol?.let {
150
+ it.point = point
151
+ mMapView?.pointAnnotationManager?.update(it)
155
152
  }
156
153
  }
157
154
 
158
155
  fun setAnchor(x: Float, y: Float) {
159
156
  mAnchor = arrayOf(x, y)
160
- if (marker != null) {
157
+ if (annotation != null) {
161
158
  updateAnchor()
162
- mMapView?.pointAnnotationManager?.update(marker!!)
159
+ mMapView?.pointAnnotationManager?.update(annotation!!)
163
160
  }
164
161
  }
165
162
 
166
163
  fun setDraggable(draggable: Boolean) {
167
164
  mDraggable = draggable
168
- if (marker != null) {
169
- marker!!.isDraggable = draggable
170
- mMapView?.pointAnnotationManager?.update(marker!!)
165
+ annotation?.let {
166
+ it.isDraggable = draggable
167
+ mMapView?.pointAnnotationManager?.update(it)
171
168
  }
172
169
  }
173
170
 
174
- fun onSelect(shouldSendEvent: Boolean) {
171
+ fun doSelect(shouldSendEvent: Boolean) {
175
172
  if (calloutView != null) {
176
173
  makeCallout()
177
174
  }
@@ -180,7 +177,7 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
180
177
  }
181
178
  }
182
179
 
183
- fun onDeselect() {
180
+ fun doDeselect() {
184
181
  mManager.handleEvent(makeEvent(false))
185
182
  if (mCalloutSymbol != null) {
186
183
  mMapView?.pointAnnotationManager?.delete(mCalloutSymbol!!)
@@ -188,17 +185,17 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
188
185
  }
189
186
 
190
187
  fun onDragStart() {
191
- mCoordinate = marker!!.point
188
+ mCoordinate = annotation!!.point
192
189
  mManager.handleEvent(makeDragEvent(EventTypes.ANNOTATION_DRAG_START))
193
190
  }
194
191
 
195
192
  fun onDrag() {
196
- mCoordinate = marker!!.point
193
+ mCoordinate = annotation!!.point
197
194
  mManager.handleEvent(makeDragEvent(EventTypes.ANNOTATION_DRAG))
198
195
  }
199
196
 
200
197
  fun onDragEnd() {
201
- mCoordinate = marker!!.point
198
+ mCoordinate = annotation!!.point
202
199
  mManager.handleEvent(makeDragEvent(EventTypes.ANNOTATION_DRAG_END))
203
200
  }
204
201
 
@@ -210,41 +207,42 @@ class RNMBXPointAnnotation(private val mContext: Context, private val mManager:
210
207
  .withIconSize(1.0)
211
208
  .withSymbolSortKey(10.0)
212
209
  }
213
- val symbolManager = mMapView?.pointAnnotationManager
214
- if (symbolManager != null && options != null) {
215
- marker = symbolManager.create(options)
216
- updateOptions()
210
+ mMapView?.pointAnnotationManager?.let { annotationManager ->
211
+ options?.let {
212
+ annotation = annotationManager.create(options)
213
+ updateOptions()
214
+ }
217
215
  }
218
216
  }
219
217
 
220
218
  private fun updateOptions() {
221
- if (marker != null) {
219
+ if (annotation != null) {
222
220
  updateIconImage()
223
221
  updateAnchor()
224
- mMapView?.pointAnnotationManager?.update(marker!!)
222
+ mMapView?.pointAnnotationManager?.update(annotation!!)
225
223
  }
226
224
  }
227
225
 
228
226
  private fun updateIconImage() {
229
227
  if (mChildView != null) {
230
228
  if (mChildBitmapId != null) {
231
- marker?.iconImage = mChildBitmapId
229
+ annotation?.iconImage = mChildBitmapId
232
230
  }
233
231
  } else {
234
- marker?.iconImage = MARKER_IMAGE_ID
235
- marker?.iconAnchor = IconAnchor.BOTTOM
232
+ annotation?.iconImage = MARKER_IMAGE_ID
233
+ annotation?.iconAnchor = IconAnchor.BOTTOM
236
234
  }
237
235
  }
238
236
 
239
237
  private fun updateAnchor() {
240
- if (mAnchor != null && mChildView != null && mChildBitmap != null && marker != null) {
238
+ if (mAnchor != null && mChildView != null && mChildBitmap != null && annotation != null) {
241
239
  var w = mChildBitmap!!.width
242
240
  var h = mChildBitmap!!.height
243
241
  val scale = resources.displayMetrics.density
244
242
  w = (w / scale).toInt()
245
243
  h = (h / scale).toInt()
246
- marker?.iconAnchor = IconAnchor.TOP_LEFT
247
- marker?.iconOffset = Arrays.asList(w.toDouble() * mAnchor!![0] * -1.0, h.toDouble() * mAnchor!![1] * -1.0)
244
+ annotation?.iconAnchor = IconAnchor.TOP_LEFT
245
+ annotation?.iconOffset = Arrays.asList(w.toDouble() * mAnchor!![0] * -1.0, h.toDouble() * mAnchor!![1] * -1.0)
248
246
  }
249
247
  }
250
248
 
@@ -209,8 +209,18 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
209
209
 
210
210
  private val mSources: MutableMap<String, RNMBXSource<*>>
211
211
  private val mImages: MutableList<RNMBXImages>
212
- private var mPointAnnotationManager: PointAnnotationManager? = null
213
- private var mActiveMarkerID: AnnotationID = INVALID_ANNOTATION_ID
212
+ public val pointAnnotationManager: RNMBXPointAnnotationManager by lazy {
213
+ val gesturesPlugin: GesturesPlugin = mapView.gestures
214
+ gesturesPlugin.removeOnMapClickListener(this)
215
+ gesturesPlugin.removeOnMapLongClickListener(this)
216
+
217
+ val result = RNMBXPointAnnotationManager(mapView)
218
+
219
+ gesturesPlugin.addOnMapClickListener(this)
220
+ gesturesPlugin.addOnMapLongClickListener(this)
221
+
222
+ result
223
+ }
214
224
  private var mProjection: ProjectionName = ProjectionName.MERCATOR
215
225
  private var mLocaleString: String? = null
216
226
  private var mLocaleLayerIds: List<String>? = null
@@ -219,7 +229,6 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
219
229
  private var mCamera: RNMBXCamera? = null
220
230
  private val mFeatures = mutableListOf<FeatureEntry>()
221
231
  private var mQueuedFeatures: MutableList<AbstractMapFeature>? = ArrayList()
222
- private val mPointAnnotations: MutableMap<String, RNMBXPointAnnotation>
223
232
  private val mCameraChangeTracker = CameraChangeTracker()
224
233
  private lateinit var mMap: MapboxMap
225
234
 
@@ -233,8 +242,6 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
233
242
  private var styleLoaded = false
234
243
 
235
244
  private var mHandledMapChangedEvents: HashSet<String>? = null
236
- private var mAnnotationClicked = false
237
- private var mAnnotationDragged = false
238
245
  private var mLocationComponentManager: LocationComponentManager? = null
239
246
  var tintColor: Int? = null
240
247
  private set
@@ -255,6 +262,8 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
255
262
  updateRequestDisallowInterceptTouchEvent(oldValue, value)
256
263
  }
257
264
 
265
+ var deselectAnnotationOnTap = false
266
+
258
267
  fun getMapboxMap(): MapboxMap {
259
268
  return mapView.getMapboxMap()
260
269
  }
@@ -264,66 +273,6 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
264
273
  mManager.tagAssigned(id)
265
274
  }
266
275
 
267
- val pointAnnotationManager: PointAnnotationManager?
268
- get() {
269
- if (mPointAnnotationManager == null) {
270
- val _this = this
271
- val gesturesPlugin: GesturesPlugin = mapView.gestures
272
- gesturesPlugin.removeOnMapClickListener(_this)
273
- gesturesPlugin.removeOnMapLongClickListener(_this)
274
-
275
- mPointAnnotationManager = mapView.annotations.createPointAnnotationManager(AnnotationConfig(layerId = "RNMBX-mapview-annotations"))
276
- mPointAnnotationManager?.addClickListener(OnPointAnnotationClickListener { pointAnnotation ->
277
- onMarkerClick(pointAnnotation)
278
- false
279
- }
280
- )
281
- mPointAnnotationManager?.addDragListener(object : OnPointAnnotationDragListener {
282
- override fun onAnnotationDragStarted(_annotation: Annotation<*>) {
283
- mAnnotationDragged = true;
284
- var reactAnnotation: RNMBXPointAnnotation? = null
285
- for (key in mPointAnnotations.keys) {
286
- val annotation = mPointAnnotations[key]
287
- val curMarkerID = annotation?.mapboxID
288
- if (_annotation.id == curMarkerID) {
289
- reactAnnotation = annotation
290
- }
291
- }
292
- reactAnnotation?.let { it.onDragStart() }
293
- }
294
-
295
- override fun onAnnotationDrag(_annotation: Annotation<*>) {
296
- var reactAnnotation: RNMBXPointAnnotation? = null
297
- for (key in mPointAnnotations.keys) {
298
- val annotation = mPointAnnotations[key]
299
- val curMarkerID = annotation?.mapboxID
300
- if (_annotation.id == curMarkerID) {
301
- reactAnnotation = annotation
302
- }
303
- }
304
- reactAnnotation?.let { it.onDrag() }
305
- }
306
-
307
- override fun onAnnotationDragFinished(_annotation: Annotation<*>) {
308
- mAnnotationDragged = false;
309
- var reactAnnotation: RNMBXPointAnnotation? = null
310
- for (key in mPointAnnotations.keys) {
311
- val annotation = mPointAnnotations[key]
312
- val curMarkerID = annotation?.mapboxID
313
- if (_annotation.id == curMarkerID) {
314
- reactAnnotation = annotation
315
- }
316
- }
317
- reactAnnotation?.let { it.onDragEnd() }
318
- }
319
- })
320
- gesturesPlugin.addOnMapClickListener(_this)
321
- gesturesPlugin.addOnMapLongClickListener(_this)
322
-
323
- }
324
- return mPointAnnotationManager
325
- }
326
-
327
276
  private fun styleLoaded(style: Style) {
328
277
  savedStyle = style
329
278
  styleLoaded = true
@@ -478,7 +427,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
478
427
  feature = childView
479
428
  } else if (childView is RNMBXPointAnnotation) {
480
429
  val annotation = childView
481
- mPointAnnotations[annotation.iD.toString()] = annotation
430
+ pointAnnotationManager.add(annotation)
482
431
  feature = childView
483
432
  } else if (childView is RNMBXMarkerView) {
484
433
  feature = childView
@@ -514,10 +463,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
514
463
  mSources.remove(feature.iD)
515
464
  } else if (feature is RNMBXPointAnnotation) {
516
465
  val annotation = feature
517
- if (annotation.mapboxID == mActiveMarkerID) {
518
- mActiveMarkerID = INVALID_ANNOTATION_ID
519
- }
520
- mPointAnnotations.remove(annotation.iD)
466
+ pointAnnotationManager.remove(annotation)
521
467
  } else if (feature is RNMBXImages) {
522
468
  mImages.remove(feature)
523
469
  }
@@ -783,12 +729,14 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
783
729
 
784
730
  override fun onMapClick(point: Point): Boolean {
785
731
  val _this = this
786
- /*if (mPointAnnotationManager != nil) {
787
- getAnnotations()
788
- }*/if (mAnnotationClicked) {
789
- mAnnotationClicked = false
732
+ if (pointAnnotationManager.getAndClearAnnotationClicked()) {
790
733
  return true
791
734
  }
735
+ if (deselectAnnotationOnTap) {
736
+ if (pointAnnotationManager.deselectSelectedAnnotation()) {
737
+ return true
738
+ }
739
+ }
792
740
  val screenPoint = mMap?.pixelForCoordinate(point)
793
741
  val touchableSources = allTouchableSources
794
742
  val hits = HashMap<String?, List<Feature?>?>()
@@ -817,8 +765,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
817
765
 
818
766
  override fun onMapLongClick(point: Point): Boolean {
819
767
  val _this = this
820
- if (mAnnotationDragged) {
821
- mAnnotationDragged = false
768
+ if (pointAnnotationManager.getAndClearAnnotationDragged()) {
822
769
  return true
823
770
  }
824
771
  val screenPoint = mMap?.pixelForCoordinate(point)
@@ -830,35 +777,6 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
830
777
  return false
831
778
  }
832
779
 
833
- fun onMarkerClick(symbol: PointAnnotation) {
834
- mAnnotationClicked = true
835
- val selectedMarkerID = symbol.id
836
- var activeAnnotation: RNMBXPointAnnotation? = null
837
- var nextActiveAnnotation: RNMBXPointAnnotation? = null
838
- for (key in mPointAnnotations.keys) {
839
- val annotation = mPointAnnotations[key]
840
- val curMarkerID = annotation?.mapboxID
841
- if (mActiveMarkerID == curMarkerID) {
842
- activeAnnotation = annotation
843
- }
844
- if (selectedMarkerID == curMarkerID && mActiveMarkerID != curMarkerID) {
845
- nextActiveAnnotation = annotation
846
- }
847
- }
848
- activeAnnotation?.let { deselectAnnotation(it) }
849
- nextActiveAnnotation?.let { selectAnnotation(it) }
850
- }
851
-
852
- fun selectAnnotation(annotation: RNMBXPointAnnotation) {
853
- mActiveMarkerID = annotation.mapboxID
854
- annotation.onSelect(true)
855
- }
856
-
857
- fun deselectAnnotation(annotation: RNMBXPointAnnotation) {
858
- mActiveMarkerID = INVALID_ANNOTATION_ID
859
- annotation.onDeselect()
860
- }
861
-
862
780
  interface FoundLayerCallback {
863
781
  fun found(layer: Layer?)
864
782
  }
@@ -1266,7 +1184,6 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
1266
1184
 
1267
1185
  mSources = HashMap()
1268
1186
  mImages = ArrayList()
1269
- mPointAnnotations = HashMap()
1270
1187
  }
1271
1188
 
1272
1189
  // region Ornaments
@@ -1610,4 +1527,154 @@ fun OrnamentSettings.setPosAndMargins(posAndMargins: ReadableMap?) {
1610
1527
  this.margins = margins
1611
1528
  }
1612
1529
 
1530
+ class RNMBXPointAnnotationManager(val mapView: MapView) {
1531
+ val manager: PointAnnotationManager;
1532
+ var annotationClicked = false
1533
+ var annotationDragged = false
1534
+
1535
+ var selected: RNMBXPointAnnotation? = null
1536
+
1537
+ val annotations: MutableMap<String, RNMBXPointAnnotation> = hashMapOf()
1538
+
1539
+ init {
1540
+ manager = mapView.annotations.createPointAnnotationManager(AnnotationConfig(layerId = "RNMBX-mapview-annotations"))
1541
+ manager.addClickListener(OnPointAnnotationClickListener { pointAnnotation ->
1542
+ onAnnotationClick(pointAnnotation)
1543
+ false
1544
+ })
1545
+ }
1546
+
1547
+ fun getAndClearAnnotationClicked(): Boolean {
1548
+ if (annotationClicked) {
1549
+ annotationClicked = false
1550
+ return true
1551
+ }
1552
+ return false
1553
+ }
1554
+
1555
+ fun getAndClearAnnotationDragged(): Boolean {
1556
+ if (annotationDragged) {
1557
+ annotationDragged = false
1558
+ return true
1559
+ }
1560
+ return false
1561
+ }
1562
+
1563
+ fun lookup(point: PointAnnotation): RNMBXPointAnnotation? {
1564
+ for (annotation in annotations.values) {
1565
+ if (point.id == annotation.mapboxID) {
1566
+ return annotation;
1567
+ }
1568
+ }
1569
+ Logger.e(LOG_TAG, "Failed to find RNMBXPointAnntoation for ${point.id}")
1570
+ return null;
1571
+ }
1572
+
1573
+ fun onAnnotationClick(pointAnnotation: RNMBXPointAnnotation) {
1574
+ var oldSelected: RNMBXPointAnnotation? = selected
1575
+ var newSelected: RNMBXPointAnnotation? = pointAnnotation
1576
+
1577
+ annotationClicked = true
1578
+
1579
+ if (newSelected == oldSelected) {
1580
+ newSelected = null
1581
+ }
1582
+
1583
+ manager.addDragListener(object : OnPointAnnotationDragListener {
1584
+ override fun onAnnotationDragStarted(_annotation: Annotation<*>) {
1585
+ annotationDragged = true;
1586
+ var reactAnnotation: RNMBXPointAnnotation? = null
1587
+ for (key in annotations.keys) {
1588
+ val annotation = annotations[key]
1589
+ val curMarkerID = annotation?.mapboxID
1590
+ if (_annotation.id == curMarkerID) {
1591
+ reactAnnotation = annotation
1592
+ }
1593
+ }
1594
+ reactAnnotation?.let { it.onDragStart() }
1595
+ }
1596
+
1597
+ override fun onAnnotationDrag(_annotation: Annotation<*>) {
1598
+ var reactAnnotation: RNMBXPointAnnotation? = null
1599
+ for (key in annotations.keys) {
1600
+ val annotation = annotations[key]
1601
+ val curMarkerID = annotation?.mapboxID
1602
+ if (_annotation.id == curMarkerID) {
1603
+ reactAnnotation = annotation
1604
+ }
1605
+ }
1606
+ reactAnnotation?.let { it.onDrag() }
1607
+ }
1608
+
1609
+ override fun onAnnotationDragFinished(_annotation: Annotation<*>) {
1610
+ annotationDragged = false;
1611
+ var reactAnnotation: RNMBXPointAnnotation? = null
1612
+ for (key in annotations.keys) {
1613
+ val annotation = annotations[key]
1614
+ val curMarkerID = annotation?.mapboxID
1615
+ if (_annotation.id == curMarkerID) {
1616
+ reactAnnotation = annotation
1617
+ }
1618
+ }
1619
+ reactAnnotation?.let { it.onDragEnd() }
1620
+ }
1621
+ })
1622
+
1623
+ oldSelected?.let { deselectAnnotation(it) }
1624
+ newSelected?.let { selectAnnotation(it) }
1625
+
1626
+ }
1627
+
1628
+ fun onAnnotationClick(point: PointAnnotation) {
1629
+ lookup(point)?.let {
1630
+ onAnnotationClick(it)
1631
+ }
1632
+ }
1633
+
1634
+ fun deselectSelectedAnnotation(): Boolean {
1635
+ selected?.let {
1636
+ deselectAnnotation(it)
1637
+ return true
1638
+ }
1639
+ return false
1640
+ }
1641
+
1642
+ fun selectAnnotation(annotation: RNMBXPointAnnotation) {
1643
+ selected = annotation
1644
+ annotation.doSelect(true)
1645
+ }
1646
+
1647
+ fun deselectAnnotation(annotation: RNMBXPointAnnotation) {
1648
+ selected = null
1649
+ annotation.doDeselect()
1650
+ }
1651
+
1652
+ fun remove(annotation: RNMBXPointAnnotation) {
1653
+ if (annotation == selected) {
1654
+ selected = null
1655
+ }
1656
+ annotations.remove(annotation.iD)
1657
+ }
1658
+
1659
+ fun delete(annotation: PointAnnotation) {
1660
+ manager.delete(annotation)
1661
+ }
1662
+
1663
+ fun update(annotation: PointAnnotation) {
1664
+ manager.update(annotation)
1665
+ }
1666
+
1667
+ fun create(options: PointAnnotationOptions): PointAnnotation {
1668
+ return manager.create(options)
1669
+ }
1670
+
1671
+ fun add(annotation: RNMBXPointAnnotation) {
1672
+ annotations[annotation.iD!!] = annotation
1673
+ }
1674
+
1675
+ companion object {
1676
+ const val LOG_TAG = "RNMBXPointAnnotationManager";
1677
+ }
1678
+ }
1679
+
1613
1680
 
@@ -330,6 +330,13 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso
330
330
  mapView.requestDisallowInterceptTouchEvent = requestDisallowInterceptTouchEvent.asBoolean()
331
331
  }
332
332
 
333
+ @ReactProp(name = "deselectAnnotationOnTap")
334
+ override fun setDeselectAnnotationOnTap(mapView: RNMBXMapView, value: Dynamic?) {
335
+ value?.let {
336
+ mapView.deselectAnnotationOnTap = it.asBoolean()
337
+ }
338
+ }
339
+
333
340
  override fun setCompassImage(view: RNMBXMapView, value: Dynamic?) {
334
341
  // TODO: No-op on Android?
335
342
  }
@@ -100,6 +100,11 @@ object GeoJSONUtils {
100
100
  val map: WritableMap = WritableNativeMap()
101
101
  map.putString("type", "Feature")
102
102
  map.putMap("geometry", toPointGeometry(latLng))
103
+ properties?.let {
104
+ if (it.hasKey("id") == true) {
105
+ map.putString("id", it.getString("id"));
106
+ }
107
+ }
103
108
  map.putMap("properties", properties)
104
109
  return map
105
110
  }
@@ -67,6 +67,9 @@ public class RNMBXMapViewManagerDelegate<T extends View, U extends BaseViewManag
67
67
  case "pitchEnabled":
68
68
  mViewManager.setPitchEnabled(view, new DynamicFromObject(value));
69
69
  break;
70
+ case "deselectAnnotationOnTap":
71
+ mViewManager.setDeselectAnnotationOnTap(view, new DynamicFromObject(value));
72
+ break;
70
73
  case "requestDisallowInterceptTouchEvent":
71
74
  mViewManager.setRequestDisallowInterceptTouchEvent(view, new DynamicFromObject(value));
72
75
  break;
@@ -28,6 +28,7 @@ public interface RNMBXMapViewManagerInterface<T extends View> {
28
28
  void setScrollEnabled(T view, Dynamic value);
29
29
  void setRotateEnabled(T view, Dynamic value);
30
30
  void setPitchEnabled(T view, Dynamic value);
31
+ void setDeselectAnnotationOnTap(T view, Dynamic value);
31
32
  void setRequestDisallowInterceptTouchEvent(T view, Dynamic value);
32
33
  void setProjection(T view, Dynamic value);
33
34
  void setLocalizeLabels(T view, Dynamic value);
@@ -38,6 +38,8 @@ class RNMBXEvent : NSObject, RNMBXEventProtocol {
38
38
  case onUserTrackingModeChange
39
39
  case vectorSourceLayerPress
40
40
  case shapeSourceLayerPress
41
+ case annotationSelected = "annotationselected"
42
+ case annotationDeselected = "annotationdeselected"
41
43
  }
42
44
 
43
45
  init(type: EventType, payload: [String:Any?]?) {