@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
@@ -5,6 +5,27 @@ import com.facebook.react.views.view.ReactViewGroup
5
5
  import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
6
6
 
7
7
  abstract class AbstractMapFeature(context: Context?) : ReactViewGroup(context) {
8
- abstract fun addToMap(mapView: RCTMGLMapView)
9
- abstract fun removeFromMap(mapView: RCTMGLMapView)
8
+ protected var mMapView: RCTMGLMapView? = null;
9
+ private var mWithMapViewCallbacks: Array<((RCTMGLMapView) -> Unit)>? = null;
10
+
11
+ open fun addToMap(mapView: RCTMGLMapView) {
12
+ mMapView = mapView;
13
+ mWithMapViewCallbacks?.forEach { it(mapView) }
14
+ mWithMapViewCallbacks = null;
15
+ }
16
+
17
+ open fun removeFromMap(mapView: RCTMGLMapView) {
18
+ mMapView = null;
19
+ }
20
+
21
+ internal fun withMapView(callback: (mapView: RCTMGLMapView) -> Unit) {
22
+ val mapView = mMapView;
23
+ if (mapView == null) {
24
+ val callbacks = mWithMapViewCallbacks ?: arrayOf();
25
+ callbacks.plus(callback)
26
+ mWithMapViewCallbacks = callbacks
27
+ } else {
28
+ callback(mapView)
29
+ }
30
+ }
10
31
  }
@@ -23,8 +23,6 @@ class RCTMGLMarkerView(context: Context?, private val mManager: RCTMGLMarkerView
23
23
  View.OnLayoutChangeListener
24
24
  {
25
25
  // region Instance variables
26
-
27
- private var mMapView: RCTMGLMapView? = null
28
26
  private var mView: View? = null
29
27
  private var didAddToMap = false
30
28
 
@@ -72,14 +70,15 @@ class RCTMGLMarkerView(context: Context?, private val mManager: RCTMGLMarkerView
72
70
 
73
71
  // endregion
74
72
 
75
- // region RCTMGLMapComponent methods
73
+ // region AbstractMapFeature methods
76
74
 
77
75
  override fun addToMap(mapView: RCTMGLMapView) {
78
- mMapView = mapView
76
+ super.addToMap(mapView)
79
77
  add()
80
78
  }
81
79
 
82
80
  override fun removeFromMap(mapView: RCTMGLMapView) {
81
+ super.removeFromMap(mapView)
83
82
  remove(mapView)
84
83
  }
85
84
 
@@ -28,7 +28,6 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
28
28
  var marker: PointAnnotation? = null
29
29
  private set
30
30
  private var mMap: MapboxMap? = null
31
- private var mMapView: RCTMGLMapView? = null
32
31
  private val mHasChildren = false
33
32
  private var mCoordinate: Point? = null
34
33
  var iD: String? = null
@@ -74,7 +73,7 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
74
73
  }
75
74
 
76
75
  override fun addToMap(mapView: RCTMGLMapView) {
77
- mMapView = mapView
76
+ super.addToMap(mapView)
78
77
  mMap = mapView.getMapboxMap()
79
78
  makeMarker()
80
79
  if (mChildView != null) {
@@ -103,6 +102,7 @@ class RCTMGLPointAnnotation(private val mContext: Context, private val mManager:
103
102
  if (calloutView != null) {
104
103
  map.offscreenAnnotationViewContainer?.removeView(calloutView)
105
104
  }
105
+ super.removeFromMap(mapView)
106
106
  }
107
107
 
108
108
  override fun onLayoutChange(v: View, left: Int, top: Int, right: Int, bottom: Int, oldLeft: Int, oldTop: Int,
@@ -45,11 +45,12 @@ import com.mapbox.rctmgl.modules.RCTMGLLogging
45
45
  import com.mapbox.rctmgl.utils.LatLng
46
46
  import com.mapbox.rctmgl.utils.Logger
47
47
 
48
+
49
+
48
50
  class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCameraManager) :
49
51
  AbstractMapFeature(
50
52
  mContext
51
53
  ) {
52
- private var mMapView: RCTMGLMapView? = null
53
54
  private var hasSentFirstRegion = false
54
55
  private var mDefaultStop: CameraStop? = null
55
56
  private var mCameraStop: CameraStop? = null
@@ -71,8 +72,8 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
71
72
  private var mFollowZoomLevel : Double? = null
72
73
  private var mFollowHeading : Double? = null
73
74
  private var mZoomLevel = -1.0
74
- private var mMinZoomLevel = -1.0
75
- private var mMaxZoomLevel = -1.0
75
+ private var mMinZoomLevel : Double? = null
76
+ private var mMaxZoomLevel : Double? = null
76
77
  private var mMaxBounds: LatLngBounds? = null
77
78
  private var mFollowUserLocation = false
78
79
  private var mFollowUserMode: String? = null
@@ -117,9 +118,8 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
117
118
  }
118
119
 
119
120
  override fun addToMap(mapView: RCTMGLMapView) {
120
- mMapView = mapView
121
+ super.addToMap(mapView)
121
122
  setInitialCamera()
122
- updateMaxMinZoomLevel()
123
123
  updateMaxBounds()
124
124
  mCameraStop?.let { updateCamera(it) }
125
125
  if (mFollowUserLocation) {
@@ -128,7 +128,9 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
128
128
  }
129
129
  }
130
130
 
131
- override fun removeFromMap(mapView: RCTMGLMapView) {}
131
+ override fun removeFromMap(mapView: RCTMGLMapView) {
132
+ super.removeFromMap(mapView)
133
+ }
132
134
  fun setStop(stop: CameraStop) {
133
135
  mCameraStop = stop
134
136
  mCameraStop!!.setCallback(mCameraCallback)
@@ -161,27 +163,20 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
161
163
  updateMaxBounds()
162
164
  }
163
165
 
164
- private fun updateMaxBounds() {
165
- /*
166
- MapboxMap map = getMapboxMap();
167
- if (map != null && mMaxBounds != null) {
168
- map.setLatLngBoundsForCameraTarget(mMaxBounds);
169
- }
170
166
 
171
- */
172
- }
167
+ private fun updateMaxBounds() {
168
+ withMapView { mapView ->
169
+ val map = mapView.getMapboxMap()
170
+ val maxBounds = mMaxBounds
171
+ val builder = CameraBoundsOptions.Builder()
173
172
 
174
- private fun updateMaxMinZoomLevel() {
175
- /*
176
- MapboxMap map = getMapboxMap();
177
- if (map != null) {
178
- if (mMinZoomLevel >= 0.0) {
179
- map.setMinZoomPreference(mMinZoomLevel);
180
- }
181
- if (mMaxZoomLevel >= 0.0) {
182
- map.setMaxZoomPreference(mMaxZoomLevel);
173
+ if (maxBounds != null) {
174
+ builder.bounds(maxBounds.toBounds())
183
175
  }
184
- }*/
176
+ mMinZoomLevel?.let { builder.minZoom(it) }
177
+ mMaxZoomLevel?.let { builder.maxZoom(it) }
178
+ map.setBounds(builder.build())
179
+ }
185
180
  }
186
181
 
187
182
  private fun setInitialCamera() {
@@ -319,18 +314,18 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
319
314
  });
320
315
  */
321
316
  } else {
322
- mLocationComponentManager!!.setCameraMode(CameraMode.NONE)
317
+ mLocationComponentManager!!.setCameraMode(com.mapbox.rctmgl.components.location.CameraMode.NONE)
323
318
  }
324
319
  }
325
320
 
326
- fun setMinZoomLevel(zoomLevel: Double) {
321
+ fun setMinZoomLevel(zoomLevel: Double?) {
327
322
  mMinZoomLevel = zoomLevel
328
- updateMaxMinZoomLevel()
323
+ updateMaxBounds()
329
324
  }
330
325
 
331
- fun setMaxZoomLevel(zoomLevel: Double) {
326
+ fun setMaxZoomLevel(zoomLevel: Double?) {
332
327
  mMaxZoomLevel = zoomLevel
333
- updateMaxMinZoomLevel()
328
+ updateMaxBounds()
334
329
  }
335
330
 
336
331
  fun setZoomLevel(zoomLevel: Double) {
@@ -1,24 +1,14 @@
1
1
  package com.mapbox.rctmgl.components.camera
2
2
 
3
- import com.mapbox.rctmgl.components.camera.CameraStop.Companion.fromReadableMap
4
- import com.mapbox.maps.MapboxMap
5
- import com.mapbox.maps.CameraOptions
6
- import com.mapbox.maps.plugin.animation.CameraAnimationsPlugin
7
- import android.view.animation.LinearInterpolator
8
- import android.view.animation.AccelerateDecelerateInterpolator
9
- import com.mapbox.rctmgl.components.camera.CameraStop
10
- import com.mapbox.rctmgl.components.camera.CameraUpdateQueue.OnCompleteAllListener
11
- import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
12
- import com.mapbox.rctmgl.components.camera.CameraUpdateItem
13
3
  import com.facebook.react.bridge.ReactApplicationContext
14
- import com.mapbox.rctmgl.components.AbstractEventEmitter
15
- import com.mapbox.rctmgl.components.camera.RCTMGLCamera
16
- import com.mapbox.rctmgl.components.camera.RCTMGLCameraManager
4
+ import com.facebook.react.bridge.ReadableMap
17
5
  import com.facebook.react.uimanager.ThemedReactContext
18
6
  import com.facebook.react.uimanager.annotations.ReactProp
19
- import com.facebook.react.bridge.ReadableMap
20
- import java.lang.AssertionError
21
- import java.util.HashMap
7
+ import com.mapbox.geojson.FeatureCollection
8
+ import com.mapbox.rctmgl.components.AbstractEventEmitter
9
+ import com.mapbox.rctmgl.components.camera.CameraStop.Companion.fromReadableMap
10
+ import com.mapbox.rctmgl.utils.GeoJSONUtils.toLatLngBounds
11
+
22
12
 
23
13
  //import com.mapbox.rctmgl.utils.GeoJSONUtils;
24
14
  class RCTMGLCameraManager(private val mContext: ReactApplicationContext) :
@@ -53,15 +43,6 @@ class RCTMGLCameraManager(private val mContext: ReactApplicationContext) :
53
43
  }
54
44
  }
55
45
 
56
- /*v10todo
57
- @ReactProp(name="maxBounds")
58
- public void setMaxBounds(RCTMGLCamera camera, String value) {
59
- if (value != null) {
60
- FeatureCollection collection = FeatureCollection.fromJson(value);
61
- camera.setMaxBounds(GeoJSONUtils.toLatLngBounds(collection));
62
- }
63
- }
64
- */
65
46
  @ReactProp(name = "userTrackingMode")
66
47
  fun setUserTrackingMode(camera: RCTMGLCamera, userTrackingMode: Int) {
67
48
  camera.setUserTrackingMode(userTrackingMode)
@@ -108,6 +89,16 @@ class RCTMGLCameraManager(private val mContext: ReactApplicationContext) :
108
89
  camera.setFollowZoomLevel(value)
109
90
  }
110
91
 
92
+ @ReactProp(name = "maxBounds")
93
+ fun setMaxBounds(camera: RCTMGLCamera, value: String?) {
94
+ if (value != null) {
95
+ val collection = FeatureCollection.fromJson(value)
96
+ camera.setMaxBounds(toLatLngBounds(collection))
97
+ } else {
98
+ camera.setMaxBounds(null)
99
+ }
100
+ }
101
+
111
102
  companion object {
112
103
  const val REACT_CLASS = "RCTMGLCamera"
113
104
  }
@@ -82,6 +82,7 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
82
82
  mNativeImages = HashMap()
83
83
  mImages = HashMap()
84
84
  mCurrentImages = HashSet()
85
+ super.removeFromMap(mapView)
85
86
  }
86
87
 
87
88
  private fun removeImages(mapView: RCTMGLMapView) {
@@ -151,6 +152,7 @@ class RCTMGLImages(context: Context, private val mManager: RCTMGLImagesManager)
151
152
  }
152
153
 
153
154
  override fun addToMap(mapView: RCTMGLMapView) {
155
+ super.addToMap(mapView)
154
156
  // Wait for style before adding the source to the map
155
157
  // only then we can pre-load required images / placeholders into the style
156
158
  // before we add the ShapeSource to the map
@@ -17,13 +17,12 @@ import com.mapbox.mapboxsdk.maps.Style;
17
17
  */ class RCTMGLNativeUserLocation(context: Context?) : AbstractMapFeature(context), OnMapReadyCallback, Style.OnStyleLoaded {
18
18
  private var mEnabled = true
19
19
  private var mMap: MapboxMap? = null
20
- private var mMapView: RCTMGLMapView? = null
21
20
 
22
21
  @RenderMode.Mode
23
22
  private var mRenderMode = RenderMode.COMPASS
24
23
  override fun addToMap(mapView: RCTMGLMapView) {
24
+ super.addToMap(mapView)
25
25
  mEnabled = true
26
- mMapView = mapView
27
26
  mapView.getMapboxMap()
28
27
  mapView.getMapAsync(this)
29
28
  setRenderMode(mRenderMode)
@@ -32,6 +31,7 @@ import com.mapbox.mapboxsdk.maps.Style;
32
31
  override fun removeFromMap(mapView: RCTMGLMapView) {
33
32
  mEnabled = false
34
33
  mMap?.getStyle(this)
34
+ super.removeFromMap(mapView)
35
35
  }
36
36
 
37
37
  @SuppressLint("MissingPermission")