@maplibre/maplibre-react-native 11.0.0-alpha.16 → 11.0.0-alpha.18
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/org/maplibre/reactnative/MLRNPackage.kt +6 -6
- package/android/src/main/java/org/maplibre/reactnative/components/camera/MLRNCameraManager.kt +3 -5
- package/android/src/main/java/org/maplibre/reactnative/components/location/LocationComponentManager.kt +154 -0
- package/android/src/main/java/org/maplibre/reactnative/components/location/MLRNNativeUserLocation.kt +70 -0
- package/android/src/main/java/org/maplibre/reactnative/components/location/MLRNNativeUserLocationManager.kt +50 -0
- package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLocationModule.kt +20 -4
- package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLogModule.kt +99 -0
- package/ios/components/camera/MLRNCameraComponentView.h +0 -8
- package/ios/components/map-view/MLRNMapView.m +1 -1
- package/ios/components/map-view/MLRNMapViewComponentView.h +0 -5
- package/ios/components/user-location/MLRNNativeUserLocation.h +1 -1
- package/ios/components/user-location/MLRNNativeUserLocation.m +6 -5
- package/ios/components/user-location/MLRNNativeUserLocationComponentView.h +10 -0
- package/ios/components/user-location/MLRNNativeUserLocationComponentView.mm +51 -0
- package/ios/modules/location/MLRNLocation.m +17 -14
- package/ios/modules/logging/MLRNLogModule.h +10 -0
- package/ios/modules/logging/MLRNLogModule.mm +39 -0
- package/ios/modules/logging/MLRNLogging.h +15 -7
- package/ios/modules/logging/MLRNLogging.m +22 -55
- package/lib/commonjs/components/annotations/Annotation.js +2 -1
- package/lib/commonjs/components/annotations/Annotation.js.map +1 -1
- package/lib/commonjs/components/map-view/MapView.js +3 -3
- package/lib/commonjs/components/map-view/MapView.js.map +1 -1
- package/lib/commonjs/components/sources/ShapeSource.js +1 -0
- package/lib/commonjs/components/sources/ShapeSource.js.map +1 -1
- package/lib/commonjs/components/user-location/NativeUserLocation.js +3 -4
- package/lib/commonjs/components/user-location/NativeUserLocation.js.map +1 -1
- package/lib/commonjs/components/user-location/UserLocation.js +22 -132
- package/lib/commonjs/components/user-location/UserLocation.js.map +1 -1
- package/lib/commonjs/components/user-location/UserLocationNativeComponent.ts +19 -0
- package/lib/commonjs/components/user-location/UserLocationPuck.js +34 -22
- package/lib/commonjs/components/user-location/UserLocationPuck.js.map +1 -1
- package/lib/commonjs/components/user-location/UserLocationPuckHeading.js +3 -2
- package/lib/commonjs/components/user-location/UserLocationPuckHeading.js.map +1 -1
- package/lib/commonjs/hooks/useCurrentPosition.js +34 -0
- package/lib/commonjs/hooks/useCurrentPosition.js.map +1 -0
- package/lib/commonjs/index.js +16 -15
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modules/log/LogManager.js +99 -0
- package/lib/commonjs/modules/log/LogManager.js.map +1 -0
- package/lib/commonjs/modules/log/NativeLogModule.js +9 -0
- package/lib/commonjs/modules/log/NativeLogModule.js.map +1 -0
- package/lib/commonjs/utils/animated/Animated.js +1 -7
- package/lib/commonjs/utils/animated/Animated.js.map +1 -1
- package/lib/module/components/annotations/Annotation.js +3 -2
- package/lib/module/components/annotations/Annotation.js.map +1 -1
- package/lib/module/components/map-view/MapView.js +3 -3
- package/lib/module/components/map-view/MapView.js.map +1 -1
- package/lib/module/components/sources/ShapeSource.js +1 -0
- package/lib/module/components/sources/ShapeSource.js.map +1 -1
- package/lib/module/components/user-location/NativeUserLocation.js +2 -4
- package/lib/module/components/user-location/NativeUserLocation.js.map +1 -1
- package/lib/module/components/user-location/UserLocation.js +22 -132
- package/lib/module/components/user-location/UserLocation.js.map +1 -1
- package/lib/module/components/user-location/UserLocationNativeComponent.ts +19 -0
- package/lib/module/components/user-location/UserLocationPuck.js +34 -22
- package/lib/module/components/user-location/UserLocationPuck.js.map +1 -1
- package/lib/module/components/user-location/UserLocationPuckHeading.js +3 -2
- package/lib/module/components/user-location/UserLocationPuckHeading.js.map +1 -1
- package/lib/module/hooks/useCurrentPosition.js +30 -0
- package/lib/module/hooks/useCurrentPosition.js.map +1 -0
- package/lib/module/index.js +4 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/log/LogManager.js +96 -0
- package/lib/module/modules/log/LogManager.js.map +1 -0
- package/lib/module/modules/log/NativeLogModule.js +5 -0
- package/lib/module/modules/log/NativeLogModule.js.map +1 -0
- package/lib/module/utils/animated/Animated.js +0 -6
- package/lib/module/utils/animated/Animated.js.map +1 -1
- package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts +3 -2
- package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/sources/ShapeSource.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/user-location/NativeUserLocation.d.ts +12 -13
- package/lib/typescript/commonjs/src/components/user-location/NativeUserLocation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/user-location/UserLocation.d.ts +13 -53
- package/lib/typescript/commonjs/src/components/user-location/UserLocation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/user-location/UserLocationNativeComponent.d.ts +8 -0
- package/lib/typescript/commonjs/src/components/user-location/UserLocationNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/user-location/UserLocationPuck.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/user-location/UserLocationPuck.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/user-location/UserLocationPuckHeading.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/hooks/useCurrentPosition.d.ts +18 -0
- package/lib/typescript/commonjs/src/hooks/useCurrentPosition.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -4
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts +3 -3
- package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts +3 -3
- package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/log/LogManager.d.ts +45 -0
- package/lib/typescript/commonjs/src/modules/log/LogManager.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/log/NativeLogModule.d.ts +13 -0
- package/lib/typescript/commonjs/src/modules/log/NativeLogModule.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts +1 -13
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts.map +1 -1
- package/lib/typescript/module/src/components/annotations/Annotation.d.ts +3 -2
- package/lib/typescript/module/src/components/annotations/Annotation.d.ts.map +1 -1
- package/lib/typescript/module/src/components/sources/ShapeSource.d.ts.map +1 -1
- package/lib/typescript/module/src/components/user-location/NativeUserLocation.d.ts +12 -13
- package/lib/typescript/module/src/components/user-location/NativeUserLocation.d.ts.map +1 -1
- package/lib/typescript/module/src/components/user-location/UserLocation.d.ts +13 -53
- package/lib/typescript/module/src/components/user-location/UserLocation.d.ts.map +1 -1
- package/lib/typescript/module/src/components/user-location/UserLocationNativeComponent.d.ts +8 -0
- package/lib/typescript/module/src/components/user-location/UserLocationNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/components/user-location/UserLocationPuck.d.ts +2 -1
- package/lib/typescript/module/src/components/user-location/UserLocationPuck.d.ts.map +1 -1
- package/lib/typescript/module/src/components/user-location/UserLocationPuckHeading.d.ts.map +1 -1
- package/lib/typescript/module/src/hooks/useCurrentPosition.d.ts +18 -0
- package/lib/typescript/module/src/hooks/useCurrentPosition.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -4
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/location/LocationManager.d.ts +3 -3
- package/lib/typescript/module/src/modules/location/LocationManager.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts +3 -3
- package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/log/LogManager.d.ts +45 -0
- package/lib/typescript/module/src/modules/log/LogManager.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/log/NativeLogModule.d.ts +13 -0
- package/lib/typescript/module/src/modules/log/NativeLogModule.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/animated/Animated.d.ts +1 -13
- package/lib/typescript/module/src/utils/animated/Animated.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/components/annotations/Annotation.tsx +7 -5
- package/src/components/map-view/MapView.tsx +3 -3
- package/src/components/sources/ShapeSource.tsx +1 -0
- package/src/components/user-location/NativeUserLocation.tsx +15 -19
- package/src/components/user-location/UserLocation.tsx +65 -249
- package/src/components/user-location/UserLocationNativeComponent.ts +19 -0
- package/src/components/user-location/UserLocationPuck.tsx +47 -28
- package/src/components/user-location/UserLocationPuckHeading.tsx +2 -1
- package/src/hooks/useCurrentPosition.ts +53 -0
- package/src/index.ts +6 -7
- package/src/modules/location/LocationManager.ts +3 -3
- package/src/modules/location/NativeLocationModule.ts +3 -3
- package/src/modules/log/LogManager.ts +114 -0
- package/src/modules/log/NativeLogModule.ts +16 -0
- package/src/utils/animated/Animated.ts +1 -28
- package/android/src/main/java/org/maplibre/reactnative/components/location/LocationComponentManager.java +0 -165
- package/android/src/main/java/org/maplibre/reactnative/components/location/MLRNNativeUserLocation.java +0 -76
- package/android/src/main/java/org/maplibre/reactnative/components/location/MLRNNativeUserLocationManager.java +0 -40
- package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLogging.java +0 -140
- package/ios/components/user-location/MLRNNativeUserLocationManager.h +0 -5
- package/ios/components/user-location/MLRNNativeUserLocationManager.m +0 -21
- package/lib/commonjs/modules/Logger.js +0 -112
- package/lib/commonjs/modules/Logger.js.map +0 -1
- package/lib/commonjs/modules/location/requestAndroidLocationPermissions.js +0 -14
- package/lib/commonjs/modules/location/requestAndroidLocationPermissions.js.map +0 -1
- package/lib/module/modules/Logger.js +0 -107
- package/lib/module/modules/Logger.js.map +0 -1
- package/lib/module/modules/location/requestAndroidLocationPermissions.js +0 -11
- package/lib/module/modules/location/requestAndroidLocationPermissions.js.map +0 -1
- package/lib/typescript/commonjs/src/modules/Logger.d.ts +0 -49
- package/lib/typescript/commonjs/src/modules/Logger.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/modules/location/requestAndroidLocationPermissions.d.ts +0 -5
- package/lib/typescript/commonjs/src/modules/location/requestAndroidLocationPermissions.d.ts.map +0 -1
- package/lib/typescript/module/src/modules/Logger.d.ts +0 -49
- package/lib/typescript/module/src/modules/Logger.d.ts.map +0 -1
- package/lib/typescript/module/src/modules/location/requestAndroidLocationPermissions.d.ts +0 -5
- package/lib/typescript/module/src/modules/location/requestAndroidLocationPermissions.d.ts.map +0 -1
- package/src/modules/Logger.ts +0 -127
- package/src/modules/location/requestAndroidLocationPermissions.ts +0 -8
|
@@ -29,7 +29,7 @@ import org.maplibre.reactnative.components.sources.MLRNRasterSourceManager
|
|
|
29
29
|
import org.maplibre.reactnative.components.sources.MLRNShapeSourceManager
|
|
30
30
|
import org.maplibre.reactnative.components.sources.MLRNVectorSourceManager
|
|
31
31
|
import org.maplibre.reactnative.modules.MLRNLocationModule
|
|
32
|
-
import org.maplibre.reactnative.modules.
|
|
32
|
+
import org.maplibre.reactnative.modules.MLRNLogModule
|
|
33
33
|
import org.maplibre.reactnative.modules.MLRNModule
|
|
34
34
|
import org.maplibre.reactnative.modules.MLRNOfflineModule
|
|
35
35
|
import org.maplibre.reactnative.modules.MLRNSnapshotModule
|
|
@@ -56,7 +56,7 @@ class MLRNPackage : BaseReactPackage() {
|
|
|
56
56
|
MLRNOfflineModule.REACT_CLASS -> return MLRNOfflineModule(reactContext)
|
|
57
57
|
MLRNSnapshotModule.NAME -> return MLRNSnapshotModule(reactContext)
|
|
58
58
|
MLRNLocationModule.NAME -> return MLRNLocationModule(reactContext)
|
|
59
|
-
|
|
59
|
+
MLRNLogModule.NAME -> return MLRNLogModule(reactContext)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
return null
|
|
@@ -120,13 +120,13 @@ class MLRNPackage : BaseReactPackage() {
|
|
|
120
120
|
isTurboModule = true
|
|
121
121
|
)
|
|
122
122
|
|
|
123
|
-
moduleInfos[
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
moduleInfos[MLRNLogModule.NAME] = ReactModuleInfo(
|
|
124
|
+
MLRNLogModule.NAME,
|
|
125
|
+
MLRNLogModule.NAME,
|
|
126
126
|
canOverrideExistingModule = false,
|
|
127
127
|
needsEagerInit = false,
|
|
128
128
|
isCxxModule = false,
|
|
129
|
-
isTurboModule =
|
|
129
|
+
isTurboModule = true
|
|
130
130
|
)
|
|
131
131
|
|
|
132
132
|
moduleInfos
|
package/android/src/main/java/org/maplibre/reactnative/components/camera/MLRNCameraManager.kt
CHANGED
|
@@ -14,10 +14,8 @@ import org.maplibre.reactnative.location.TrackUserLocationMode
|
|
|
14
14
|
import org.maplibre.reactnative.utils.GeoJSONUtils
|
|
15
15
|
|
|
16
16
|
@ReactModule(name = MLRNCameraManager.REACT_CLASS)
|
|
17
|
-
class MLRNCameraManager(private val
|
|
18
|
-
ViewGroupManager<MLRNCamera>(
|
|
19
|
-
|
|
20
|
-
), MLRNCameraManagerInterface<MLRNCamera> {
|
|
17
|
+
class MLRNCameraManager(private val context: ReactApplicationContext) :
|
|
18
|
+
ViewGroupManager<MLRNCamera>(), MLRNCameraManagerInterface<MLRNCamera> {
|
|
21
19
|
private val delegate: MLRNCameraManagerDelegate<MLRNCamera, MLRNCameraManager> =
|
|
22
20
|
MLRNCameraManagerDelegate(this)
|
|
23
21
|
|
|
@@ -42,7 +40,7 @@ class MLRNCameraManager(private val mContext: ReactApplicationContext) :
|
|
|
42
40
|
@ReactProp(name = "initialViewState")
|
|
43
41
|
override fun setInitialViewState(camera: MLRNCamera, value: ReadableMap?) {
|
|
44
42
|
if (value != null && !camera.hasInitialViewState()) {
|
|
45
|
-
val stop = CameraStop.fromReadableMap(
|
|
43
|
+
val stop = CameraStop.fromReadableMap(context, value, null)
|
|
46
44
|
camera.setInitialViewState(stop)
|
|
47
45
|
}
|
|
48
46
|
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
package org.maplibre.reactnative.components.location
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import org.maplibre.android.location.LocationComponent
|
|
6
|
+
import org.maplibre.android.location.LocationComponentActivationOptions
|
|
7
|
+
import org.maplibre.android.location.LocationComponentOptions
|
|
8
|
+
import org.maplibre.android.location.OnCameraTrackingChangedListener
|
|
9
|
+
import org.maplibre.android.location.modes.CameraMode
|
|
10
|
+
import org.maplibre.android.location.modes.RenderMode
|
|
11
|
+
import org.maplibre.android.maps.MapLibreMap
|
|
12
|
+
import org.maplibre.android.maps.Style
|
|
13
|
+
import org.maplibre.reactnative.R
|
|
14
|
+
import org.maplibre.reactnative.components.mapview.MLRNMapView
|
|
15
|
+
import org.maplibre.reactnative.location.LocationManager
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The LocationComponent on android implements both location tracking and display of user's current location.
|
|
19
|
+
* LocationComponentManager attempts to separate that, so that Camera can ask for location tracking independent of display of user current location.
|
|
20
|
+
* And NativeUserLocation can ask for display of user's current location - independent of Camera's user tracking.
|
|
21
|
+
*/
|
|
22
|
+
class LocationComponentManager(mapView: MLRNMapView?, private val context: Context) {
|
|
23
|
+
private var mMapView: MLRNMapView? = null
|
|
24
|
+
private var mMap: MapLibreMap? = null
|
|
25
|
+
|
|
26
|
+
private var mLocationManager: LocationManager? = null
|
|
27
|
+
private var mLocationComponent: LocationComponent? = null
|
|
28
|
+
|
|
29
|
+
@RenderMode.Mode
|
|
30
|
+
private var mRenderMode: Int = RenderMode.COMPASS
|
|
31
|
+
|
|
32
|
+
private var mShowUserLocation = false
|
|
33
|
+
|
|
34
|
+
private var mFollowUserLocation = false
|
|
35
|
+
|
|
36
|
+
private var mShowingUserLocation = false
|
|
37
|
+
|
|
38
|
+
private var mOnCameraTrackingChangedListener: OnCameraTrackingChangedListener? = null
|
|
39
|
+
|
|
40
|
+
init {
|
|
41
|
+
mMapView = mapView
|
|
42
|
+
mMap = mMapView?.mapLibreMap
|
|
43
|
+
|
|
44
|
+
mLocationManager = LocationManager.getInstance(context)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fun showUserLocation(showUserLocation: Boolean) {
|
|
48
|
+
mShowUserLocation = showUserLocation
|
|
49
|
+
stateChanged()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fun setFollowUserLocation(followUserLocation: Boolean) {
|
|
53
|
+
mFollowUserLocation = followUserLocation
|
|
54
|
+
stateChanged()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fun setCameraMode(@CameraMode.Mode cameraMode: Int) {
|
|
58
|
+
mLocationComponent?.cameraMode = cameraMode
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
fun setRenderMode(@RenderMode.Mode renderMode: Int) {
|
|
62
|
+
mRenderMode = renderMode
|
|
63
|
+
if (mShowingUserLocation) {
|
|
64
|
+
mLocationComponent?.renderMode = renderMode
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fun setPreferredFramesPerSecond(preferredFramesPerSecond: Int) {
|
|
69
|
+
if (preferredFramesPerSecond <= 0) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
mLocationComponent?.setMaxAnimationFps(preferredFramesPerSecond)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fun addOnCameraTrackingChangedListener(onCameraTrackingChangedListener: OnCameraTrackingChangedListener?) {
|
|
77
|
+
mOnCameraTrackingChangedListener?.let {
|
|
78
|
+
mLocationComponent?.removeOnCameraTrackingChangedListener(
|
|
79
|
+
it
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
mOnCameraTrackingChangedListener = onCameraTrackingChangedListener
|
|
84
|
+
|
|
85
|
+
mOnCameraTrackingChangedListener?.let { mLocationComponent?.addOnCameraTrackingChangedListener(it) }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@SuppressLint("MissingPermission")
|
|
89
|
+
private fun stateChanged() {
|
|
90
|
+
mLocationComponent?.setLocationComponentEnabled((mFollowUserLocation || mShowUserLocation))
|
|
91
|
+
|
|
92
|
+
if (mShowingUserLocation != mShowUserLocation) {
|
|
93
|
+
updateShowUserLocation(mShowUserLocation)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (mFollowUserLocation) {
|
|
97
|
+
if (!mShowUserLocation) {
|
|
98
|
+
mLocationComponent?.renderMode = RenderMode.GPS
|
|
99
|
+
} else {
|
|
100
|
+
mLocationComponent?.renderMode = mRenderMode
|
|
101
|
+
}
|
|
102
|
+
mLocationComponent?.onStart()
|
|
103
|
+
} else {
|
|
104
|
+
mLocationComponent?.cameraMode = CameraMode.NONE
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
fun hasLocationComponent(): Boolean {
|
|
109
|
+
return (mLocationComponent != null)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
fun update(style: Style) {
|
|
113
|
+
update(mShowUserLocation, style)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
fun update(displayUserLocation: Boolean, style: Style) {
|
|
117
|
+
val tintColor = mMapView?.tintColor
|
|
118
|
+
|
|
119
|
+
if (mLocationComponent == null || tintColor != null) {
|
|
120
|
+
mLocationComponent = mMap?.locationComponent
|
|
121
|
+
|
|
122
|
+
val locationComponentActivationOptions: LocationComponentActivationOptions =
|
|
123
|
+
LocationComponentActivationOptions.builder(context, style)
|
|
124
|
+
.locationComponentOptions(options(displayUserLocation)).build()
|
|
125
|
+
mLocationComponent?.activateLocationComponent(locationComponentActivationOptions)
|
|
126
|
+
mLocationComponent?.locationEngine = mLocationManager!!.engine
|
|
127
|
+
mShowingUserLocation = displayUserLocation
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
updateShowUserLocation(displayUserLocation)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private fun updateShowUserLocation(displayUserLocation: Boolean) {
|
|
134
|
+
if (mShowingUserLocation != displayUserLocation) {
|
|
135
|
+
mLocationComponent?.applyStyle(options(displayUserLocation))
|
|
136
|
+
mShowingUserLocation = displayUserLocation
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
fun options(displayUserLocation: Boolean): LocationComponentOptions {
|
|
141
|
+
var builder: LocationComponentOptions.Builder = LocationComponentOptions.builder(context)
|
|
142
|
+
val tintColor = mMapView?.tintColor
|
|
143
|
+
if (!displayUserLocation) {
|
|
144
|
+
builder = builder.padding(mMap?.getPadding()).backgroundDrawable(R.drawable.empty)
|
|
145
|
+
.backgroundDrawableStale(R.drawable.empty).bearingDrawable(R.drawable.empty)
|
|
146
|
+
.foregroundDrawable(R.drawable.empty).foregroundDrawableStale(R.drawable.empty)
|
|
147
|
+
.gpsDrawable(R.drawable.empty).accuracyAlpha(0.0f)
|
|
148
|
+
} else if (tintColor != null) {
|
|
149
|
+
builder = builder.enableStaleState(false).bearingTintColor(tintColor)
|
|
150
|
+
.foregroundTintColor(tintColor).accuracyColor(tintColor)
|
|
151
|
+
}
|
|
152
|
+
return builder.build()
|
|
153
|
+
}
|
|
154
|
+
}
|
package/android/src/main/java/org/maplibre/reactnative/components/location/MLRNNativeUserLocation.kt
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
package org.maplibre.reactnative.components.location
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import org.maplibre.android.location.modes.RenderMode
|
|
6
|
+
import org.maplibre.android.location.permissions.PermissionsManager
|
|
7
|
+
import org.maplibre.android.maps.MapLibreMap
|
|
8
|
+
import org.maplibre.android.maps.OnMapReadyCallback
|
|
9
|
+
import org.maplibre.android.maps.Style
|
|
10
|
+
import org.maplibre.android.maps.Style.OnStyleLoaded
|
|
11
|
+
import org.maplibre.reactnative.components.AbstractMapFeature
|
|
12
|
+
import org.maplibre.reactnative.components.mapview.MLRNMapView
|
|
13
|
+
|
|
14
|
+
class MLRNNativeUserLocation(context: Context?) : AbstractMapFeature(context), OnMapReadyCallback,
|
|
15
|
+
OnStyleLoaded {
|
|
16
|
+
private var enabled = true
|
|
17
|
+
private var map: MapLibreMap? = null
|
|
18
|
+
private var mapView: MLRNMapView? = null
|
|
19
|
+
|
|
20
|
+
@RenderMode.Mode
|
|
21
|
+
private var mRenderMode = RenderMode.COMPASS
|
|
22
|
+
private var mPreferredFramesPerSecond = 0
|
|
23
|
+
|
|
24
|
+
override fun addToMap(mapView: MLRNMapView) {
|
|
25
|
+
enabled = true
|
|
26
|
+
this.mapView = mapView
|
|
27
|
+
mapView.getMapAsync(this)
|
|
28
|
+
setRenderMode(mRenderMode)
|
|
29
|
+
setPreferredFramesPerSecond(mPreferredFramesPerSecond)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override fun removeFromMap(mapView: MLRNMapView?) {
|
|
33
|
+
enabled = false
|
|
34
|
+
if (map != null) map!!.getStyle(this)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@SuppressLint("MissingPermission")
|
|
38
|
+
override fun onMapReady(mapLibreMap: MapLibreMap) {
|
|
39
|
+
map = mapLibreMap
|
|
40
|
+
mapLibreMap.getStyle(this)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@SuppressLint("MissingPermission")
|
|
44
|
+
override fun onStyleLoaded(style: Style) {
|
|
45
|
+
val context = getContext()
|
|
46
|
+
if (!PermissionsManager.areLocationPermissionsGranted(context)) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
val locationComponent = mapView!!.locationComponentManager
|
|
51
|
+
locationComponent.update(style)
|
|
52
|
+
locationComponent.showUserLocation(enabled)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fun setRenderMode(@RenderMode.Mode renderMode: Int) {
|
|
56
|
+
mRenderMode = renderMode
|
|
57
|
+
if (mapView != null) {
|
|
58
|
+
val locationComponent = mapView!!.locationComponentManager
|
|
59
|
+
locationComponent.setRenderMode(renderMode)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fun setPreferredFramesPerSecond(framesPerSecond: Int) {
|
|
64
|
+
mPreferredFramesPerSecond = framesPerSecond
|
|
65
|
+
if (mapView != null) {
|
|
66
|
+
val locationComponent = mapView!!.locationComponentManager
|
|
67
|
+
locationComponent.setPreferredFramesPerSecond(framesPerSecond)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
package org.maplibre.reactnative.components.location
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
6
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
7
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
8
|
+
import com.facebook.react.viewmanagers.MLRNNativeUserLocationManagerDelegate
|
|
9
|
+
import com.facebook.react.viewmanagers.MLRNNativeUserLocationManagerInterface
|
|
10
|
+
import org.maplibre.android.location.modes.RenderMode
|
|
11
|
+
|
|
12
|
+
@ReactModule(name = MLRNNativeUserLocationManager.REACT_CLASS)
|
|
13
|
+
class MLRNNativeUserLocationManager() :
|
|
14
|
+
ViewGroupManager<MLRNNativeUserLocation>(),
|
|
15
|
+
MLRNNativeUserLocationManagerInterface<MLRNNativeUserLocation> {
|
|
16
|
+
private val delegate: MLRNNativeUserLocationManagerDelegate<MLRNNativeUserLocation, MLRNNativeUserLocationManager> =
|
|
17
|
+
MLRNNativeUserLocationManagerDelegate(this)
|
|
18
|
+
|
|
19
|
+
override fun getDelegate(): ViewManagerDelegate<MLRNNativeUserLocation> = delegate
|
|
20
|
+
|
|
21
|
+
companion object {
|
|
22
|
+
const val REACT_CLASS: String = "MLRNNativeUserLocation"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override fun getName(): String = REACT_CLASS
|
|
26
|
+
|
|
27
|
+
override fun createViewInstance(context: ThemedReactContext): MLRNNativeUserLocation {
|
|
28
|
+
return MLRNNativeUserLocation(context)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@ReactProp(name = "mode")
|
|
32
|
+
override fun setMode(userLocation: MLRNNativeUserLocation, mode: String?) {
|
|
33
|
+
if ("heading".equals(mode, ignoreCase = true)) {
|
|
34
|
+
userLocation.setRenderMode(RenderMode.COMPASS)
|
|
35
|
+
} else if ("course".equals(mode, ignoreCase = true)) {
|
|
36
|
+
userLocation.setRenderMode(RenderMode.GPS)
|
|
37
|
+
} else {
|
|
38
|
+
userLocation.setRenderMode(RenderMode.NORMAL)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactProp(name = "androidPreferredFramesPerSecond")
|
|
43
|
+
override fun setAndroidPreferredFramesPerSecond(
|
|
44
|
+
userLocation: MLRNNativeUserLocation, preferredFramesPerSecond: Int
|
|
45
|
+
) {
|
|
46
|
+
userLocation.setPreferredFramesPerSecond(preferredFramesPerSecond)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
}
|
|
@@ -134,15 +134,31 @@ class MLRNLocationModule(reactContext: ReactApplicationContext) :
|
|
|
134
134
|
|
|
135
135
|
coords.putDouble("longitude", location.longitude)
|
|
136
136
|
coords.putDouble("latitude", location.latitude)
|
|
137
|
-
coords.putDouble("altitude", location.altitude)
|
|
138
137
|
coords.putDouble("accuracy", location.accuracy.toDouble())
|
|
139
|
-
|
|
138
|
+
|
|
139
|
+
if (location.hasAltitude()) {
|
|
140
|
+
coords.putDouble("altitude", location.altitude)
|
|
141
|
+
} else {
|
|
142
|
+
coords.putNull("altitude")
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && location.hasVerticalAccuracy()) {
|
|
140
146
|
coords.putDouble("altitudeAccuracy", location.verticalAccuracyMeters.toDouble())
|
|
141
147
|
} else {
|
|
142
148
|
coords.putNull("altitudeAccuracy")
|
|
143
149
|
}
|
|
144
|
-
|
|
145
|
-
|
|
150
|
+
|
|
151
|
+
if (location.hasBearing()) {
|
|
152
|
+
coords.putDouble("heading", location.bearing.toDouble())
|
|
153
|
+
} else {
|
|
154
|
+
coords.putNull("heading")
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (location.hasSpeed()) {
|
|
158
|
+
coords.putDouble("speed", location.speed.toDouble())
|
|
159
|
+
} else {
|
|
160
|
+
coords.putNull("speed")
|
|
161
|
+
}
|
|
146
162
|
|
|
147
163
|
val geolocationPosition: WritableMap = WritableNativeMap()
|
|
148
164
|
geolocationPosition.putMap("coords", coords)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
package org.maplibre.reactnative.modules
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.facebook.react.bridge.Arguments
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import org.maplibre.android.log.Logger
|
|
7
|
+
import org.maplibre.android.log.LoggerDefinition
|
|
8
|
+
import org.maplibre.reactnative.NativeLogModuleSpec
|
|
9
|
+
|
|
10
|
+
class MLRNLogModule(reactContext: ReactApplicationContext) : NativeLogModuleSpec(
|
|
11
|
+
reactContext
|
|
12
|
+
) {
|
|
13
|
+
|
|
14
|
+
companion object {
|
|
15
|
+
const val NAME: String = "MLRNLogModule"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override fun getName() = NAME
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
init {
|
|
22
|
+
Logger.setVerbosity(Logger.WARN)
|
|
23
|
+
|
|
24
|
+
Logger.setLoggerDefinition(object : LoggerDefinition {
|
|
25
|
+
override fun v(tag: String, msg: String) {
|
|
26
|
+
Log.v(tag, msg)
|
|
27
|
+
onLog("verbose", tag, msg)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun v(tag: String, msg: String, tr: Throwable) {
|
|
31
|
+
Log.v(tag, msg, tr)
|
|
32
|
+
onLog("verbose", tag, msg)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun d(tag: String, msg: String) {
|
|
36
|
+
Log.d(tag, msg)
|
|
37
|
+
onLog("debug", tag, msg)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override fun d(tag: String, msg: String, tr: Throwable) {
|
|
41
|
+
Log.d(tag, msg, tr)
|
|
42
|
+
onLog("debug", tag, msg)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override fun i(tag: String, msg: String) {
|
|
46
|
+
Log.i(tag, msg)
|
|
47
|
+
onLog("info", tag, msg)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
override fun i(tag: String, msg: String, tr: Throwable) {
|
|
51
|
+
Log.i(tag, msg, tr)
|
|
52
|
+
onLog("info", tag, msg)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override fun w(tag: String, msg: String) {
|
|
56
|
+
Log.w(tag, msg)
|
|
57
|
+
onLog("warn", tag, msg)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override fun w(tag: String, msg: String, tr: Throwable) {
|
|
61
|
+
Log.w(tag, msg, tr)
|
|
62
|
+
onLog("warn", tag, msg)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override fun e(tag: String, msg: String) {
|
|
66
|
+
Log.e(tag, msg)
|
|
67
|
+
onLog("error", tag, msg)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override fun e(tag: String, msg: String, tr: Throwable) {
|
|
71
|
+
Log.e(tag, msg, tr)
|
|
72
|
+
onLog("error", tag, msg)
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
override fun setLogLevel(level: String) {
|
|
79
|
+
@Logger.LogLevel val logLevel = when (level) {
|
|
80
|
+
"error" -> Logger.ERROR
|
|
81
|
+
"warn" -> Logger.WARN
|
|
82
|
+
"info" -> Logger.INFO
|
|
83
|
+
"debug" -> Logger.DEBUG
|
|
84
|
+
"verbose" -> Logger.VERBOSE
|
|
85
|
+
else -> Logger.NONE
|
|
86
|
+
}
|
|
87
|
+
Logger.setVerbosity(logLevel)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
fun onLog(level: String, tag: String, msg: String) {
|
|
92
|
+
val event = Arguments.createMap()
|
|
93
|
+
event.putString("level", level)
|
|
94
|
+
event.putString("tag", tag)
|
|
95
|
+
event.putString("message", msg)
|
|
96
|
+
|
|
97
|
+
emitOnLog(event)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
#import <React/RCTViewComponentView.h>
|
|
2
2
|
#import <UIKit/UIKit.h>
|
|
3
3
|
|
|
4
|
-
#import <React/RCTUIManager.h>
|
|
5
|
-
#import <React/RCTViewComponentView.h>
|
|
6
|
-
|
|
7
|
-
#ifndef MLRNCameraComponentView_h
|
|
8
|
-
#define MLRNCameraComponentView_h
|
|
9
|
-
|
|
10
4
|
NS_ASSUME_NONNULL_BEGIN
|
|
11
5
|
|
|
12
6
|
@interface MLRNCameraComponentView : RCTViewComponentView
|
|
@@ -14,5 +8,3 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
14
8
|
@end
|
|
15
9
|
|
|
16
10
|
NS_ASSUME_NONNULL_END
|
|
17
|
-
|
|
18
|
-
#endif
|
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
#import <React/RCTUIManager.h>
|
|
5
5
|
#import <React/RCTViewComponentView.h>
|
|
6
6
|
|
|
7
|
-
#ifndef MLRNMapViewComponentView_h
|
|
8
|
-
#define MLRNMapViewComponentView_h
|
|
9
|
-
|
|
10
7
|
NS_ASSUME_NONNULL_BEGIN
|
|
11
8
|
|
|
12
9
|
@interface MLRNMapViewComponentView : RCTViewComponentView
|
|
@@ -14,5 +11,3 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
14
11
|
@end
|
|
15
12
|
|
|
16
13
|
NS_ASSUME_NONNULL_END
|
|
17
|
-
|
|
18
|
-
#endif
|
|
@@ -17,20 +17,21 @@
|
|
|
17
17
|
_map.showsUserHeadingIndicator = NO;
|
|
18
18
|
} else if (map) {
|
|
19
19
|
map.useNativeUserLocationAnnotationView = YES;
|
|
20
|
-
// Toggle off/on showsUserLocation in order for
|
|
20
|
+
// Toggle off/on showsUserLocation in order for MapLibre Native to invalidate the
|
|
21
21
|
// current (hidden) user location annotation view. See also: HiddenUserLocationAnnotationView
|
|
22
22
|
map.showsUserLocation = NO;
|
|
23
23
|
map.showsUserLocation = YES;
|
|
24
|
-
map.showsUserHeadingIndicator = self.
|
|
24
|
+
map.showsUserHeadingIndicator = self.showsUserHeadingIndicator;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
_map = map;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
- (void)
|
|
31
|
-
|
|
30
|
+
- (void)setShowsUserHeadingIndicator:(BOOL)showsUserHeadingIndicator {
|
|
31
|
+
_showsUserHeadingIndicator = showsUserHeadingIndicator;
|
|
32
|
+
|
|
32
33
|
if (_map) {
|
|
33
|
-
_map.showsUserHeadingIndicator =
|
|
34
|
+
_map.showsUserHeadingIndicator = showsUserHeadingIndicator;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#import "MLRNNativeUserLocationComponentView.h"
|
|
2
|
+
|
|
3
|
+
#import <react/renderer/components/MapLibreReactNativeSpec/ComponentDescriptors.h>
|
|
4
|
+
#import <react/renderer/components/MapLibreReactNativeSpec/Props.h>
|
|
5
|
+
#import <react/renderer/components/MapLibreReactNativeSpec/RCTComponentViewHelpers.h>
|
|
6
|
+
|
|
7
|
+
#import "MLRNNativeUserLocation.h"
|
|
8
|
+
|
|
9
|
+
using namespace facebook::react;
|
|
10
|
+
|
|
11
|
+
@interface MLRNNativeUserLocationComponentView () <RCTMLRNNativeUserLocationViewProtocol>
|
|
12
|
+
|
|
13
|
+
@end
|
|
14
|
+
|
|
15
|
+
@implementation MLRNNativeUserLocationComponentView {
|
|
16
|
+
MLRNNativeUserLocation *_view;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
20
|
+
if (self = [super initWithFrame:frame]) {
|
|
21
|
+
static const auto defaultProps = std::make_shared<const MLRNNativeUserLocationProps>();
|
|
22
|
+
_props = defaultProps;
|
|
23
|
+
[self prepareView];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return self;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
- (void)prepareView {
|
|
30
|
+
_view = [[MLRNNativeUserLocation alloc] init];
|
|
31
|
+
self.contentView = _view;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#pragma mark - RCTComponentViewProtocol
|
|
35
|
+
|
|
36
|
+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
|
|
37
|
+
const auto &oldViewProps = *std::static_pointer_cast<MLRNNativeUserLocationProps const>(_props);
|
|
38
|
+
const auto &newViewProps = *std::static_pointer_cast<MLRNNativeUserLocationProps const>(props);
|
|
39
|
+
|
|
40
|
+
if (oldViewProps.mode != newViewProps.mode) {
|
|
41
|
+
[_view setShowsUserHeadingIndicator:newViewProps.mode != MLRNNativeUserLocationMode::Default];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
[super updateProps:props oldProps:oldProps];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
48
|
+
return concreteComponentDescriptorProvider<MLRNNativeUserLocationComponentDescriptor>();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@end
|
|
@@ -2,22 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
@implementation MLRNLocation
|
|
4
4
|
|
|
5
|
-
- (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
NSMutableDictionary<NSString *, NSNumber *> *coords = [[NSMutableDictionary alloc] init];
|
|
9
|
-
coords[@"longitude"] = @(_location.coordinate.longitude);
|
|
10
|
-
coords[@"latitude"] = @(_location.coordinate.latitude);
|
|
11
|
-
coords[@"accuracy"] = @(_location.horizontalAccuracy);
|
|
12
|
-
coords[@"altitude"] = @(_location.altitude);
|
|
13
|
-
coords[@"altitudeAccuracy"] = @(_location.verticalAccuracy);
|
|
14
|
-
coords[@"heading"] = @(_location.course);
|
|
15
|
-
coords[@"speed"] = @(_location.speed);
|
|
5
|
+
- (id)numberOrNull:(double)value {
|
|
6
|
+
return value < 0 ? [NSNull null] : @(value);
|
|
7
|
+
}
|
|
16
8
|
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
- (NSDictionary<NSString *, id> *)toJSON {
|
|
10
|
+
double altitudeAccuracy = _location.verticalAccuracy;
|
|
19
11
|
|
|
20
|
-
return
|
|
12
|
+
return @{
|
|
13
|
+
@"coords" : @{
|
|
14
|
+
@"longitude" : @(_location.coordinate.longitude),
|
|
15
|
+
@"latitude" : @(_location.coordinate.latitude),
|
|
16
|
+
@"accuracy" : @(_location.horizontalAccuracy),
|
|
17
|
+
@"altitude" : altitudeAccuracy < 0 ? [NSNull null] : @(_location.altitude),
|
|
18
|
+
@"altitudeAccuracy" : [self numberOrNull:altitudeAccuracy],
|
|
19
|
+
@"heading" : [self numberOrNull:_location.course],
|
|
20
|
+
@"speed" : [self numberOrNull:_location.speed]
|
|
21
|
+
},
|
|
22
|
+
@"timestamp" : @([_location.timestamp timeIntervalSince1970])
|
|
23
|
+
};
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
@end
|