@rnmapbox/maps 10.3.0-rc.0 → 10.3.0
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/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt +55 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContentManager.kt +7 -2
- package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewManager.kt +0 -2
- package/android/src/main/java/com/rnmapbox/rnmbx/components/location/RNMBXNativeUserLocationManager.kt +25 -24
- package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt +3 -2
- package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt +57 -39
- package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapViewManager.kt +0 -9
- package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/atmosphere/RNMBXAtmosphere.kt +4 -4
- package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/atmosphere/RNMBXAtmosphereManager.kt +2 -1
- package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/light/RNMBXLightManager.kt +2 -1
- package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXSource.kt +2 -6
- package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/terrain/RNMBXTerrainManager.kt +2 -1
- package/android/src/main/java/com/rnmapbox/rnmbx/events/FeatureClickEvent.java +5 -6
- package/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt +1 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/utils/ConvertUtils.kt +0 -30
- package/android/src/main/java/com/rnmapbox/rnmbx/utils/extensions/Dynamic.kt +3 -1
- package/android/src/main/java/com/rnmapbox/rnmbx/utils/extensions/ReadableArray.kt +16 -14
- package/ios/RNMBX/RNMBXMapViewModule.mm +1 -1
- package/ios/RNMBX/RNMBXModule.swift +1 -0
- package/lib/module/Mapbox.native.js.map +1 -1
- package/lib/module/components/MapView.js +95 -113
- package/lib/module/components/MapView.js.map +1 -1
- package/lib/module/components/MarkerView.js +93 -76
- package/lib/module/components/MarkerView.js.map +1 -1
- package/lib/module/modules/offline/offlineManager.js +2 -12
- package/lib/module/modules/offline/offlineManager.js.map +1 -1
- package/lib/module/specs/RNMBXMarkerViewContentNativeComponent.ts +13 -1
- package/lib/typescript/src/Mapbox.native.d.ts +1 -1
- package/lib/typescript/src/Mapbox.native.d.ts.map +1 -1
- package/lib/typescript/src/components/Camera.d.ts +2 -2
- package/lib/typescript/src/components/Camera.d.ts.map +1 -1
- package/lib/typescript/src/components/MapView.d.ts +53 -41
- package/lib/typescript/src/components/MapView.d.ts.map +1 -1
- package/lib/typescript/src/components/MarkerView.d.ts +10 -17
- package/lib/typescript/src/components/MarkerView.d.ts.map +1 -1
- package/lib/typescript/src/modules/offline/offlineManager.d.ts.map +1 -1
- package/lib/typescript/src/specs/RNMBXMarkerViewContentNativeComponent.d.ts +6 -0
- package/lib/typescript/src/specs/RNMBXMarkerViewContentNativeComponent.d.ts.map +1 -1
- package/package.json +1 -1
- package/setup-jest.js +1 -1
- package/src/Mapbox.native.ts +5 -1
- package/src/components/Camera.tsx +2 -2
- package/src/components/MapView.tsx +137 -154
- package/src/components/MarkerView.tsx +118 -95
- package/src/modules/offline/offlineManager.ts +2 -14
- package/src/specs/RNMBXMarkerViewContentNativeComponent.ts +13 -1
package/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
package com.rnmapbox.rnmbx.components.annotation
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
|
+
import android.view.MotionEvent
|
|
4
5
|
import android.view.View.MeasureSpec
|
|
5
6
|
import android.view.ViewGroup
|
|
7
|
+
import com.facebook.react.bridge.Arguments
|
|
8
|
+
import com.facebook.react.bridge.ReactContext
|
|
9
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
6
10
|
import com.facebook.react.views.view.ReactViewGroup
|
|
11
|
+
import com.rnmapbox.rnmbx.components.camera.BaseEvent
|
|
7
12
|
|
|
8
13
|
class RNMBXMarkerViewContent(context: Context): ReactViewGroup(context) {
|
|
9
14
|
var inAdd: Boolean = false
|
|
10
15
|
|
|
16
|
+
// Track last reported translation to avoid feedback loop:
|
|
17
|
+
// Mapbox sets setTranslationX(512) → we fire event → JS sets transform:[{translateX:512}]
|
|
18
|
+
// → Fabric calls setTranslationX(512) again → same value → no re-fire.
|
|
19
|
+
private var lastReportedTx = Float.NaN
|
|
20
|
+
private var lastReportedTy = Float.NaN
|
|
21
|
+
|
|
11
22
|
init {
|
|
12
23
|
allowRenderingOutside()
|
|
13
24
|
}
|
|
@@ -17,6 +28,50 @@ class RNMBXMarkerViewContent(context: Context): ReactViewGroup(context) {
|
|
|
17
28
|
configureParentClipping()
|
|
18
29
|
}
|
|
19
30
|
|
|
31
|
+
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
|
32
|
+
// On ACTION_DOWN, tell the parent MapView not to intercept subsequent MOVE/UP
|
|
33
|
+
// events for pan/zoom recognition — that would send CANCEL to child Pressables
|
|
34
|
+
// and suppress onPress. Android resets the disallow flag on each new DOWN, so
|
|
35
|
+
// calling this once per gesture is sufficient. See maplibre-react-native#1289.
|
|
36
|
+
if (ev.actionMasked == MotionEvent.ACTION_DOWN) {
|
|
37
|
+
parent?.requestDisallowInterceptTouchEvent(true)
|
|
38
|
+
}
|
|
39
|
+
return super.dispatchTouchEvent(ev)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
override fun setTranslationX(translationX: Float) {
|
|
43
|
+
super.setTranslationX(translationX)
|
|
44
|
+
maybeFireAnnotationPositionEvent()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
override fun setTranslationY(translationY: Float) {
|
|
48
|
+
super.setTranslationY(translationY)
|
|
49
|
+
maybeFireAnnotationPositionEvent()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private fun maybeFireAnnotationPositionEvent() {
|
|
53
|
+
val tx = translationX
|
|
54
|
+
val ty = translationY
|
|
55
|
+
// Dedup: skip if value unchanged (prevents feedback loop when Fabric
|
|
56
|
+
// re-applies the same transform prop back to setTranslationX/Y).
|
|
57
|
+
if (tx == lastReportedTx && ty == lastReportedTy) return
|
|
58
|
+
lastReportedTx = tx
|
|
59
|
+
lastReportedTy = ty
|
|
60
|
+
|
|
61
|
+
val reactContext = context as? ReactContext ?: return
|
|
62
|
+
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id) ?: return
|
|
63
|
+
// Use getSurfaceId(view) — more reliable for Fabric than getSurfaceId(context)
|
|
64
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
65
|
+
dispatcher.dispatchEvent(
|
|
66
|
+
BaseEvent(surfaceId, id, "topAnnotationPosition",
|
|
67
|
+
Arguments.createMap().apply {
|
|
68
|
+
putDouble("x", tx.toDouble())
|
|
69
|
+
putDouble("y", ty.toDouble())
|
|
70
|
+
},
|
|
71
|
+
canCoalesce = true)
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
20
75
|
private fun configureParentClipping() {
|
|
21
76
|
val parent = parent
|
|
22
77
|
if (parent is android.view.ViewGroup) {
|
|
@@ -2,13 +2,14 @@ package com.rnmapbox.rnmbx.components.annotation
|
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
4
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
-
import com.facebook.react.uimanager.ViewGroupManager
|
|
6
5
|
import com.facebook.react.viewmanagers.RNMBXMarkerViewContentManagerInterface
|
|
6
|
+
import com.rnmapbox.rnmbx.components.AbstractEventEmitter
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class RNMBXMarkerViewContentManager(reactApplicationContext: ReactApplicationContext) :
|
|
10
|
-
|
|
10
|
+
AbstractEventEmitter<RNMBXMarkerViewContent>(reactApplicationContext),
|
|
11
11
|
RNMBXMarkerViewContentManagerInterface<RNMBXMarkerView> {
|
|
12
|
+
|
|
12
13
|
override fun getName(): String {
|
|
13
14
|
return REACT_CLASS
|
|
14
15
|
}
|
|
@@ -17,6 +18,10 @@ class RNMBXMarkerViewContentManager(reactApplicationContext: ReactApplicationCon
|
|
|
17
18
|
return RNMBXMarkerViewContent(context)
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
override fun customEvents(): Map<String, String> {
|
|
22
|
+
return mapOf("topAnnotationPosition" to "onAnnotationPosition")
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
companion object {
|
|
21
26
|
const val REACT_CLASS = "RNMBXMarkerViewContent"
|
|
22
27
|
}
|
|
@@ -11,8 +11,11 @@ import com.google.gson.Gson
|
|
|
11
11
|
import com.google.gson.stream.JsonWriter
|
|
12
12
|
import com.mapbox.bindgen.Value
|
|
13
13
|
import com.mapbox.maps.extension.style.expressions.generated.Expression
|
|
14
|
+
import com.rnmapbox.rnmbx.components.location.RNMBXNativeUserLocationManager.Companion.TAG
|
|
14
15
|
import com.rnmapbox.rnmbx.rncompat.dynamic.*
|
|
15
16
|
import com.rnmapbox.rnmbx.utils.Logger
|
|
17
|
+
import com.rnmapbox.rnmbx.utils.extensions.asBooleanOrNull
|
|
18
|
+
import com.rnmapbox.rnmbx.utils.extensions.asStringOrNull
|
|
16
19
|
import com.rnmapbox.rnmbx.utils.extensions.toJsonArray
|
|
17
20
|
import java.io.StringWriter
|
|
18
21
|
import javax.annotation.Nonnull
|
|
@@ -27,51 +30,50 @@ class RNMBXNativeUserLocationManager : ViewGroupManager<RNMBXNativeUserLocation>
|
|
|
27
30
|
|
|
28
31
|
@ReactProp(name = "androidRenderMode")
|
|
29
32
|
override fun setAndroidRenderMode(userLocation: RNMBXNativeUserLocation, mode: Dynamic) {
|
|
30
|
-
|
|
31
|
-
Logger.e(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
mode.asStringOrNull()?.let {
|
|
34
|
+
Logger.e(TAG, "androidRenderMode is deprecated, use puckBearing instead")
|
|
35
|
+
|
|
36
|
+
when (it) {
|
|
37
|
+
"compass" -> userLocation.androidRenderMode = RenderMode.COMPASS
|
|
38
|
+
"gps" -> userLocation.androidRenderMode = RenderMode.GPS
|
|
39
|
+
"normal" -> userLocation.androidRenderMode = RenderMode.NORMAL
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
@ReactProp(name = "puckBearing")
|
|
41
45
|
override fun setPuckBearing(view: RNMBXNativeUserLocation, value: Dynamic) {
|
|
42
|
-
when (value
|
|
46
|
+
when (value.asStringOrNull()) {
|
|
43
47
|
"heading" -> view.puckBearing = PuckBearing.HEADING
|
|
44
48
|
"course" -> view.puckBearing = PuckBearing.COURSE
|
|
45
49
|
null -> Unit
|
|
46
50
|
else ->
|
|
47
|
-
Logger.e(
|
|
51
|
+
Logger.e(TAG, "unexpected value for puckBearing: $value")
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
@ReactProp(name = "puckBearingEnabled")
|
|
52
56
|
override fun setPuckBearingEnabled(view: RNMBXNativeUserLocation, value: Dynamic) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
Logger.e("RNMBXNativeUserLocationManager", "unexpected value for puckBearingEnabled: $value")
|
|
58
|
-
}
|
|
57
|
+
value.asBooleanOrNull()?.let {
|
|
58
|
+
view.puckBearingEnabled = it
|
|
59
|
+
} ?: run {
|
|
60
|
+
Logger.e(TAG, "unexpected value for puckBearingEnabled: $value")
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
@ReactProp(name = "topImage")
|
|
63
65
|
override fun setTopImage(view: RNMBXNativeUserLocation, value: Dynamic?) {
|
|
64
|
-
view.topImage = value?.
|
|
66
|
+
view.topImage = value?.asStringOrNull()
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
@ReactProp(name = "bearingImage")
|
|
68
70
|
override fun setBearingImage(view: RNMBXNativeUserLocation, value: Dynamic?) {
|
|
69
|
-
view.bearingImage = value?.
|
|
71
|
+
view.bearingImage = value?.asStringOrNull()
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
@ReactProp(name = "shadowImage")
|
|
73
75
|
override fun setShadowImage(view: RNMBXNativeUserLocation, value: Dynamic?) {
|
|
74
|
-
view.shadowImage = value?.
|
|
76
|
+
view.shadowImage = value?.asStringOrNull()
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
@ReactProp(name = "scale", defaultDouble = 1.0)
|
|
@@ -98,11 +100,10 @@ class RNMBXNativeUserLocationManager : ViewGroupManager<RNMBXNativeUserLocation>
|
|
|
98
100
|
|
|
99
101
|
companion object {
|
|
100
102
|
const val REACT_CLASS = "RNMBXNativeUserLocation"
|
|
103
|
+
const val TAG = "RNMBXNativeUserLocationManager"
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
|
|
104
|
-
|
|
105
|
-
|
|
106
107
|
fun _convertToDoubleValueOrExpression(value: Dynamic?, name: String): Value? {
|
|
107
108
|
if (value == null) {
|
|
108
109
|
return null
|
|
@@ -111,7 +112,7 @@ fun _convertToDoubleValueOrExpression(value: Dynamic?, name: String): Value? {
|
|
|
111
112
|
ReadableType.Array -> {
|
|
112
113
|
val array = value.asArray()
|
|
113
114
|
if (array == null) {
|
|
114
|
-
Logger.e(
|
|
115
|
+
Logger.e(TAG, "_convertToDoubleValueOrExpression: array is null for $name")
|
|
115
116
|
return null
|
|
116
117
|
}
|
|
117
118
|
Expression.fromRaw(Gson().toJson(array.toJsonArray()))
|
|
@@ -120,10 +121,10 @@ fun _convertToDoubleValueOrExpression(value: Dynamic?, name: String): Value? {
|
|
|
120
121
|
Value.valueOf(value.asDouble())
|
|
121
122
|
else -> {
|
|
122
123
|
Logger.e(
|
|
123
|
-
|
|
124
|
-
"_convertToExpressionString: cannot convert $name to a double or double
|
|
124
|
+
TAG,
|
|
125
|
+
"_convertToExpressionString: cannot convert $name to a double or double expression. $value"
|
|
125
126
|
)
|
|
126
|
-
|
|
127
|
+
null
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
}
|
|
@@ -12,6 +12,7 @@ import com.rnmapbox.rnmbx.utils.ExpressionParser
|
|
|
12
12
|
import com.rnmapbox.rnmbx.utils.ViewRefTag
|
|
13
13
|
import com.rnmapbox.rnmbx.utils.ViewTagResolver
|
|
14
14
|
import com.rnmapbox.rnmbx.utils.extensions.toCoordinate
|
|
15
|
+
import com.rnmapbox.rnmbx.utils.extensions.toScreenBox
|
|
15
16
|
import com.rnmapbox.rnmbx.utils.extensions.toScreenCoordinate
|
|
16
17
|
import com.rnmapbox.rnmbx.utils.extensions.toValueHashMap
|
|
17
18
|
|
|
@@ -116,7 +117,7 @@ class NativeMapViewModule(context: ReactApplicationContext, val viewTagResolver:
|
|
|
116
117
|
val layerIds = ConvertUtils.toStringList(withLayerIDs)
|
|
117
118
|
|
|
118
119
|
it.queryRenderedFeaturesAtPoint(
|
|
119
|
-
|
|
120
|
+
atPoint.toScreenCoordinate(),
|
|
120
121
|
ExpressionParser.from(withFilter),
|
|
121
122
|
if (layerIds.size == 0) null else layerIds,
|
|
122
123
|
createCommandResponse(promise)
|
|
@@ -135,7 +136,7 @@ class NativeMapViewModule(context: ReactApplicationContext, val viewTagResolver:
|
|
|
135
136
|
val layerIds = ConvertUtils.toStringList(withLayerIDs)
|
|
136
137
|
|
|
137
138
|
it.queryRenderedFeaturesInRect(
|
|
138
|
-
|
|
139
|
+
if (withBBox.size() == 0) null else withBBox.toScreenBox(),
|
|
139
140
|
ExpressionParser.from(withFilter),
|
|
140
141
|
if (layerIds.size == 0) null else layerIds,
|
|
141
142
|
createCommandResponse(promise)
|
|
@@ -2,11 +2,8 @@ package com.rnmapbox.rnmbx.components.mapview
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.graphics.BitmapFactory
|
|
5
|
-
import android.graphics.PointF
|
|
6
|
-
import android.graphics.RectF
|
|
7
5
|
import android.os.Handler
|
|
8
6
|
import android.os.Looper
|
|
9
|
-
import android.util.Log
|
|
10
7
|
import android.view.Gravity
|
|
11
8
|
import android.view.View
|
|
12
9
|
import android.view.View.OnLayoutChangeListener
|
|
@@ -701,24 +698,26 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
|
|
|
701
698
|
return true
|
|
702
699
|
}
|
|
703
700
|
}
|
|
704
|
-
val
|
|
701
|
+
val screenPointPx = mMap?.pixelForCoordinate(point)
|
|
705
702
|
val touchableSources = allTouchableSources
|
|
706
703
|
val hits = HashMap<String?, List<Feature?>?>()
|
|
707
|
-
if (
|
|
708
|
-
handleTapInSources(LinkedList(touchableSources),
|
|
704
|
+
if (screenPointPx != null) {
|
|
705
|
+
handleTapInSources(LinkedList(touchableSources), screenPointPx, hits, ArrayList(), object : HandleTap {
|
|
709
706
|
override fun run(hitTouchableSources: List<RNMBXSource<*>?>?, hits: Map<String?, List<Feature?>?>) {
|
|
707
|
+
/** Android Mapbox SDK returns screen coordinates in physical pixels, while JS expects density-independent pixels. */
|
|
708
|
+
val screenPointDp = toDp(screenPointPx)
|
|
710
709
|
if (hits.size > 0) {
|
|
711
710
|
val source = getTouchableSourceWithHighestZIndex(hitTouchableSources as List<RNMBXSource<*>>?)
|
|
712
711
|
if (source != null && source.hasPressListener() && source.iD != null && source.iD in hits) {
|
|
713
712
|
source.onPress(RNMBXSource.OnPressEvent(
|
|
714
713
|
hits[source.iD] as List<Feature>,
|
|
715
714
|
GeoJSONUtils.toLatLng(point),
|
|
716
|
-
|
|
715
|
+
screenPointDp
|
|
717
716
|
))
|
|
718
717
|
return
|
|
719
718
|
}
|
|
720
719
|
}
|
|
721
|
-
val event = MapClickEvent(_this, LatLng(point),
|
|
720
|
+
val event = MapClickEvent(_this, LatLng(point), screenPointDp)
|
|
722
721
|
mManager.handleEvent(event)
|
|
723
722
|
}
|
|
724
723
|
|
|
@@ -732,9 +731,10 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
|
|
|
732
731
|
if (pointAnnotations.getAndClearAnnotationDragged()) {
|
|
733
732
|
return true
|
|
734
733
|
}
|
|
735
|
-
val
|
|
736
|
-
if (
|
|
737
|
-
val
|
|
734
|
+
val screenPointPx = mMap?.pixelForCoordinate(point)
|
|
735
|
+
if (screenPointPx != null) {
|
|
736
|
+
val screenPointDp = toDp(screenPointPx)
|
|
737
|
+
val event = MapClickEvent(_this, LatLng(point), screenPointDp, EventTypes.MAP_LONG_CLICK)
|
|
738
738
|
mManager.handleEvent(event)
|
|
739
739
|
}
|
|
740
740
|
|
|
@@ -908,48 +908,61 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
|
|
|
908
908
|
}
|
|
909
909
|
}
|
|
910
910
|
|
|
911
|
-
private fun getDisplayDensity():
|
|
912
|
-
return mContext.resources.displayMetrics.density
|
|
911
|
+
private fun getDisplayDensity(): Double {
|
|
912
|
+
return mContext.resources.displayMetrics.density.toDouble()
|
|
913
913
|
}
|
|
914
914
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
val
|
|
915
|
+
/** Converts a point from physical pixels to density-independent pixels. */
|
|
916
|
+
private fun toDp(pointPx: ScreenCoordinate): ScreenCoordinate {
|
|
917
|
+
val density = getDisplayDensity()
|
|
918
|
+
return ScreenCoordinate(pointPx.x / density, pointPx.y / density)
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/** Converts a point from density-independent pixels to physical pixels. */
|
|
922
|
+
private fun toPx(pointDp: ScreenCoordinate): ScreenCoordinate {
|
|
923
|
+
val density = getDisplayDensity()
|
|
924
|
+
return ScreenCoordinate(pointDp.x * density, pointDp.y * density)
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/** Converts a bounding box from density-independent pixels to physical pixels. */
|
|
928
|
+
private fun toPx(boxDp: ScreenBox): ScreenBox {
|
|
929
|
+
val density = getDisplayDensity()
|
|
930
|
+
return ScreenBox(
|
|
931
|
+
ScreenCoordinate(boxDp.min.x * density, boxDp.min.y * density),
|
|
932
|
+
ScreenCoordinate(boxDp.max.x * density, boxDp.max.y * density),
|
|
933
|
+
)
|
|
934
|
+
}
|
|
918
935
|
|
|
919
|
-
|
|
936
|
+
fun getCoordinateFromView(pointDp: ScreenCoordinate, response: CommandResponse) {
|
|
937
|
+
val pointPx = toPx(pointDp)
|
|
938
|
+
|
|
939
|
+
val coordinate = mMap!!.coordinateForPixel(pointPx)
|
|
920
940
|
|
|
921
941
|
response.success {
|
|
922
942
|
it.putArray("coordinateFromView", coordinate.toReadableArray())
|
|
923
943
|
}
|
|
924
944
|
}
|
|
925
945
|
|
|
926
|
-
fun getPointInView(
|
|
927
|
-
val
|
|
928
|
-
val density = getDisplayDensity()
|
|
929
|
-
val pointInView = PointF((point.x / density).toFloat(), (point.y / density).toFloat())
|
|
946
|
+
fun getPointInView(coordinates: Point, response: CommandResponse) {
|
|
947
|
+
val pointDp = toDp(mMap!!.pixelForCoordinate(coordinates))
|
|
930
948
|
|
|
931
949
|
response.success {
|
|
932
950
|
val array: WritableArray = WritableNativeArray()
|
|
933
|
-
array.pushDouble(
|
|
934
|
-
array.pushDouble(
|
|
951
|
+
array.pushDouble(pointDp.x)
|
|
952
|
+
array.pushDouble(pointDp.y)
|
|
935
953
|
it.putArray("pointInView", array)
|
|
936
954
|
}
|
|
937
955
|
}
|
|
938
956
|
|
|
939
|
-
fun queryRenderedFeaturesAtPoint(
|
|
957
|
+
fun queryRenderedFeaturesAtPoint(pointDp: ScreenCoordinate, filter: Expression?, layerIDs: List<String>?, response: CommandResponse) {
|
|
940
958
|
if (mMap == null) {
|
|
941
959
|
Logger.e("queryRenderedFeaturesAtPoint", "mapbox map is null")
|
|
942
960
|
return
|
|
943
961
|
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
val
|
|
947
|
-
val
|
|
948
|
-
(point.x * density).toDouble(),
|
|
949
|
-
(point.y * density).toDouble()
|
|
950
|
-
)
|
|
951
|
-
val queryGeometry = RenderedQueryGeometry(screenCoordinate)
|
|
952
|
-
val layers = layerIDs?.takeUnless { it.isEmpty() } ?: null;
|
|
962
|
+
|
|
963
|
+
val pointPx = toPx(pointDp)
|
|
964
|
+
val queryGeometry = RenderedQueryGeometry(pointPx)
|
|
965
|
+
val layers = layerIDs?.takeUnless { it.isEmpty() } ?: null
|
|
953
966
|
val queryOptions = RenderedQueryOptions(layers, filter)
|
|
954
967
|
mMap.queryRenderedFeatures(queryGeometry, queryOptions) { features ->
|
|
955
968
|
if (features.isValue) {
|
|
@@ -966,14 +979,19 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
|
|
|
966
979
|
}
|
|
967
980
|
}
|
|
968
981
|
|
|
969
|
-
fun queryRenderedFeaturesInRect(
|
|
982
|
+
fun queryRenderedFeaturesInRect(rectDp: ScreenBox?, filter: Expression?, layerIDs: List<String>?, response: CommandResponse) {
|
|
970
983
|
val size = mMap.getMapOptions().size
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
984
|
+
|
|
985
|
+
val rectPx: ScreenBox =
|
|
986
|
+
rectDp?.let { toPx(it) }
|
|
987
|
+
?: ScreenBox(
|
|
988
|
+
ScreenCoordinate(0.0, 0.0),
|
|
989
|
+
/** No conversion needed, screen size is already returned in physical pixels. */
|
|
990
|
+
ScreenCoordinate(size?.width?.toDouble() ?: 0.0, size?.height?.toDouble() ?: 0.0)
|
|
991
|
+
)
|
|
992
|
+
|
|
975
993
|
mMap.queryRenderedFeatures(
|
|
976
|
-
RenderedQueryGeometry(
|
|
994
|
+
RenderedQueryGeometry(rectPx),
|
|
977
995
|
RenderedQueryOptions(layerIDs, filter)
|
|
978
996
|
) { features ->
|
|
979
997
|
if (features.isValue) {
|
|
@@ -10,25 +10,16 @@ import com.facebook.react.uimanager.LayoutShadowNode
|
|
|
10
10
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
11
11
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
12
12
|
import com.rnmapbox.rnmbx.events.constants.EventKeys
|
|
13
|
-
import com.facebook.react.common.MapBuilder
|
|
14
13
|
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
15
14
|
import com.facebook.react.viewmanagers.RNMBXMapViewManagerDelegate
|
|
16
15
|
import com.facebook.react.viewmanagers.RNMBXMapViewManagerInterface
|
|
17
|
-
import com.mapbox.maps.MapInitOptions
|
|
18
16
|
import com.mapbox.maps.extension.style.layers.properties.generated.ProjectionName
|
|
19
17
|
import com.mapbox.maps.plugin.gestures.gestures
|
|
20
|
-
import com.mapbox.maps.plugin.logo.logo
|
|
21
|
-
import com.rnmapbox.rnmbx.events.AndroidCallbackEvent
|
|
22
18
|
import com.rnmapbox.rnmbx.events.constants.eventMapOf
|
|
23
|
-
import com.rnmapbox.rnmbx.utils.ConvertUtils
|
|
24
|
-
import com.rnmapbox.rnmbx.utils.ExpressionParser
|
|
25
19
|
import com.rnmapbox.rnmbx.utils.Logger
|
|
26
20
|
import com.rnmapbox.rnmbx.utils.ViewTagResolver
|
|
27
21
|
import com.rnmapbox.rnmbx.utils.extensions.getAndLogIfNotBoolean
|
|
28
22
|
import com.rnmapbox.rnmbx.utils.extensions.getAndLogIfNotDouble
|
|
29
|
-
import com.rnmapbox.rnmbx.utils.extensions.toCoordinate
|
|
30
|
-
import com.rnmapbox.rnmbx.utils.extensions.toRectF
|
|
31
|
-
import com.rnmapbox.rnmbx.utils.extensions.toScreenCoordinate
|
|
32
23
|
import java.lang.Exception
|
|
33
24
|
import java.util.HashMap
|
|
34
25
|
|
package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/atmosphere/RNMBXAtmosphere.kt
CHANGED
|
@@ -4,8 +4,7 @@ import android.content.Context
|
|
|
4
4
|
import com.facebook.react.bridge.ReadableMap
|
|
5
5
|
import com.mapbox.maps.MapboxMap
|
|
6
6
|
import com.mapbox.maps.extension.style.atmosphere.generated.Atmosphere
|
|
7
|
-
import com.mapbox.maps.extension.style.
|
|
8
|
-
import com.mapbox.maps.extension.style.terrain.generated.removeTerrain
|
|
7
|
+
import com.mapbox.maps.extension.style.atmosphere.generated.removeAtmosphere
|
|
9
8
|
import com.rnmapbox.rnmbx.components.RemovalReason
|
|
10
9
|
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapView
|
|
11
10
|
import com.rnmapbox.rnmbx.components.styles.RNMBXStyle
|
|
@@ -42,7 +41,8 @@ class RNMBXAtmosphere(context: Context?) : AbstractSourceConsumer(context) {
|
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
override fun removeFromMap(mapView: RNMBXMapView, reason: RemovalReason): Boolean {
|
|
45
|
-
mapView.savedStyle?.let { it.
|
|
44
|
+
mapView.savedStyle?.let { it.removeAtmosphere() }
|
|
45
|
+
mAtmosphere = null
|
|
46
46
|
mMap = null
|
|
47
47
|
return super.removeFromMap(mapView, reason)
|
|
48
48
|
}
|
|
@@ -55,7 +55,7 @@ class RNMBXAtmosphere(context: Context?) : AbstractSourceConsumer(context) {
|
|
|
55
55
|
mAtmosphere?.also {
|
|
56
56
|
RNMBXStyleFactory.setAtmosphereLayerStyle(
|
|
57
57
|
it, RNMBXStyle(
|
|
58
|
-
context, mReactStyle
|
|
58
|
+
context, mReactStyle,
|
|
59
59
|
mMap!!
|
|
60
60
|
)
|
|
61
61
|
)
|
|
@@ -2,6 +2,7 @@ package com.rnmapbox.rnmbx.components.styles.atmosphere
|
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.Dynamic
|
|
4
4
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
import com.rnmapbox.rnmbx.utils.extensions.asMapOrNull
|
|
5
6
|
import com.facebook.react.uimanager.ViewGroupManager
|
|
6
7
|
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
7
8
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
@@ -30,7 +31,7 @@ class RNMBXAtmosphereManager : ViewGroupManager<RNMBXAtmosphere>(), RNMBXAtmosph
|
|
|
30
31
|
|
|
31
32
|
@ReactProp(name = "reactStyle")
|
|
32
33
|
override fun setReactStyle(atmosphere: RNMBXAtmosphere, reactStyle: Dynamic) {
|
|
33
|
-
atmosphere.setReactStyle(reactStyle.
|
|
34
|
+
atmosphere.setReactStyle(reactStyle.asMapOrNull())
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
companion object {
|
package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/light/RNMBXLightManager.kt
CHANGED
|
@@ -2,6 +2,7 @@ package com.rnmapbox.rnmbx.components.styles.light
|
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.Dynamic
|
|
4
4
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
import com.rnmapbox.rnmbx.utils.extensions.asMapOrNull
|
|
5
6
|
import com.facebook.react.uimanager.ViewGroupManager
|
|
6
7
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
7
8
|
import com.facebook.react.viewmanagers.RNMBXLightManagerInterface
|
|
@@ -18,7 +19,7 @@ class RNMBXLightManager : ViewGroupManager<RNMBXLight>(),
|
|
|
18
19
|
|
|
19
20
|
@ReactProp(name = "reactStyle")
|
|
20
21
|
override fun setReactStyle(light: RNMBXLight, reactStyle: Dynamic) {
|
|
21
|
-
light.setReactStyle(reactStyle.
|
|
22
|
+
light.setReactStyle(reactStyle.asMapOrNull())
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
companion object {
|
|
@@ -6,22 +6,18 @@ import com.mapbox.maps.extension.style.sources.addSource
|
|
|
6
6
|
import com.rnmapbox.rnmbx.components.AbstractMapFeature
|
|
7
7
|
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapView
|
|
8
8
|
import com.mapbox.maps.MapboxMap
|
|
9
|
-
import com.rnmapbox.rnmbx.components.styles.sources.AbstractSourceConsumer
|
|
10
9
|
import com.facebook.react.bridge.ReadableMap
|
|
11
|
-
import com.rnmapbox.rnmbx.components.styles.sources.RNMBXSource
|
|
12
|
-
import android.graphics.PointF
|
|
13
10
|
import android.view.View
|
|
14
11
|
import com.facebook.react.common.MapBuilder
|
|
15
12
|
import com.mapbox.geojson.Feature
|
|
13
|
+
import com.mapbox.maps.ScreenCoordinate
|
|
16
14
|
import com.mapbox.maps.Style
|
|
17
15
|
import com.mapbox.maps.extension.style.StyleContract
|
|
18
16
|
import com.mapbox.maps.extension.style.sources.Source
|
|
19
17
|
import com.rnmapbox.rnmbx.components.RemovalReason
|
|
20
|
-
import com.rnmapbox.rnmbx.components.styles.sources.RNMBXSource.OnPressEvent
|
|
21
18
|
import com.rnmapbox.rnmbx.utils.LatLng
|
|
22
19
|
import com.rnmapbox.rnmbx.utils.Logger
|
|
23
20
|
import java.lang.ClassCastException
|
|
24
|
-
import java.util.ArrayList
|
|
25
21
|
import java.util.HashMap
|
|
26
22
|
|
|
27
23
|
data class FeatureInfo(val feature: AbstractMapFeature?, var added: Boolean) {
|
|
@@ -221,7 +217,7 @@ abstract class RNMBXSource<T : Source?>(context: Context?) : AbstractMapFeature(
|
|
|
221
217
|
|
|
222
218
|
|
|
223
219
|
abstract fun makeSource(): T
|
|
224
|
-
class OnPressEvent(var features: List<Feature>, var latLng: LatLng, var screenPoint:
|
|
220
|
+
class OnPressEvent(var features: List<Feature>, var latLng: LatLng, var screenPoint: ScreenCoordinate)
|
|
225
221
|
|
|
226
222
|
abstract fun onPress(event: OnPressEvent?)
|
|
227
223
|
|
package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/terrain/RNMBXTerrainManager.kt
CHANGED
|
@@ -2,6 +2,7 @@ package com.rnmapbox.rnmbx.components.styles.terrain
|
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.Dynamic
|
|
4
4
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
import com.rnmapbox.rnmbx.utils.extensions.asMapOrNull
|
|
5
6
|
import com.facebook.react.uimanager.ViewGroupManager
|
|
6
7
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
7
8
|
import com.facebook.react.viewmanagers.RNMBXTerrainManagerInterface
|
|
@@ -23,7 +24,7 @@ class RNMBXTerrainManager : ViewGroupManager<RNMBXTerrain>(),
|
|
|
23
24
|
|
|
24
25
|
@ReactProp(name = "reactStyle")
|
|
25
26
|
override fun setReactStyle(terrain: RNMBXTerrain, reactStyle: Dynamic) {
|
|
26
|
-
terrain.setReactStyle(reactStyle.
|
|
27
|
+
terrain.setReactStyle(reactStyle.asMapOrNull())
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
companion object {
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
package com.rnmapbox.rnmbx.events;
|
|
2
2
|
|
|
3
|
-
import android.graphics.PointF;
|
|
4
3
|
import android.view.View;
|
|
5
4
|
|
|
6
5
|
import com.facebook.react.bridge.Arguments;
|
|
7
6
|
import com.facebook.react.bridge.WritableArray;
|
|
8
7
|
import com.facebook.react.bridge.WritableMap;
|
|
9
8
|
import com.mapbox.geojson.Feature;
|
|
9
|
+
import com.mapbox.maps.ScreenCoordinate;
|
|
10
10
|
import com.rnmapbox.rnmbx.components.styles.sources.RNMBXSource;
|
|
11
11
|
import com.rnmapbox.rnmbx.events.constants.EventKeys;
|
|
12
12
|
import com.rnmapbox.rnmbx.events.constants.EventTypes;
|
|
13
|
-
import com.rnmapbox.rnmbx.utils.ConvertUtils;
|
|
14
13
|
import com.rnmapbox.rnmbx.utils.GeoJSONUtils;
|
|
15
14
|
import com.rnmapbox.rnmbx.utils.LatLng;
|
|
16
15
|
|
|
@@ -24,9 +23,9 @@ public class FeatureClickEvent extends AbstractEvent {
|
|
|
24
23
|
private String mEventKey;
|
|
25
24
|
private List<Feature> mFeatures;
|
|
26
25
|
private LatLng mLatLng;
|
|
27
|
-
private
|
|
26
|
+
private ScreenCoordinate mPoint;
|
|
28
27
|
|
|
29
|
-
public FeatureClickEvent(View view, String eventKey, String eventType, List<Feature> features, LatLng latLng,
|
|
28
|
+
public FeatureClickEvent(View view, String eventKey, String eventType, List<Feature> features, LatLng latLng, ScreenCoordinate point) {
|
|
30
29
|
super(view, eventType);
|
|
31
30
|
mFeatures = features;
|
|
32
31
|
mEventKey = eventKey;
|
|
@@ -55,8 +54,8 @@ public class FeatureClickEvent extends AbstractEvent {
|
|
|
55
54
|
map.putMap("coordinates", coordinates);
|
|
56
55
|
|
|
57
56
|
WritableMap point = Arguments.createMap();
|
|
58
|
-
point.putDouble("x", mPoint.
|
|
59
|
-
point.putDouble("y", mPoint.
|
|
57
|
+
point.putDouble("x", mPoint.getX());
|
|
58
|
+
point.putDouble("y", mPoint.getY());
|
|
60
59
|
map.putMap("point", point);
|
|
61
60
|
|
|
62
61
|
return map;
|
|
@@ -114,6 +114,7 @@ class RNMBXModule(private val mReactContext: ReactApplicationContext) : ReactCon
|
|
|
114
114
|
val locationModuleCallbackNames: MutableMap<String, String> = HashMap()
|
|
115
115
|
locationModuleCallbackNames["Update"] = RNMBXLocationModule.LOCATION_UPDATE
|
|
116
116
|
return MapBuilder.builder<String, Any>()
|
|
117
|
+
// Deprecated: means v10 or later, always true. Will be removed in next major version.
|
|
117
118
|
.put("MapboxV10", true)
|
|
118
119
|
.put("StyleURL", styleURLS)
|
|
119
120
|
.put("EventTypes", eventTypes)
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
package com.rnmapbox.rnmbx.utils
|
|
2
2
|
|
|
3
|
-
import android.graphics.PointF
|
|
4
|
-
import android.graphics.RectF
|
|
5
3
|
import android.util.Log
|
|
6
4
|
import com.facebook.react.bridge.Arguments
|
|
7
5
|
import com.facebook.react.bridge.NoSuchKeyException
|
|
@@ -172,34 +170,6 @@ object ConvertUtils {
|
|
|
172
170
|
return list
|
|
173
171
|
}
|
|
174
172
|
|
|
175
|
-
fun toPointF(array: ReadableArray?): PointF {
|
|
176
|
-
val pointF = PointF()
|
|
177
|
-
|
|
178
|
-
if (array == null) {
|
|
179
|
-
return pointF
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
pointF.set(array.getDouble(0).toFloat(), array.getDouble(1).toFloat())
|
|
183
|
-
return pointF
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// returns null if array is null
|
|
187
|
-
fun toRectF(array: ReadableArray?): RectF? {
|
|
188
|
-
val rectF = RectF()
|
|
189
|
-
|
|
190
|
-
if (array == null || array.size() == 0) {
|
|
191
|
-
return null
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
rectF.set(
|
|
195
|
-
array.getDouble(3).toFloat(),
|
|
196
|
-
array.getDouble(0).toFloat(),
|
|
197
|
-
array.getDouble(1).toFloat(),
|
|
198
|
-
array.getDouble(2).toFloat()
|
|
199
|
-
)
|
|
200
|
-
return rectF
|
|
201
|
-
}
|
|
202
|
-
|
|
203
173
|
fun getDouble(key: String, map: ReadableMap, defaultValue: Double): Double {
|
|
204
174
|
var value = defaultValue
|
|
205
175
|
|