@rnmapbox/maps 10.0.0-beta.46 → 10.0.0-beta.48

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 (32) hide show
  1. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/AbstractMapFeature.kt +23 -2
  2. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerView.kt +3 -4
  3. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLPointAnnotation.kt +2 -2
  4. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCamera.kt +24 -29
  5. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCameraManager.kt +16 -25
  6. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt +2 -0
  7. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/RCTMGLNativeUserLocation.kt +2 -2
  8. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +245 -76
  9. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapViewManager.kt +25 -2
  10. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/atmosphere/RCTMGLAtmosphere.kt +2 -0
  11. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTLayer.kt +2 -2
  12. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLShapeSource.kt +4 -0
  13. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTSource.kt +2 -3
  14. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/terrain/RCTMGLTerrain.kt +2 -0
  15. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/ConvertUtils.java +1 -1
  16. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/LatLngBounds.kt +35 -0
  17. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/CoordinateBounds.kt +23 -0
  18. package/docs/MapView.md +2 -2
  19. package/docs/docs.json +5 -5
  20. package/ios/RCTMGL-v10/RCTMGLCamera.swift +60 -4
  21. package/ios/RCTMGL-v10/RCTMGLCameraManager.m +1 -0
  22. package/ios/RCTMGL-v10/RCTMGLMapView.swift +14 -26
  23. package/ios/RCTMGL-v10/RCTMGLMapViewManager.swift +9 -11
  24. package/ios/RCTMGL-v10/RCTMGLShapeSource.swift +29 -23
  25. package/ios/RCTMGL-v10/RCTMGLShapeSourceManager.m +3 -3
  26. package/ios/RCTMGL-v10/RCTMGLShapeSourceManager.swift +3 -3
  27. package/javascript/components/MapView.js +20 -15
  28. package/javascript/components/MarkerView.tsx +12 -1
  29. package/javascript/components/ShapeSource.tsx +3 -3
  30. package/javascript/components/SymbolLayer.tsx +1 -1
  31. package/package.json +1 -1
  32. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/LatLngBounds.java +0 -42
@@ -26,19 +26,17 @@ import com.mapbox.maps.extension.style.layers.getLayer
26
26
  import com.mapbox.maps.extension.style.layers.properties.generated.Visibility
27
27
  import com.mapbox.maps.plugin.annotation.Annotation
28
28
  import com.mapbox.maps.plugin.annotation.annotations
29
- import com.mapbox.maps.plugin.annotation.generated.OnPointAnnotationClickListener
30
- import com.mapbox.maps.plugin.annotation.generated.OnPointAnnotationDragListener
31
- import com.mapbox.maps.plugin.annotation.generated.PointAnnotation
32
- import com.mapbox.maps.plugin.annotation.generated.PointAnnotationManager
33
- import com.mapbox.maps.plugin.annotation.generated.createPointAnnotationManager
29
+ import com.mapbox.maps.plugin.annotation.generated.*
34
30
  import com.mapbox.maps.plugin.attribution.attribution
35
31
  import com.mapbox.maps.plugin.attribution.generated.AttributionSettings
36
32
  import com.mapbox.maps.plugin.compass.compass
33
+ import com.mapbox.maps.plugin.compass.generated.CompassSettings
37
34
  import com.mapbox.maps.plugin.delegates.listeners.*
38
35
  import com.mapbox.maps.plugin.gestures.*
39
36
  import com.mapbox.maps.plugin.logo.generated.LogoSettings
40
37
  import com.mapbox.maps.plugin.logo.logo
41
- import com.mapbox.maps.viewannotation.ViewAnnotationManager
38
+ import com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettings
39
+ import com.mapbox.maps.plugin.scalebar.scalebar
42
40
  import com.mapbox.rctmgl.R
43
41
  import com.mapbox.rctmgl.components.AbstractMapFeature
44
42
  import com.mapbox.rctmgl.components.annotation.RCTMGLMarkerView
@@ -57,6 +55,7 @@ import com.mapbox.rctmgl.events.IEvent
57
55
  import com.mapbox.rctmgl.events.MapChangeEvent
58
56
  import com.mapbox.rctmgl.events.MapClickEvent
59
57
  import com.mapbox.rctmgl.events.constants.EventTypes
58
+ import com.mapbox.rctmgl.utils.BitmapUtils
60
59
  import com.mapbox.rctmgl.utils.GeoJSONUtils
61
60
  import com.mapbox.rctmgl.utils.LatLng
62
61
  import com.mapbox.rctmgl.utils.Logger
@@ -66,6 +65,13 @@ import org.json.JSONObject
66
65
  import java.util.*
67
66
 
68
67
 
68
+ data class OrnamentSettings(
69
+ var enabled : Boolean? = false,
70
+ var margins: ReadableMap? =null,
71
+ var position: Int = -1
72
+ )
73
+
74
+
69
75
  interface RCTMGLMapViewLifecycleOwner : LifecycleOwner {
70
76
  fun handleLifecycleEvent(event: Lifecycle.Event)
71
77
  }
@@ -389,6 +395,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
389
395
  }
390
396
 
391
397
  fun setReactStyleURL(styleURL: String) {
398
+ mStyleURL = styleURL
392
399
  if (mMap != null) {
393
400
  removeAllFeaturesFromMap()
394
401
  if (isJSONValid(mStyleURL)) {
@@ -608,7 +615,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
608
615
  properties.putBoolean("isUserInteraction", mCameraChangeTracker.isUserInteraction)
609
616
  try {
610
617
  val bounds = mMap.coordinateBoundsForCamera(position.toCameraOptions())
611
- properties.putArray("visibleBounds", GeoJSONUtils.fromCoordinateBounds(bounds))
618
+ properties.putArray("visibleBounds", bounds.toReadableArray())
612
619
  } catch (ex: Exception) {
613
620
  Logger.e(LOG_TAG, "An error occurred while attempting to make the region", ex)
614
621
  }
@@ -724,7 +731,8 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
724
731
  }
725
732
 
726
733
  fun queryRenderedFeaturesInRect(callbackID: String?, rect: RectF, filter: Expression?, layerIDs: List<String>?) {
727
- val screenBox = ScreenBox(
734
+ val size = mMap!!.getMapOptions().size
735
+ val screenBox = if (rect.isEmpty()) ScreenBox(ScreenCoordinate(0.0, 0.0), ScreenCoordinate(size?.width!!.toDouble(), size?.height!!.toDouble())) else ScreenBox(
728
736
  ScreenCoordinate(rect.right.toDouble(), rect.bottom.toDouble() ),
729
737
  ScreenCoordinate(rect.left.toDouble(), rect.top.toDouble()),
730
738
  )
@@ -760,10 +768,32 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
760
768
  val bounds = mMap!!.coordinateBoundsForCamera(mMap!!.cameraState.toCameraOptions())
761
769
 
762
770
  sendResponse(callbackID, {
763
- it.putArray("visibleBounds", GeoJSONUtils.fromCoordinateBounds(bounds))
771
+ it.putArray("visibleBounds", bounds.toReadableArray())
764
772
  })
765
773
  }
766
774
 
775
+ fun takeSnap(callbackID: String?, writeToDisk: Boolean) {
776
+ this.snapshot { snapshot ->
777
+ if (snapshot == null) {
778
+ Logger.e("takeSnap", "snapshot failed")
779
+
780
+ sendResponse(callbackID, {
781
+ it.putNull("data")
782
+ it.putString("error", "no snapshot")
783
+ })
784
+ } else {
785
+ val uri: String = if (writeToDisk) BitmapUtils.createTempFile(
786
+ mContext,
787
+ snapshot
788
+ ) else BitmapUtils.createBase64(snapshot)
789
+
790
+ sendResponse(callbackID, {
791
+ it.putString("uri", uri)
792
+ })
793
+ }
794
+ }
795
+ }
796
+
767
797
  fun queryTerrainElevation(callbackID: String?, longitude: Double, latitude: Double) {
768
798
  val result = mMap?.getElevation(Point.fromLngLat(longitude, latitude))
769
799
 
@@ -858,12 +888,12 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
858
888
 
859
889
  // region Ornaments
860
890
 
861
- fun toGravity(kind: String, viewPosition: Int): Int {
891
+ private fun toGravity(kind: String, viewPosition: Int): Int {
862
892
  return when (viewPosition) {
863
- 0 -> (Gravity.TOP or Gravity.START)
864
- 1 -> (Gravity.TOP or Gravity.END)
865
- 2 -> (Gravity.BOTTOM or Gravity.START)
866
- 3 -> (Gravity.BOTTOM or Gravity.END)
893
+ 0 -> (Gravity.TOP or Gravity.LEFT)
894
+ 1 -> (Gravity.TOP or Gravity.RIGHT)
895
+ 2 -> (Gravity.BOTTOM or Gravity.LEFT)
896
+ 3 -> (Gravity.BOTTOM or Gravity.RIGHT)
867
897
  else -> {
868
898
  Logger.e(
869
899
  "MapView",
@@ -874,13 +904,46 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
874
904
  }
875
905
  }
876
906
 
877
- var mCompassEnabled = false
907
+ private fun updateOrnament(kind: String, from: OrnamentSettings, to: GenericOrnamentSettings) {
908
+ from.enabled?.let { to.enabled = it }
909
+ if (from.position >= 0) {
910
+ to.position = toGravity(kind, from.position)
911
+ }
912
+
913
+ from.margins?.let {
914
+ val pixelDensity = resources.displayMetrics.density
915
+ val x: Int? = it.getDouble("x")?.let { (it * pixelDensity).toInt() }
916
+ val y: Int? = it.getDouble("y")?.let { (it * pixelDensity).toInt() }
917
+
918
+ val horizontalGravity = to.position and Gravity.HORIZONTAL_GRAVITY_MASK
919
+ val verticalGravity = to.position and Gravity.VERTICAL_GRAVITY_MASK
920
+
921
+ when (horizontalGravity) {
922
+ Gravity.LEFT -> { to.setHMargins(x?.toFloat(), 0f) }
923
+ Gravity.RIGHT -> { to.setHMargins(0f, x?.toFloat()) }
924
+ Gravity.CENTER_HORIZONTAL ->{ to.setHMargins(x?.toFloat(), x?.toFloat()) }
925
+ else -> Logger.e(
926
+ "MapView",
927
+ "${kind}ViewMargins: unexpected absolute pos: $horizontalGravity"
928
+ )
929
+ }
930
+ when (verticalGravity) {
931
+ Gravity.TOP -> { to.setVMargins(y?.toFloat(), 0f) }
932
+ Gravity.BOTTOM -> { to.setVMargins(0f, y?.toFloat()) }
933
+ Gravity.CENTER_VERTICAL -> { to.setVMargins(y?.toFloat(), y?.toFloat()) }
934
+ else -> Logger.e(
935
+ "MapView",
936
+ "${kind}ViewMargins: unexpected vertical pos: $verticalGravity"
937
+ )
938
+ }
939
+ }
940
+ }
941
+
942
+ var mCompassSettings = OrnamentSettings(enabled = false)
878
943
  var mCompassFadeWhenNorth = false
879
- var mCompassViewMargins: ReadableMap? = null
880
- var mCompassViewPosition: Int = -1
881
944
 
882
945
  fun setReactCompassEnabled(compassEnabled: Boolean) {
883
- mCompassEnabled = compassEnabled
946
+ mCompassSettings.enabled = compassEnabled
884
947
  updateCompass()
885
948
  }
886
949
 
@@ -890,82 +953,55 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
890
953
  }
891
954
 
892
955
  fun setReactCompassViewMargins(compassViewMargins: ReadableMap) {
893
- mCompassViewMargins = compassViewMargins
956
+ mCompassSettings.margins = compassViewMargins
894
957
  updateCompass()
895
958
  }
896
959
 
897
960
  fun setReactCompassViewPosition(compassViewPosition: Int) {
898
- mCompassViewPosition = compassViewPosition
961
+ mCompassSettings.position = compassViewPosition
899
962
  updateCompass()
900
963
  }
901
964
 
902
- fun setReactCompassMargins(compassMargins: ReadableMap) {
903
- val bottom_mask = 1;
904
- val right_mask = 2;
905
-
906
- var margins = WritableNativeMap()
907
- var position = 0;
908
- if (compassMargins.hasKey("bottom")) {
909
- margins.putInt("y", compassMargins.getInt("bottom"))
910
- position = position or bottom_mask
911
- } else {
912
- if (compassMargins.hasKey("top")) {
913
- margins.putInt("y", compassMargins.getInt("top"))
914
- }
915
- }
916
-
917
- if (compassMargins.hasKey("left")) {
918
- margins.putInt("x", compassMargins.getInt("left"))
919
- } else {
920
- if (compassMargins.hasKey("right")) {
921
- margins.putInt("x", compassMargins.getInt("right"))
922
- }
923
- }
924
- mCompassViewPosition = position
925
- mCompassViewMargins = margins
965
+ fun setReactCompassPosition(compassPosition: ReadableMap) {
966
+ mCompassSettings.setPosAndMargins(compassPosition)
926
967
  updateCompass()
927
968
  }
928
969
 
929
970
  private fun updateCompass() {
930
971
  compass.updateSettings {
931
- enabled = mCompassEnabled
932
972
  fadeWhenFacingNorth = mCompassFadeWhenNorth
933
- if (mCompassViewPosition >= 0) {
934
- position = toGravity("compass", mCompassViewPosition)
935
- }
973
+ updateOrnament("compass", mCompassSettings, this.toGenericOrnamentSettings())
974
+ }
975
+ }
936
976
 
937
- val compassViewMargins = mCompassViewMargins
938
- if (compassViewMargins != null) {
939
- val pixelDensity = resources.displayMetrics.density.toInt()
940
- val x: Int = compassViewMargins.getInt("x") * pixelDensity
941
- val y: Int = compassViewMargins.getInt("y") * pixelDensity
977
+ var mScaleBarSettings = OrnamentSettings(enabled = false)
942
978
 
943
- val horizontalGravity = position and Gravity.HORIZONTAL_GRAVITY_MASK
944
- val verticalGravity = position and Gravity.VERTICAL_GRAVITY_MASK
979
+ fun setReactScaleBarEnabled(scaleBarEnabled: Boolean) {
980
+ mScaleBarSettings.enabled = scaleBarEnabled
981
+ updateScaleBar()
982
+ }
945
983
 
946
- when (horizontalGravity) {
947
- Gravity.LEFT -> {
948
- marginLeft = x.toFloat()
949
- }
950
- Gravity.RIGHT -> marginRight = x.toFloat()
951
- Gravity.CENTER_HORIZONTAL -> marginLeft = x.toFloat()
952
- else -> Logger.e(
953
- "MapView",
954
- "compassViewMargins: unexpected absolute pos: $horizontalGravity"
955
- )
956
- }
957
- when (verticalGravity) {
958
- Gravity.TOP -> marginTop = y.toFloat()
959
- Gravity.BOTTOM -> marginBottom = y.toFloat()
960
- Gravity.CENTER_VERTICAL -> marginTop = y.toFloat()
961
- else -> Logger.e(
962
- "MapView",
963
- "compassViewMargins: unexpected vertical pos: $verticalGravity"
964
- )
965
- }
966
- }
984
+ fun setReactScaleBarViewMargins(scaleBarMargins: ReadableMap) {
985
+ mScaleBarSettings.margins = scaleBarMargins
986
+ updateScaleBar()
987
+ }
988
+
989
+ fun setReactScaleBarViewPosition(scaleBarPosition: Int) {
990
+ mScaleBarSettings.position = scaleBarPosition
991
+ updateScaleBar()
992
+ }
993
+
994
+ fun setReactScaleBarPosition(scaleBarPosition: ReadableMap) {
995
+ mScaleBarSettings.setPosAndMargins(scaleBarPosition)
996
+ updateScaleBar()
997
+ }
998
+
999
+ private fun updateScaleBar() {
1000
+ scalebar.updateSettings {
1001
+ updateOrnament("scaleBar", mScaleBarSettings, this.toGenericOrnamentSettings())
967
1002
  }
968
1003
  }
1004
+
969
1005
  // endregion
970
1006
 
971
1007
  private fun getGravityAndMargin (position:ReadableMap): Pair<Int, IntArray> {
@@ -1043,6 +1079,44 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
1043
1079
  private var mLogoGravity: Int? = null
1044
1080
  private var mLogoMargin: IntArray? = null
1045
1081
 
1082
+ var mLogoSettings = OrnamentSettings(enabled = null)
1083
+
1084
+ fun setReactLogoEnabled(enabled: Boolean?) {
1085
+ mLogoSettings.enabled = enabled
1086
+ updateLogo()
1087
+ }
1088
+
1089
+ fun setReactLogoMargins(margins: ReadableMap) {
1090
+ mLogoSettings.margins = margins
1091
+ updateLogo()
1092
+ }
1093
+
1094
+ fun setReactLogoViewPosition(position: Int) {
1095
+ mLogoSettings.position = position
1096
+ updateLogo()
1097
+ }
1098
+
1099
+ fun setReactLogoPosition(position: ReadableMap?) {
1100
+ mLogoSettings.setPosAndMargins(position)
1101
+ updateLogo()
1102
+ }
1103
+
1104
+ private fun updateLogo() {
1105
+ logo.updateSettings {
1106
+ updateOrnament("logo", mLogoSettings, this.toGenericOrnamentSettings())
1107
+ }
1108
+
1109
+ logo.updateSettings {
1110
+ println(String.format("logo :: position - before 0x%08x", position))
1111
+ //position = Gravity.BOTTOM or Gravity.RIGHT
1112
+ println(String.format("eq bottom|right %b", position == (Gravity.BOTTOM or Gravity.RIGHT)))
1113
+ if (position == Gravity.BOTTOM or Gravity.RIGHT) {
1114
+ position = Gravity.BOTTOM or Gravity.RIGHT
1115
+ }
1116
+ println(String.format("logo :: position - after 0x%08x", position))
1117
+ }
1118
+ }
1119
+ /*
1046
1120
  fun setReactLogoEnabled(logoEnabled: Boolean?) {
1047
1121
  mLogoEnabled = logoEnabled ?: LogoSettings().enabled
1048
1122
  updateLogo()
@@ -1081,6 +1155,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
1081
1155
  }
1082
1156
  }
1083
1157
  }
1158
+ */
1084
1159
  // endregion
1085
1160
 
1086
1161
  // region lifecycle
@@ -1128,3 +1203,97 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
1128
1203
 
1129
1204
  // endregion
1130
1205
  }
1206
+
1207
+ fun OrnamentSettings.setPosAndMargins(posAndMargins: ReadableMap?) {
1208
+ if (posAndMargins == null) { return }
1209
+
1210
+ val bottom_mask = 1;
1211
+ val right_mask = 2;
1212
+
1213
+ var margins = WritableNativeMap()
1214
+ var position = 0;
1215
+ if (posAndMargins
1216
+ .hasKey("bottom")) {
1217
+ margins.putInt("y", posAndMargins.getInt("bottom"))
1218
+ position = position or bottom_mask
1219
+ } else {
1220
+ if (posAndMargins.hasKey("top")) {
1221
+ margins.putInt("y", posAndMargins.getInt("top"))
1222
+ }
1223
+ }
1224
+
1225
+ if (posAndMargins.hasKey("left")) {
1226
+ margins.putInt("x", posAndMargins.getInt("left"))
1227
+ } else {
1228
+ if (posAndMargins.hasKey("right")) {
1229
+ position = position or right_mask
1230
+ margins.putInt("x", posAndMargins.getInt("right"))
1231
+ }
1232
+ }
1233
+ this.position = position
1234
+ this.margins = margins
1235
+ }
1236
+
1237
+ interface GenericOrnamentSettings {
1238
+ fun setHMargins(left: Float?, right: Float?)
1239
+ fun setVMargins(top: Float?, bottom: Float?)
1240
+ var enabled: Boolean
1241
+ var position: Int
1242
+ }
1243
+
1244
+ fun ScaleBarSettings.toGenericOrnamentSettings() = object : GenericOrnamentSettings {
1245
+ private val settings = this@toGenericOrnamentSettings
1246
+ override fun setHMargins(left: Float?, right: Float?) {
1247
+ left?.let { settings.marginLeft = it }
1248
+ right?.let { settings.marginRight = it }
1249
+ }
1250
+ override fun setVMargins(top: Float?, bottom: Float?) {
1251
+ top?.let { settings.marginTop = it }
1252
+ bottom?.let { settings.marginBottom = it }
1253
+ }
1254
+ override var enabled: Boolean
1255
+ get() = settings.enabled
1256
+ set(value) { settings.enabled = value }
1257
+ override var position: Int
1258
+ get() = settings.position
1259
+ set(value) { settings.position = value }
1260
+ }
1261
+
1262
+ fun CompassSettings.toGenericOrnamentSettings() = object : GenericOrnamentSettings {
1263
+ private val settings = this@toGenericOrnamentSettings
1264
+ override fun setHMargins(left: Float?, right: Float?) {
1265
+ left?.let { settings.marginLeft = it }
1266
+ right?.let { settings.marginRight = it }
1267
+ }
1268
+ override fun setVMargins(top: Float?, bottom: Float?) {
1269
+ top?.let { settings.marginTop = it }
1270
+ bottom?.let { settings.marginBottom = it }
1271
+ }
1272
+ override var enabled: Boolean
1273
+ get() = settings.enabled
1274
+ set(value) { settings.enabled = value }
1275
+ override var position: Int
1276
+ get() = settings.position
1277
+ set(value) { settings.position = value }
1278
+ }
1279
+
1280
+ fun LogoSettings.toGenericOrnamentSettings() = object : GenericOrnamentSettings {
1281
+ private val settings = this@toGenericOrnamentSettings
1282
+ override fun setHMargins(left: Float?, right: Float?) {
1283
+ left?.let { settings.marginLeft = it }
1284
+ right?.let { settings.marginRight = it }
1285
+ }
1286
+ override fun setVMargins(top: Float?, bottom: Float?) {
1287
+ top?.let { settings.marginTop = it }
1288
+ bottom?.let { settings.marginBottom = it }
1289
+ }
1290
+ override var enabled: Boolean
1291
+ get() = settings.enabled
1292
+ set(value) { settings.enabled = value }
1293
+ override var position: Int
1294
+ get() = settings.position
1295
+ set(value) {
1296
+ println(String.format("logo :: position: 0x%08x", value))
1297
+ settings.position = value
1298
+ }
1299
+ }
@@ -136,6 +136,26 @@ open class RCTMGLMapViewManager(context: ReactApplicationContext?) :
136
136
  mapView!!.setReactLogoPosition(logoPosition);
137
137
  }
138
138
 
139
+ @ReactProp(name = "scaleBarEnabled")
140
+ fun setScaleBarEnabled(mapView: RCTMGLMapView?, scaleBarEnabled: Boolean) {
141
+ mapView!!.setReactScaleBarEnabled(scaleBarEnabled);
142
+ }
143
+
144
+ @ReactProp(name = "scaleBarViewMargins")
145
+ fun setScaleBarViewMargins(mapView: RCTMGLMapView?, scaleBarMargins: ReadableMap?) {
146
+ mapView!!.setReactScaleBarViewMargins(scaleBarMargins!!);
147
+ }
148
+
149
+ @ReactProp(name = "scaleBarViewPosition")
150
+ fun setScaleBarViewPosition(mapView: RCTMGLMapView?, scaleBarPosition: Int) {
151
+ mapView!!.setReactScaleBarViewPosition(scaleBarPosition!!)
152
+ }
153
+
154
+ @ReactProp(name = "scaleBarPosition")
155
+ fun scaleBarViewPosition(mapView: RCTMGLMapView?, scaleBarPosition: ReadableMap) {
156
+ mapView!!.setReactScaleBarPosition(scaleBarPosition)
157
+ }
158
+
139
159
  @ReactProp(name = "compassEnabled")
140
160
  fun setCompassEnabled(mapView: RCTMGLMapView?, compassEnabled: Boolean) {
141
161
  mapView!!.setReactCompassEnabled(compassEnabled);
@@ -157,8 +177,8 @@ open class RCTMGLMapViewManager(context: ReactApplicationContext?) :
157
177
  }
158
178
 
159
179
  @ReactProp(name = "compassPosition")
160
- fun setCompassMargins(mapView: RCTMGLMapView?, compassMargins: ReadableMap) {
161
- mapView!!.setReactCompassMargins(compassMargins)
180
+ fun setCompassPosition(mapView: RCTMGLMapView?, compassMargins: ReadableMap) {
181
+ mapView!!.setReactCompassPosition(compassMargins)
162
182
  }
163
183
 
164
184
  @ReactProp(name = "contentInset")
@@ -253,6 +273,9 @@ open class RCTMGLMapViewManager(context: ReactApplicationContext?) :
253
273
  METHOD_VISIBLE_BOUNDS -> {
254
274
  mapView.getVisibleBounds(args!!.getString(0));
255
275
  }
276
+ METHOD_TAKE_SNAP -> {
277
+ mapView.takeSnap(args!!.getString(0), args!!.getBoolean(1))
278
+ }
256
279
  }
257
280
  /*
258
281
  switch (commandID) {
@@ -32,6 +32,7 @@ class RCTMGLAtmosphere(context: Context?) : AbstractSourceConsumer(context) {
32
32
  // endregion RCTLayer
33
33
 
34
34
  override fun addToMap(mapView: RCTMGLMapView) {
35
+ super.addToMap(mapView)
35
36
  mMap = mapView.getMapboxMap()
36
37
  val atmosphere = makeAtmosphere()
37
38
  mAtmosphere = atmosphere
@@ -42,6 +43,7 @@ class RCTMGLAtmosphere(context: Context?) : AbstractSourceConsumer(context) {
42
43
  override fun removeFromMap(mapView: RCTMGLMapView) {
43
44
  mapView.savedStyle?.let { it.removeTerrain() }
44
45
  mMap = null
46
+ super.removeFromMap(mapView)
45
47
  }
46
48
 
47
49
  fun makeAtmosphere(): Atmosphere {
@@ -42,7 +42,6 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
42
42
  protected var mMap: MapboxMap? = null
43
43
  @JvmField
44
44
  protected var mLayer: T? = null
45
- protected var mMapView: RCTMGLMapView? = null
46
45
  protected var mHadFilter = false
47
46
 
48
47
  fun setSourceID(sourceID: String?) {
@@ -230,8 +229,8 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
230
229
  }
231
230
 
232
231
  override fun addToMap(mapView: RCTMGLMapView) {
232
+ super.addToMap(mapView)
233
233
  mMap = mapView.getMapboxMap()
234
- mMapView = mapView
235
234
  if (style == null) return
236
235
  val existingLayer = getLayerAs(style, iD)
237
236
  if (existingLayer != null) {
@@ -251,6 +250,7 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
251
250
  if (style != null) {
252
251
  style!!.removeStyleLayer(mLayer!!.layerId)
253
252
  }
253
+ super.removeFromMap(mapView)
254
254
  }
255
255
 
256
256
  // v10TOOD: adding anything seems to make getStyle null
@@ -77,6 +77,10 @@ class RCTMGLShapeSource(context: Context, private val mManager: RCTMGLShapeSourc
77
77
 
78
78
  fun setClusterMaxZoom(clusterMaxZoom: Long) {
79
79
  mClusterMaxZoom = clusterMaxZoom
80
+ if (mSource != null && mMapView != null && !mMapView!!.isDestroyed) {
81
+ val result = mMap!!.getStyle()!!
82
+ .setStyleSourceProperty(iD!!, "clusterMaxZoom", Value.valueOf(clusterMaxZoom))
83
+ }
80
84
  }
81
85
 
82
86
  fun setClusterProperties(clusterProperties: HashMap<String, Any>) {
@@ -24,8 +24,6 @@ import java.util.ArrayList
24
24
  import java.util.HashMap
25
25
 
26
26
  abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(context) {
27
- @JvmField
28
- protected var mMapView: RCTMGLMapView? = null
29
27
  @JvmField
30
28
  protected var mMap: MapboxMap? = null
31
29
  var iD: String? = null
@@ -107,7 +105,7 @@ abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(co
107
105
  }
108
106
 
109
107
  override fun addToMap(mapView: RCTMGLMapView) {
110
- mMapView = mapView
108
+ super.addToMap(mapView)
111
109
  mMap = mapView.getMapboxMap()
112
110
  mMap?.getStyle(object : Style.OnStyleLoaded {
113
111
  override fun onStyleLoaded(style: Style) {
@@ -149,6 +147,7 @@ abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(co
149
147
  Logger.w(LOG_TAG, String.format("RCTSource.removeFromMap: %s - %s", mSource, ex.message), ex)
150
148
  }
151
149
  }
150
+ super.removeFromMap(mapView)
152
151
  }
153
152
 
154
153
  fun addLayer(childView: View?, childPosition: Int) {
@@ -36,6 +36,7 @@ class RCTMGLTerrain(context: Context?) : AbstractSourceConsumer(context) {
36
36
  }
37
37
 
38
38
  override fun addToMap(mapView: RCTMGLMapView) {
39
+ super.addToMap(mapView)
39
40
  mMap = mapView.getMapboxMap()
40
41
  val terrain = makeTerrain()
41
42
  mTerrain = terrain
@@ -46,6 +47,7 @@ class RCTMGLTerrain(context: Context?) : AbstractSourceConsumer(context) {
46
47
  override fun removeFromMap(mapView: RCTMGLMapView) {
47
48
  mapView.savedStyle?.let { it.removeTerrain() }
48
49
  mMap = null
50
+ super.removeFromMap(mapView)
49
51
  }
50
52
 
51
53
  fun makeTerrain(): Terrain {
@@ -217,7 +217,7 @@ public class ConvertUtils {
217
217
  public static RectF toRectF(ReadableArray array) {
218
218
  RectF rectF = new RectF();
219
219
 
220
- if (array == null) {
220
+ if (array == null || array.size() == 0) {
221
221
  return rectF;
222
222
  }
223
223
 
@@ -0,0 +1,35 @@
1
+ package com.mapbox.rctmgl.utils
2
+
3
+ import com.mapbox.geojson.Point
4
+ import com.mapbox.maps.CoordinateBounds
5
+ import com.mapbox.rctmgl.utils.LatLngBounds
6
+
7
+ class LatLngBounds internal constructor(
8
+ var latNorth: Double,
9
+ var lonEast: Double,
10
+ var latSouth: Double,
11
+ var lonWest: Double
12
+ ) {
13
+ val southWest: LatLng
14
+ get() = LatLng(latSouth, lonWest)
15
+ val northEast: LatLng
16
+ get() = LatLng(latNorth, lonEast)
17
+
18
+ fun toLatLngs(): Array<LatLng> {
19
+ return arrayOf(northEast, southWest)
20
+ }
21
+
22
+ fun toBounds(): CoordinateBounds {
23
+ return CoordinateBounds(
24
+ Point.fromLngLat(lonWest, latSouth),
25
+ Point.fromLngLat(lonEast, latNorth),
26
+ false
27
+ )
28
+ }
29
+
30
+ companion object {
31
+ fun from(bbox: Double, bbox1: Double, bbox2: Double, bbox3: Double): LatLngBounds {
32
+ return LatLngBounds(bbox, bbox1, bbox2, bbox3)
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,23 @@
1
+ package com.mapbox.rctmgl.utils.extensions
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.bridge.ReadableArray
5
+ import com.mapbox.maps.CoordinateBounds
6
+ import com.mapbox.rctmgl.utils.GeoJSONUtils
7
+ import com.mapbox.rctmgl.utils.LatLng
8
+
9
+ fun CoordinateBounds.toReadableArray() : ReadableArray {
10
+ val array = Arguments.createArray()
11
+ val ne = northeast
12
+ val sw = southwest
13
+ val latLngs = arrayOf(
14
+ LatLng(ne.latitude(), ne.longitude()),
15
+ LatLng(ne.latitude(), sw.longitude()),
16
+ LatLng(sw.latitude(), sw.longitude()),
17
+ LatLng(sw.latitude(), ne.longitude())
18
+ )
19
+ for (latLng in latLngs) {
20
+ array.pushArray(GeoJSONUtils.fromLatLng(latLng))
21
+ }
22
+ return array
23
+ }
package/docs/MapView.md CHANGED
@@ -118,12 +118,12 @@ this._map.queryRenderedFeaturesAtPoint([30, 40], ['==', 'type', 'Point'], ['id1'
118
118
 
119
119
  ### queryRenderedFeaturesInRect(bbox[, filter][, layerIDs])
120
120
 
121
- Returns an array of rendered map features that intersect with the given rectangle,<br/>restricted to the given style layers and filtered by the given predicate.
121
+ Returns an array of rendered map features that intersect with the given rectangle,<br/>restricted to the given style layers and filtered by the given predicate. In v10,<br/>passing an empty array will query the entire visible bounds of the map.
122
122
 
123
123
  #### arguments
124
124
  | Name | Type | Required | Description |
125
125
  | ---- | :--: | :------: | :----------: |
126
- | `bbox` | `Array` | `Yes` | A rectangle expressed in the map view’s coordinate system. |
126
+ | `bbox` | `Array` | `Yes` | A rectangle expressed in the map view’s coordinate system. For v10, this can be an empty array to query the visible map area. |
127
127
  | `filter` | `Array` | `No` | A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array. |
128
128
  | `layerIDs` | `Array` | `No` | A array of layer id's to filter the features by |
129
129