@rnmapbox/maps 10.0.0-beta.46 → 10.0.0-beta.47
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.
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/AbstractMapFeature.kt +23 -2
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerView.kt +3 -4
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLPointAnnotation.kt +2 -2
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCamera.kt +19 -10
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCameraManager.kt +16 -25
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt +2 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/RCTMGLNativeUserLocation.kt +2 -2
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +217 -69
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapViewManager.kt +22 -2
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/atmosphere/RCTMGLAtmosphere.kt +2 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTLayer.kt +2 -2
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTMGLShapeSource.kt +4 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTSource.kt +2 -3
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/terrain/RCTMGLTerrain.kt +2 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/LatLngBounds.kt +35 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/CoordinateBounds.kt +23 -0
- package/docs/docs.json +2 -2
- package/ios/RCTMGL-v10/RCTMGLCamera.swift +37 -2
- package/ios/RCTMGL-v10/RCTMGLCameraManager.m +1 -0
- package/ios/RCTMGL-v10/RCTMGLShapeSource.swift +29 -23
- package/ios/RCTMGL-v10/RCTMGLShapeSourceManager.m +3 -3
- package/ios/RCTMGL-v10/RCTMGLShapeSourceManager.swift +3 -3
- package/javascript/components/MarkerView.tsx +15 -1
- package/javascript/components/ShapeSource.tsx +3 -3
- package/package.json +1 -1
- 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
|
-
|
|
9
|
-
|
|
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
|
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerView.kt
CHANGED
|
@@ -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
|
|
73
|
+
// region AbstractMapFeature methods
|
|
76
74
|
|
|
77
75
|
override fun addToMap(mapView: RCTMGLMapView) {
|
|
78
|
-
|
|
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
|
-
|
|
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,
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCamera.kt
CHANGED
|
@@ -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
|
|
@@ -117,7 +118,7 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
|
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
override fun addToMap(mapView: RCTMGLMapView) {
|
|
120
|
-
|
|
121
|
+
super.addToMap(mapView)
|
|
121
122
|
setInitialCamera()
|
|
122
123
|
updateMaxMinZoomLevel()
|
|
123
124
|
updateMaxBounds()
|
|
@@ -128,7 +129,9 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
|
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
override fun removeFromMap(mapView: RCTMGLMapView) {
|
|
132
|
+
override fun removeFromMap(mapView: RCTMGLMapView) {
|
|
133
|
+
super.removeFromMap(mapView)
|
|
134
|
+
}
|
|
132
135
|
fun setStop(stop: CameraStop) {
|
|
133
136
|
mCameraStop = stop
|
|
134
137
|
mCameraStop!!.setCallback(mCameraCallback)
|
|
@@ -161,14 +164,20 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
|
|
|
161
164
|
updateMaxBounds()
|
|
162
165
|
}
|
|
163
166
|
|
|
167
|
+
|
|
164
168
|
private fun updateMaxBounds() {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
169
|
+
withMapView { mapView ->
|
|
170
|
+
val map = mapView.getMapboxMap()
|
|
171
|
+
val maxBounds = mMaxBounds
|
|
172
|
+
if (maxBounds != null) {
|
|
173
|
+
map.setBounds(CameraBoundsOptions.Builder().bounds(
|
|
174
|
+
maxBounds.toBounds()
|
|
175
|
+
).build())
|
|
176
|
+
} else {
|
|
177
|
+
map.setBounds(CameraBoundsOptions.Builder().build())
|
|
178
|
+
}
|
|
170
179
|
|
|
171
|
-
|
|
180
|
+
}
|
|
172
181
|
}
|
|
173
182
|
|
|
174
183
|
private fun updateMaxMinZoomLevel() {
|
|
@@ -319,7 +328,7 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
|
|
|
319
328
|
});
|
|
320
329
|
*/
|
|
321
330
|
} else {
|
|
322
|
-
mLocationComponentManager!!.setCameraMode(CameraMode.NONE)
|
|
331
|
+
mLocationComponentManager!!.setCameraMode(com.mapbox.rctmgl.components.location.CameraMode.NONE)
|
|
323
332
|
}
|
|
324
333
|
}
|
|
325
334
|
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCameraManager.kt
CHANGED
|
@@ -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.
|
|
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.
|
|
20
|
-
import
|
|
21
|
-
import
|
|
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
|
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt
CHANGED
|
@@ -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")
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt
CHANGED
|
@@ -33,11 +33,14 @@ import com.mapbox.maps.plugin.annotation.generated.PointAnnotationManager
|
|
|
33
33
|
import com.mapbox.maps.plugin.annotation.generated.createPointAnnotationManager
|
|
34
34
|
import com.mapbox.maps.plugin.attribution.attribution
|
|
35
35
|
import com.mapbox.maps.plugin.attribution.generated.AttributionSettings
|
|
36
|
+
import com.mapbox.maps.plugin.scalebar.scalebar
|
|
36
37
|
import com.mapbox.maps.plugin.compass.compass
|
|
38
|
+
import com.mapbox.maps.plugin.compass.generated.CompassSettings
|
|
37
39
|
import com.mapbox.maps.plugin.delegates.listeners.*
|
|
38
40
|
import com.mapbox.maps.plugin.gestures.*
|
|
39
41
|
import com.mapbox.maps.plugin.logo.generated.LogoSettings
|
|
40
42
|
import com.mapbox.maps.plugin.logo.logo
|
|
43
|
+
import com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettings
|
|
41
44
|
import com.mapbox.maps.viewannotation.ViewAnnotationManager
|
|
42
45
|
import com.mapbox.rctmgl.R
|
|
43
46
|
import com.mapbox.rctmgl.components.AbstractMapFeature
|
|
@@ -65,6 +68,12 @@ import org.json.JSONException
|
|
|
65
68
|
import org.json.JSONObject
|
|
66
69
|
import java.util.*
|
|
67
70
|
|
|
71
|
+
data class OrnamentSettings(
|
|
72
|
+
var enabled : Boolean? = false,
|
|
73
|
+
var margins: ReadableMap? =null,
|
|
74
|
+
var position: Int = -1
|
|
75
|
+
)
|
|
76
|
+
|
|
68
77
|
|
|
69
78
|
interface RCTMGLMapViewLifecycleOwner : LifecycleOwner {
|
|
70
79
|
fun handleLifecycleEvent(event: Lifecycle.Event)
|
|
@@ -608,7 +617,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
608
617
|
properties.putBoolean("isUserInteraction", mCameraChangeTracker.isUserInteraction)
|
|
609
618
|
try {
|
|
610
619
|
val bounds = mMap.coordinateBoundsForCamera(position.toCameraOptions())
|
|
611
|
-
properties.putArray("visibleBounds",
|
|
620
|
+
properties.putArray("visibleBounds", bounds.toReadableArray())
|
|
612
621
|
} catch (ex: Exception) {
|
|
613
622
|
Logger.e(LOG_TAG, "An error occurred while attempting to make the region", ex)
|
|
614
623
|
}
|
|
@@ -760,7 +769,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
760
769
|
val bounds = mMap!!.coordinateBoundsForCamera(mMap!!.cameraState.toCameraOptions())
|
|
761
770
|
|
|
762
771
|
sendResponse(callbackID, {
|
|
763
|
-
it.putArray("visibleBounds",
|
|
772
|
+
it.putArray("visibleBounds", bounds.toReadableArray())
|
|
764
773
|
})
|
|
765
774
|
}
|
|
766
775
|
|
|
@@ -858,12 +867,12 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
858
867
|
|
|
859
868
|
// region Ornaments
|
|
860
869
|
|
|
861
|
-
fun toGravity(kind: String, viewPosition: Int): Int {
|
|
870
|
+
private fun toGravity(kind: String, viewPosition: Int): Int {
|
|
862
871
|
return when (viewPosition) {
|
|
863
|
-
0 -> (Gravity.TOP or Gravity.
|
|
864
|
-
1 -> (Gravity.
|
|
865
|
-
2 -> (Gravity.
|
|
866
|
-
3 -> (Gravity.BOTTOM or Gravity.
|
|
872
|
+
0 -> (Gravity.TOP or Gravity.LEFT)
|
|
873
|
+
1 -> (Gravity.BOTTOM or Gravity.LEFT)
|
|
874
|
+
2 -> (Gravity.TOP or Gravity.RIGHT)
|
|
875
|
+
3 -> (Gravity.BOTTOM or Gravity.RIGHT)
|
|
867
876
|
else -> {
|
|
868
877
|
Logger.e(
|
|
869
878
|
"MapView",
|
|
@@ -874,13 +883,46 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
874
883
|
}
|
|
875
884
|
}
|
|
876
885
|
|
|
877
|
-
|
|
886
|
+
private fun updateOrnament(kind: String, from: OrnamentSettings, to: GenericOrnamentSettings) {
|
|
887
|
+
from.enabled?.let { to.enabled = it }
|
|
888
|
+
if (from.position >= 0) {
|
|
889
|
+
to.position = toGravity(kind, from.position)
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
from.margins?.let {
|
|
893
|
+
val pixelDensity = resources.displayMetrics.density
|
|
894
|
+
val x: Int? = it.getDouble("x")?.let { (it * pixelDensity).toInt() }
|
|
895
|
+
val y: Int? = it.getDouble("y")?.let { (it * pixelDensity).toInt() }
|
|
896
|
+
|
|
897
|
+
val horizontalGravity = to.position and Gravity.HORIZONTAL_GRAVITY_MASK
|
|
898
|
+
val verticalGravity = to.position and Gravity.VERTICAL_GRAVITY_MASK
|
|
899
|
+
|
|
900
|
+
when (horizontalGravity) {
|
|
901
|
+
Gravity.LEFT -> { to.setHMargins(x?.toFloat(), 0f) }
|
|
902
|
+
Gravity.RIGHT -> { to.setHMargins(0f, x?.toFloat()) }
|
|
903
|
+
Gravity.CENTER_HORIZONTAL ->{ to.setHMargins(x?.toFloat(), x?.toFloat()) }
|
|
904
|
+
else -> Logger.e(
|
|
905
|
+
"MapView",
|
|
906
|
+
"${kind}ViewMargins: unexpected absolute pos: $horizontalGravity"
|
|
907
|
+
)
|
|
908
|
+
}
|
|
909
|
+
when (verticalGravity) {
|
|
910
|
+
Gravity.TOP -> { to.setVMargins(y?.toFloat(), 0f) }
|
|
911
|
+
Gravity.BOTTOM -> { to.setVMargins(0f, y?.toFloat()) }
|
|
912
|
+
Gravity.CENTER_VERTICAL -> { to.setVMargins(y?.toFloat(), y?.toFloat()) }
|
|
913
|
+
else -> Logger.e(
|
|
914
|
+
"MapView",
|
|
915
|
+
"${kind}ViewMargins: unexpected vertical pos: $verticalGravity"
|
|
916
|
+
)
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
var mCompassSettings = OrnamentSettings(enabled = false)
|
|
878
922
|
var mCompassFadeWhenNorth = false
|
|
879
|
-
var mCompassViewMargins: ReadableMap? = null
|
|
880
|
-
var mCompassViewPosition: Int = -1
|
|
881
923
|
|
|
882
924
|
fun setReactCompassEnabled(compassEnabled: Boolean) {
|
|
883
|
-
|
|
925
|
+
mCompassSettings.enabled = compassEnabled
|
|
884
926
|
updateCompass()
|
|
885
927
|
}
|
|
886
928
|
|
|
@@ -890,82 +932,55 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
890
932
|
}
|
|
891
933
|
|
|
892
934
|
fun setReactCompassViewMargins(compassViewMargins: ReadableMap) {
|
|
893
|
-
|
|
935
|
+
mCompassSettings.margins = compassViewMargins
|
|
894
936
|
updateCompass()
|
|
895
937
|
}
|
|
896
938
|
|
|
897
939
|
fun setReactCompassViewPosition(compassViewPosition: Int) {
|
|
898
|
-
|
|
940
|
+
mCompassSettings.position = compassViewPosition
|
|
899
941
|
updateCompass()
|
|
900
942
|
}
|
|
901
943
|
|
|
902
|
-
fun
|
|
903
|
-
|
|
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
|
|
944
|
+
fun setReactCompassPosition(compassPosition: ReadableMap) {
|
|
945
|
+
mCompassSettings.setPosAndMargins(compassPosition)
|
|
926
946
|
updateCompass()
|
|
927
947
|
}
|
|
928
948
|
|
|
929
949
|
private fun updateCompass() {
|
|
930
950
|
compass.updateSettings {
|
|
931
|
-
enabled = mCompassEnabled
|
|
932
951
|
fadeWhenFacingNorth = mCompassFadeWhenNorth
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
952
|
+
updateOrnament("compass", mCompassSettings, this.toGenericOrnamentSettings())
|
|
953
|
+
}
|
|
954
|
+
}
|
|
936
955
|
|
|
937
|
-
|
|
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
|
|
956
|
+
var mScaleBarSettings = OrnamentSettings(enabled = false)
|
|
942
957
|
|
|
943
|
-
|
|
944
|
-
|
|
958
|
+
fun setReactScaleBarEnabled(scaleBarEnabled: Boolean) {
|
|
959
|
+
mScaleBarSettings.enabled = scaleBarEnabled
|
|
960
|
+
updateScaleBar()
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
fun setReactScaleBarViewMargins(scaleBarMargins: ReadableMap) {
|
|
964
|
+
mScaleBarSettings.margins = scaleBarMargins
|
|
965
|
+
updateScaleBar()
|
|
966
|
+
}
|
|
945
967
|
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
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
|
-
}
|
|
968
|
+
fun setReactScaleBarViewPosition(scaleBarPosition: Int) {
|
|
969
|
+
mScaleBarSettings.position = scaleBarPosition
|
|
970
|
+
updateScaleBar()
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
fun setReactScaleBarPosition(scaleBarPosition: ReadableMap) {
|
|
974
|
+
mScaleBarSettings.setPosAndMargins(scaleBarPosition)
|
|
975
|
+
updateScaleBar()
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
private fun updateScaleBar() {
|
|
979
|
+
scalebar.updateSettings {
|
|
980
|
+
updateOrnament("scaleBar", mScaleBarSettings, this.toGenericOrnamentSettings())
|
|
967
981
|
}
|
|
968
982
|
}
|
|
983
|
+
|
|
969
984
|
// endregion
|
|
970
985
|
|
|
971
986
|
private fun getGravityAndMargin (position:ReadableMap): Pair<Int, IntArray> {
|
|
@@ -1043,6 +1058,44 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1043
1058
|
private var mLogoGravity: Int? = null
|
|
1044
1059
|
private var mLogoMargin: IntArray? = null
|
|
1045
1060
|
|
|
1061
|
+
var mLogoSettings = OrnamentSettings(enabled = null)
|
|
1062
|
+
|
|
1063
|
+
fun setReactLogoEnabled(enabled: Boolean?) {
|
|
1064
|
+
mLogoSettings.enabled = enabled
|
|
1065
|
+
updateLogo()
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
fun setReactLogoMargins(margins: ReadableMap) {
|
|
1069
|
+
mLogoSettings.margins = margins
|
|
1070
|
+
updateLogo()
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
fun setReactLogoViewPosition(position: Int) {
|
|
1074
|
+
mLogoSettings.position = position
|
|
1075
|
+
updateLogo()
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
fun setReactLogoPosition(position: ReadableMap?) {
|
|
1079
|
+
mLogoSettings.setPosAndMargins(position)
|
|
1080
|
+
updateLogo()
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
private fun updateLogo() {
|
|
1084
|
+
logo.updateSettings {
|
|
1085
|
+
updateOrnament("logo", mLogoSettings, this.toGenericOrnamentSettings())
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
logo.updateSettings {
|
|
1089
|
+
println(String.format("logo :: position - before 0x%08x", position))
|
|
1090
|
+
//position = Gravity.BOTTOM or Gravity.RIGHT
|
|
1091
|
+
println(String.format("eq bottom|right %b", position == (Gravity.BOTTOM or Gravity.RIGHT)))
|
|
1092
|
+
if (position == Gravity.BOTTOM or Gravity.RIGHT) {
|
|
1093
|
+
position = Gravity.BOTTOM or Gravity.RIGHT
|
|
1094
|
+
}
|
|
1095
|
+
println(String.format("logo :: position - after 0x%08x", position))
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
/*
|
|
1046
1099
|
fun setReactLogoEnabled(logoEnabled: Boolean?) {
|
|
1047
1100
|
mLogoEnabled = logoEnabled ?: LogoSettings().enabled
|
|
1048
1101
|
updateLogo()
|
|
@@ -1081,6 +1134,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1081
1134
|
}
|
|
1082
1135
|
}
|
|
1083
1136
|
}
|
|
1137
|
+
*/
|
|
1084
1138
|
// endregion
|
|
1085
1139
|
|
|
1086
1140
|
// region lifecycle
|
|
@@ -1128,3 +1182,97 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1128
1182
|
|
|
1129
1183
|
// endregion
|
|
1130
1184
|
}
|
|
1185
|
+
|
|
1186
|
+
fun OrnamentSettings.setPosAndMargins(posAndMargins: ReadableMap?) {
|
|
1187
|
+
if (posAndMargins == null) { return }
|
|
1188
|
+
|
|
1189
|
+
val bottom_mask = 1;
|
|
1190
|
+
val right_mask = 2;
|
|
1191
|
+
|
|
1192
|
+
var margins = WritableNativeMap()
|
|
1193
|
+
var position = 0;
|
|
1194
|
+
if (posAndMargins
|
|
1195
|
+
.hasKey("bottom")) {
|
|
1196
|
+
margins.putInt("y", posAndMargins.getInt("bottom"))
|
|
1197
|
+
position = position or bottom_mask
|
|
1198
|
+
} else {
|
|
1199
|
+
if (posAndMargins.hasKey("top")) {
|
|
1200
|
+
margins.putInt("y", posAndMargins.getInt("top"))
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
if (posAndMargins.hasKey("left")) {
|
|
1205
|
+
margins.putInt("x", posAndMargins.getInt("left"))
|
|
1206
|
+
} else {
|
|
1207
|
+
if (posAndMargins.hasKey("right")) {
|
|
1208
|
+
position = position or right_mask
|
|
1209
|
+
margins.putInt("x", posAndMargins.getInt("right"))
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
this.position = position
|
|
1213
|
+
this.margins = margins
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
interface GenericOrnamentSettings {
|
|
1217
|
+
fun setHMargins(left: Float?, right: Float?)
|
|
1218
|
+
fun setVMargins(top: Float?, bottom: Float?)
|
|
1219
|
+
var enabled: Boolean
|
|
1220
|
+
var position: Int
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
fun ScaleBarSettings.toGenericOrnamentSettings() = object : GenericOrnamentSettings {
|
|
1224
|
+
private val settings = this@toGenericOrnamentSettings
|
|
1225
|
+
override fun setHMargins(left: Float?, right: Float?) {
|
|
1226
|
+
left?.let { settings.marginLeft = it }
|
|
1227
|
+
right?.let { settings.marginRight = it }
|
|
1228
|
+
}
|
|
1229
|
+
override fun setVMargins(top: Float?, bottom: Float?) {
|
|
1230
|
+
top?.let { settings.marginTop = it }
|
|
1231
|
+
bottom?.let { settings.marginBottom = it }
|
|
1232
|
+
}
|
|
1233
|
+
override var enabled: Boolean
|
|
1234
|
+
get() = settings.enabled
|
|
1235
|
+
set(value) { settings.enabled = value }
|
|
1236
|
+
override var position: Int
|
|
1237
|
+
get() = settings.position
|
|
1238
|
+
set(value) { settings.position = value }
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
fun CompassSettings.toGenericOrnamentSettings() = object : GenericOrnamentSettings {
|
|
1242
|
+
private val settings = this@toGenericOrnamentSettings
|
|
1243
|
+
override fun setHMargins(left: Float?, right: Float?) {
|
|
1244
|
+
left?.let { settings.marginLeft = it }
|
|
1245
|
+
right?.let { settings.marginRight = it }
|
|
1246
|
+
}
|
|
1247
|
+
override fun setVMargins(top: Float?, bottom: Float?) {
|
|
1248
|
+
top?.let { settings.marginTop = it }
|
|
1249
|
+
bottom?.let { settings.marginBottom = it }
|
|
1250
|
+
}
|
|
1251
|
+
override var enabled: Boolean
|
|
1252
|
+
get() = settings.enabled
|
|
1253
|
+
set(value) { settings.enabled = value }
|
|
1254
|
+
override var position: Int
|
|
1255
|
+
get() = settings.position
|
|
1256
|
+
set(value) { settings.position = value }
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
fun LogoSettings.toGenericOrnamentSettings() = object : GenericOrnamentSettings {
|
|
1260
|
+
private val settings = this@toGenericOrnamentSettings
|
|
1261
|
+
override fun setHMargins(left: Float?, right: Float?) {
|
|
1262
|
+
left?.let { settings.marginLeft = it }
|
|
1263
|
+
right?.let { settings.marginRight = it }
|
|
1264
|
+
}
|
|
1265
|
+
override fun setVMargins(top: Float?, bottom: Float?) {
|
|
1266
|
+
top?.let { settings.marginTop = it }
|
|
1267
|
+
bottom?.let { settings.marginBottom = it }
|
|
1268
|
+
}
|
|
1269
|
+
override var enabled: Boolean
|
|
1270
|
+
get() = settings.enabled
|
|
1271
|
+
set(value) { settings.enabled = value }
|
|
1272
|
+
override var position: Int
|
|
1273
|
+
get() = settings.position
|
|
1274
|
+
set(value) {
|
|
1275
|
+
println(String.format("logo :: position: 0x%08x", value))
|
|
1276
|
+
settings.position = value
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
@@ -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
|
|
161
|
-
mapView!!.
|
|
180
|
+
fun setCompassPosition(mapView: RCTMGLMapView?, compassMargins: ReadableMap) {
|
|
181
|
+
mapView!!.setReactCompassPosition(compassMargins)
|
|
162
182
|
}
|
|
163
183
|
|
|
164
184
|
@ReactProp(name = "contentInset")
|
|
@@ -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 {
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTLayer.kt
CHANGED
|
@@ -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>) {
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTSource.kt
CHANGED
|
@@ -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
|
-
|
|
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 {
|
|
@@ -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
|
+
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/CoordinateBounds.kt
ADDED
|
@@ -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/docs.json
CHANGED
|
@@ -3939,10 +3939,10 @@
|
|
|
3939
3939
|
"name": "Promise",
|
|
3940
3940
|
"elements": [
|
|
3941
3941
|
{
|
|
3942
|
-
"name": "
|
|
3942
|
+
"name": "number"
|
|
3943
3943
|
}
|
|
3944
3944
|
],
|
|
3945
|
-
"raw": "Promise<
|
|
3945
|
+
"raw": "Promise<number>"
|
|
3946
3946
|
}
|
|
3947
3947
|
},
|
|
3948
3948
|
"description": "Returns the zoom needed to expand the cluster.",
|
|
@@ -108,7 +108,8 @@ class RCTMGLCamera : RCTMGLMapComponentBase, LocationConsumer {
|
|
|
108
108
|
var cameraAnimator: BasicCameraAnimator?
|
|
109
109
|
let cameraUpdateQueue = CameraUpdateQueue()
|
|
110
110
|
|
|
111
|
-
//
|
|
111
|
+
// MARK: React properties
|
|
112
|
+
|
|
112
113
|
@objc var animationDuration: NSNumber?
|
|
113
114
|
@objc var animationMode: NSString?
|
|
114
115
|
@objc var defaultStop: [String: Any]?
|
|
@@ -145,8 +146,19 @@ class RCTMGLCamera : RCTMGLMapComponentBase, LocationConsumer {
|
|
|
145
146
|
_updateCamera()
|
|
146
147
|
}
|
|
147
148
|
}
|
|
149
|
+
|
|
150
|
+
@objc var maxBounds: String? {
|
|
151
|
+
didSet {
|
|
152
|
+
if let maxBounds = maxBounds {
|
|
153
|
+
logged("RCTMGLCamera.maxBounds") {
|
|
154
|
+
let maxBoundsFeature = try JSONDecoder().decode(FeatureCollection.self, from: maxBounds.data(using: .utf8)!)
|
|
155
|
+
try _updateMaxBounds(maxBoundsFeature)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
148
160
|
|
|
149
|
-
// Update methods
|
|
161
|
+
// MARK: Update methods
|
|
150
162
|
|
|
151
163
|
func _updateCameraFromJavascript() {
|
|
152
164
|
guard !followUserLocation else {
|
|
@@ -185,6 +197,29 @@ class RCTMGLCamera : RCTMGLMapComponentBase, LocationConsumer {
|
|
|
185
197
|
map.viewport.idle()
|
|
186
198
|
map.location.removeLocationConsumer(consumer: self)
|
|
187
199
|
}
|
|
200
|
+
|
|
201
|
+
func _toCoordinateBounds(_ bounds: FeatureCollection) throws -> CoordinateBounds {
|
|
202
|
+
guard bounds.features.count == 2 else {
|
|
203
|
+
throw RCTMGLError.paramError("Expected two Points in FeatureColletion")
|
|
204
|
+
}
|
|
205
|
+
let swFeature = bounds.features[0]
|
|
206
|
+
let neFeature = bounds.features[1]
|
|
207
|
+
|
|
208
|
+
guard case let .point(sw) = swFeature.geometry,
|
|
209
|
+
case let .point(ne) = neFeature.geometry else {
|
|
210
|
+
throw RCTMGLError.paramError("Expected two Points in FeatureColletion")
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return CoordinateBounds(southwest: sw.coordinates, northeast: ne.coordinates)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
func _updateMaxBounds(_ bounds: FeatureCollection) throws {
|
|
217
|
+
withMapView { map in
|
|
218
|
+
logged("RCTMGLCamera._updateMaxBounds") {
|
|
219
|
+
try map.mapboxMap.setCameraBounds(with: CameraBoundsOptions(bounds: try self._toCoordinateBounds(bounds)))
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
188
223
|
|
|
189
224
|
func _updateCameraFromTrackingMode() {
|
|
190
225
|
withMapView { map in
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
@interface RCT_EXTERN_MODULE(RCTMGLCameraManager, RCTViewManager)
|
|
6
6
|
|
|
7
|
+
RCT_EXPORT_VIEW_PROPERTY(maxBounds, NSString)
|
|
7
8
|
RCT_EXPORT_VIEW_PROPERTY(animationDuration, NSNumber)
|
|
8
9
|
RCT_EXPORT_VIEW_PROPERTY(animationMode, NSString)
|
|
9
10
|
RCT_EXPORT_VIEW_PROPERTY(defaultStop, NSDictionary)
|
|
@@ -21,7 +21,19 @@ class RCTMGLShapeSource : RCTMGLSource {
|
|
|
21
21
|
|
|
22
22
|
@objc var cluster : NSNumber?
|
|
23
23
|
@objc var clusterRadius : NSNumber?
|
|
24
|
-
@objc var clusterMaxZoomLevel : NSNumber?
|
|
24
|
+
@objc var clusterMaxZoomLevel : NSNumber? {
|
|
25
|
+
didSet {
|
|
26
|
+
logged("RCTMGLShapeSource.clusterMaxZoomLevel") {
|
|
27
|
+
if let number = clusterMaxZoomLevel?.doubleValue {
|
|
28
|
+
doUpdate { (style) in
|
|
29
|
+
logged("RCTMGLShapeSource.doUpdate") {
|
|
30
|
+
try style.setSourceProperty(for: id, property: "clusterMaxZoom", value: number)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
25
37
|
@objc var clusterProperties : [String: [Any]]?;
|
|
26
38
|
|
|
27
39
|
@objc var maxZoomLevel : NSNumber?
|
|
@@ -192,7 +204,7 @@ extension RCTMGLShapeSource
|
|
|
192
204
|
extension RCTMGLShapeSource
|
|
193
205
|
{
|
|
194
206
|
func getClusterExpansionZoom(
|
|
195
|
-
_
|
|
207
|
+
_ featureJSON: String,
|
|
196
208
|
completion: @escaping (Result<Int, Error>) -> Void)
|
|
197
209
|
{
|
|
198
210
|
guard let mapView = map?.mapView else {
|
|
@@ -200,29 +212,23 @@ extension RCTMGLShapeSource
|
|
|
200
212
|
return
|
|
201
213
|
}
|
|
202
214
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
let
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
guard let value = features.value as? NSNumber else {
|
|
215
|
-
completion(.failure(RCTMGLError.failed("getClusterExpansionZoom: not a number")))
|
|
216
|
-
return
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
completion(.success(value.intValue))
|
|
220
|
-
case .failure(let error):
|
|
221
|
-
completion(.failure(error))
|
|
215
|
+
logged("RCTMGLShapeSource.getClusterExpansionZoom", rejecter: { (_,_,error) in
|
|
216
|
+
completion(.failure(error!))
|
|
217
|
+
}) {
|
|
218
|
+
let cluster : Feature = try parse(featureJSON);
|
|
219
|
+
|
|
220
|
+
mapView.mapboxMap.queryFeatureExtension(for: self.id, feature: cluster, extension: "supercluster", extensionField: "expansion-zoom") { result in
|
|
221
|
+
switch result {
|
|
222
|
+
case .success(let features):
|
|
223
|
+
guard let value = features.value as? NSNumber else {
|
|
224
|
+
completion(.failure(RCTMGLError.failed("getClusterExpansionZoom: not a number")))
|
|
225
|
+
return
|
|
222
226
|
}
|
|
227
|
+
|
|
228
|
+
completion(.success(value.intValue))
|
|
229
|
+
case .failure(let error):
|
|
230
|
+
completion(.failure(error))
|
|
223
231
|
}
|
|
224
|
-
case .failure(let error):
|
|
225
|
-
completion(.failure(error))
|
|
226
232
|
}
|
|
227
233
|
}
|
|
228
234
|
}
|
|
@@ -25,9 +25,9 @@ RCT_REMAP_VIEW_PROPERTY(onMapboxShapeSourcePress, onPress, RCTBubblingEventBlock
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
RCT_EXTERN_METHOD(getClusterExpansionZoom:(nonnull NSNumber*)reactTag
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
featureJSON:(nonnull NSString*)featureJSON
|
|
29
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
30
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
31
31
|
|
|
32
32
|
RCT_EXTERN_METHOD(getClusterLeaves:(nonnull NSNumber*)reactTag
|
|
33
33
|
featureJSON:(nonnull NSString*)featureJSON
|
|
@@ -38,12 +38,12 @@ extension RCTMGLShapeSourceManager {
|
|
|
38
38
|
extension RCTMGLShapeSourceManager {
|
|
39
39
|
@objc func getClusterExpansionZoom(
|
|
40
40
|
_ reactTag: NSNumber,
|
|
41
|
-
|
|
41
|
+
featureJSON: String,
|
|
42
42
|
resolver: @escaping RCTPromiseResolveBlock,
|
|
43
43
|
rejecter: @escaping RCTPromiseRejectBlock) -> Void
|
|
44
44
|
{
|
|
45
|
-
self.withShapeSource(reactTag, name:"
|
|
46
|
-
shapeSource.getClusterExpansionZoom(
|
|
45
|
+
self.withShapeSource(reactTag, name:"getCluster ExpansionZoom", rejecter: rejecter) { shapeSource in
|
|
46
|
+
shapeSource.getClusterExpansionZoom(featureJSON) { result in
|
|
47
47
|
switch result {
|
|
48
48
|
case .success(let zoom):
|
|
49
49
|
resolver([
|
|
@@ -119,8 +119,22 @@ class MarkerView extends React.PureComponent<Props> {
|
|
|
119
119
|
anchor={anchor}
|
|
120
120
|
allowOverlap={this.props.allowOverlap}
|
|
121
121
|
isSelected={this.props.isSelected}
|
|
122
|
+
onTouchEnd={(e) => {
|
|
123
|
+
console.log('e => ');
|
|
124
|
+
e.stopPropagation();
|
|
125
|
+
}}
|
|
122
126
|
>
|
|
123
|
-
<View
|
|
127
|
+
<View
|
|
128
|
+
style={{ flex: 0, alignSelf: 'flex-start' }}
|
|
129
|
+
onStartShouldSetResponder={(_event) => {
|
|
130
|
+
console.log('+> onStart');
|
|
131
|
+
return true;
|
|
132
|
+
}}
|
|
133
|
+
onTouchEnd={(e) => {
|
|
134
|
+
console.log('e => ');
|
|
135
|
+
e.stopPropagation();
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
124
138
|
{this.props.children}
|
|
125
139
|
</View>
|
|
126
140
|
</RCTMGLMarkerView>
|
|
@@ -210,12 +210,12 @@ export class ShapeSource extends NativeBridgeComponent(
|
|
|
210
210
|
*/
|
|
211
211
|
async getClusterExpansionZoom(
|
|
212
212
|
feature: string | GeoJSON.Feature,
|
|
213
|
-
): Promise<
|
|
213
|
+
): Promise<number> {
|
|
214
214
|
if (typeof feature === 'number') {
|
|
215
215
|
console.warn(
|
|
216
216
|
'Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.',
|
|
217
217
|
);
|
|
218
|
-
const res: { data:
|
|
218
|
+
const res: { data: number } = await this._runNativeCommand(
|
|
219
219
|
'getClusterExpansionZoomById',
|
|
220
220
|
this._nativeRef,
|
|
221
221
|
[feature],
|
|
@@ -223,7 +223,7 @@ export class ShapeSource extends NativeBridgeComponent(
|
|
|
223
223
|
return res.data;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
const res: { data:
|
|
226
|
+
const res: { data: number } = await this._runNativeCommand(
|
|
227
227
|
'getClusterExpansionZoom',
|
|
228
228
|
this._nativeRef,
|
|
229
229
|
[JSON.stringify(feature)],
|
package/package.json
CHANGED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
package com.mapbox.rctmgl.utils;
|
|
2
|
-
|
|
3
|
-
import com.mapbox.geojson.Point;
|
|
4
|
-
import com.mapbox.maps.CoordinateBounds;
|
|
5
|
-
|
|
6
|
-
public class LatLngBounds {
|
|
7
|
-
public static LatLngBounds from(double bbox, double bbox1, double bbox2, double bbox3) {
|
|
8
|
-
return new LatLngBounds(bbox, bbox1, bbox2, bbox3);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
LatLng getSouthWest() {
|
|
12
|
-
return new LatLng(latSouth, lonWest);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
LatLng getNorthEast() {
|
|
16
|
-
return new LatLng(latNorth, lonEast);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
LatLng[] toLatLngs() {
|
|
20
|
-
return new LatLng[] {getNorthEast(), getSouthWest()};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
double latNorth;
|
|
24
|
-
double lonEast;
|
|
25
|
-
double latSouth;
|
|
26
|
-
double lonWest;
|
|
27
|
-
|
|
28
|
-
LatLngBounds(double latNorth,double lonEast, double latSouth, double lonWest) {
|
|
29
|
-
this.latNorth = latNorth;
|
|
30
|
-
this.lonEast = lonEast;
|
|
31
|
-
this.latSouth = latSouth;
|
|
32
|
-
this.lonWest = lonWest;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public CoordinateBounds toBounds() {
|
|
36
|
-
return new CoordinateBounds(
|
|
37
|
-
Point.fromLngLat(lonWest, latSouth),
|
|
38
|
-
Point.fromLngLat(lonEast, latNorth),
|
|
39
|
-
false
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
}
|