@rnmapbox/maps 10.0.0-beta.58 → 10.0.0-beta.60
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/build.gradle +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCamera.kt +5 -96
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCameraManager.kt +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/LocationComponentManager.kt +125 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/RCTMGLNativeUserLocation.kt +6 -10
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/RenderMode.kt +21 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +36 -72
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapViewManager.kt +10 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/RCTMGLStyleFactory.java +26 -5
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTLayer.kt +2 -7
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/LocationEvent.kt +75 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/location/LocationManager.kt +66 -12
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLLocationModule.kt +147 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/CoordinateBounds.kt +3 -9
- package/ios/RCTMGL/RCTMGLLocation.m +1 -1
- package/ios/RCTMGL-v10/RCTMGLBackgroundLayer.swift +3 -1
- package/ios/RCTMGL-v10/RCTMGLCircleLayer.swift +3 -1
- package/ios/RCTMGL-v10/RCTMGLFillExtrustionLayer.swift +3 -1
- package/ios/RCTMGL-v10/RCTMGLFillLayer.swift +3 -1
- package/ios/RCTMGL-v10/RCTMGLHeatmapLayer.swift +3 -1
- package/ios/RCTMGL-v10/RCTMGLLayer.swift +0 -2
- package/ios/RCTMGL-v10/RCTMGLLineLayer.swift +3 -1
- package/ios/RCTMGL-v10/RCTMGLLocationModule.swift +1 -1
- package/ios/RCTMGL-v10/RCTMGLLogging.swift +10 -2
- package/ios/RCTMGL-v10/RCTMGLRasterLayer.swift +3 -1
- package/ios/RCTMGL-v10/RCTMGLSkyLayer.swift +3 -1
- package/ios/RCTMGL-v10/RCTMGLStyle.swift +25 -15
- package/ios/RCTMGL-v10/RCTMGLSymbolLayer.swift +3 -1
- package/{assets → javascript/assets}/heading.png +0 -0
- package/{assets → javascript/assets}/heading@2x.png +0 -0
- package/{assets → javascript/assets}/heading@3x.png +0 -0
- package/javascript/components/Camera.tsx +1 -1
- package/javascript/components/HeadingIndicator.tsx +1 -1
- package/lib/commonjs/assets/heading.png +0 -0
- package/lib/commonjs/assets/heading@2x.png +0 -0
- package/lib/commonjs/assets/heading@3x.png +0 -0
- package/lib/commonjs/classes/AnimatedExtractCoordinateFromArray.js +3 -1
- package/lib/commonjs/classes/AnimatedExtractCoordinateFromArray.js.map +1 -1
- package/lib/commonjs/components/AbstractLayer.js +3 -1
- package/lib/commonjs/components/AbstractLayer.js.map +1 -1
- package/lib/commonjs/components/AbstractSource.js +3 -1
- package/lib/commonjs/components/AbstractSource.js.map +1 -1
- package/lib/commonjs/components/BackgroundLayer.js +3 -1
- package/lib/commonjs/components/BackgroundLayer.js.map +1 -1
- package/lib/commonjs/components/Callout.js +3 -1
- package/lib/commonjs/components/Callout.js.map +1 -1
- package/lib/commonjs/components/Camera.js.map +1 -1
- package/lib/commonjs/components/CircleLayer.js +3 -1
- package/lib/commonjs/components/CircleLayer.js.map +1 -1
- package/lib/commonjs/components/FillExtrusionLayer.js +3 -1
- package/lib/commonjs/components/FillExtrusionLayer.js.map +1 -1
- package/lib/commonjs/components/FillLayer.js +3 -1
- package/lib/commonjs/components/FillLayer.js.map +1 -1
- package/lib/commonjs/components/HeadingIndicator.js +1 -1
- package/lib/commonjs/components/HeatmapLayer.js +3 -1
- package/lib/commonjs/components/HeatmapLayer.js.map +1 -1
- package/lib/commonjs/components/ImageSource.js +3 -1
- package/lib/commonjs/components/ImageSource.js.map +1 -1
- package/lib/commonjs/components/Images.js +3 -1
- package/lib/commonjs/components/Images.js.map +1 -1
- package/lib/commonjs/components/Light.js +3 -1
- package/lib/commonjs/components/Light.js.map +1 -1
- package/lib/commonjs/components/LineLayer.js +3 -1
- package/lib/commonjs/components/LineLayer.js.map +1 -1
- package/lib/commonjs/components/MapView.js +3 -1
- package/lib/commonjs/components/MapView.js.map +1 -1
- package/lib/commonjs/components/MarkerView.js +3 -1
- package/lib/commonjs/components/MarkerView.js.map +1 -1
- package/lib/commonjs/components/NativeBridgeComponent.js +3 -1
- package/lib/commonjs/components/NativeBridgeComponent.js.map +1 -1
- package/lib/commonjs/components/NativeUserLocation.js +3 -1
- package/lib/commonjs/components/NativeUserLocation.js.map +1 -1
- package/lib/commonjs/components/PointAnnotation.js +3 -1
- package/lib/commonjs/components/PointAnnotation.js.map +1 -1
- package/lib/commonjs/components/RasterDemSource.js +3 -1
- package/lib/commonjs/components/RasterDemSource.js.map +1 -1
- package/lib/commonjs/components/RasterLayer.js +3 -1
- package/lib/commonjs/components/RasterLayer.js.map +1 -1
- package/lib/commonjs/components/RasterSource.js +3 -1
- package/lib/commonjs/components/RasterSource.js.map +1 -1
- package/lib/commonjs/components/ShapeSource.js +3 -1
- package/lib/commonjs/components/ShapeSource.js.map +1 -1
- package/lib/commonjs/components/SkyLayer.js +3 -1
- package/lib/commonjs/components/SkyLayer.js.map +1 -1
- package/lib/commonjs/components/SymbolLayer.js +3 -1
- package/lib/commonjs/components/SymbolLayer.js.map +1 -1
- package/lib/commonjs/components/UserLocation.js +3 -1
- package/lib/commonjs/components/UserLocation.js.map +1 -1
- package/lib/commonjs/components/VectorSource.js +3 -1
- package/lib/commonjs/components/VectorSource.js.map +1 -1
- package/lib/commonjs/components/annotations/Annotation.js +3 -1
- package/lib/commonjs/components/annotations/Annotation.js.map +1 -1
- package/lib/commonjs/utils/BridgeValue.js +3 -1
- package/lib/commonjs/utils/BridgeValue.js.map +1 -1
- package/lib/commonjs/utils/Logger.js +3 -1
- package/lib/commonjs/utils/Logger.js.map +1 -1
- package/lib/commonjs/web/components/Camera.js +3 -1
- package/lib/commonjs/web/components/Camera.js.map +1 -1
- package/lib/commonjs/web/components/MapView.js +3 -1
- package/lib/commonjs/web/components/MapView.js.map +1 -1
- package/lib/commonjs/web/utils/Logger.js +3 -1
- package/lib/commonjs/web/utils/Logger.js.map +1 -1
- package/lib/module/assets/heading.png +0 -0
- package/lib/module/assets/heading@2x.png +0 -0
- package/lib/module/assets/heading@3x.png +0 -0
- package/lib/module/classes/AnimatedExtractCoordinateFromArray.js +3 -1
- package/lib/module/classes/AnimatedExtractCoordinateFromArray.js.map +1 -1
- package/lib/module/components/AbstractLayer.js +3 -1
- package/lib/module/components/AbstractLayer.js.map +1 -1
- package/lib/module/components/AbstractSource.js +3 -1
- package/lib/module/components/AbstractSource.js.map +1 -1
- package/lib/module/components/BackgroundLayer.js +3 -1
- package/lib/module/components/BackgroundLayer.js.map +1 -1
- package/lib/module/components/Callout.js +3 -1
- package/lib/module/components/Callout.js.map +1 -1
- package/lib/module/components/Camera.js.map +1 -1
- package/lib/module/components/CircleLayer.js +3 -1
- package/lib/module/components/CircleLayer.js.map +1 -1
- package/lib/module/components/FillExtrusionLayer.js +3 -1
- package/lib/module/components/FillExtrusionLayer.js.map +1 -1
- package/lib/module/components/FillLayer.js +3 -1
- package/lib/module/components/FillLayer.js.map +1 -1
- package/lib/module/components/HeadingIndicator.js +1 -1
- package/lib/module/components/HeadingIndicator.js.map +1 -1
- package/lib/module/components/HeatmapLayer.js +3 -1
- package/lib/module/components/HeatmapLayer.js.map +1 -1
- package/lib/module/components/ImageSource.js +3 -1
- package/lib/module/components/ImageSource.js.map +1 -1
- package/lib/module/components/Images.js +3 -1
- package/lib/module/components/Images.js.map +1 -1
- package/lib/module/components/Light.js +3 -1
- package/lib/module/components/Light.js.map +1 -1
- package/lib/module/components/LineLayer.js +3 -1
- package/lib/module/components/LineLayer.js.map +1 -1
- package/lib/module/components/MapView.js +3 -1
- package/lib/module/components/MapView.js.map +1 -1
- package/lib/module/components/MarkerView.js +3 -1
- package/lib/module/components/MarkerView.js.map +1 -1
- package/lib/module/components/NativeBridgeComponent.js +3 -1
- package/lib/module/components/NativeBridgeComponent.js.map +1 -1
- package/lib/module/components/NativeUserLocation.js +3 -1
- package/lib/module/components/NativeUserLocation.js.map +1 -1
- package/lib/module/components/PointAnnotation.js +3 -1
- package/lib/module/components/PointAnnotation.js.map +1 -1
- package/lib/module/components/RasterDemSource.js +3 -1
- package/lib/module/components/RasterDemSource.js.map +1 -1
- package/lib/module/components/RasterLayer.js +3 -1
- package/lib/module/components/RasterLayer.js.map +1 -1
- package/lib/module/components/RasterSource.js +3 -1
- package/lib/module/components/RasterSource.js.map +1 -1
- package/lib/module/components/ShapeSource.js +3 -1
- package/lib/module/components/ShapeSource.js.map +1 -1
- package/lib/module/components/SkyLayer.js +3 -1
- package/lib/module/components/SkyLayer.js.map +1 -1
- package/lib/module/components/SymbolLayer.js +3 -1
- package/lib/module/components/SymbolLayer.js.map +1 -1
- package/lib/module/components/UserLocation.js +3 -1
- package/lib/module/components/UserLocation.js.map +1 -1
- package/lib/module/components/VectorSource.js +3 -1
- package/lib/module/components/VectorSource.js.map +1 -1
- package/lib/module/components/annotations/Annotation.js +3 -1
- package/lib/module/components/annotations/Annotation.js.map +1 -1
- package/lib/module/utils/BridgeValue.js +3 -1
- package/lib/module/utils/BridgeValue.js.map +1 -1
- package/lib/module/utils/Logger.js +3 -1
- package/lib/module/utils/Logger.js.map +1 -1
- package/lib/module/web/components/Camera.js +3 -1
- package/lib/module/web/components/Camera.js.map +1 -1
- package/lib/module/web/components/MapView.js +3 -1
- package/lib/module/web/components/MapView.js.map +1 -1
- package/lib/module/web/utils/Logger.js +3 -1
- package/lib/module/web/utils/Logger.js.map +1 -1
- package/lib/typescript/components/Camera.d.ts +1 -1
- package/lib/typescript/components/Camera.d.ts.map +1 -1
- package/package.json +6 -5
- package/plugin/build/generateCode.d.ts +42 -0
- package/plugin/build/generateCode.js +107 -0
- package/plugin/build/withMapbox.d.ts +1 -1
- package/plugin/build/withMapbox.js +3 -3
- package/plugin/src/generateCode.ts +155 -0
- package/plugin/src/withMapbox.ts +3 -5
- package/rnmapbox-maps.podspec +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/LocationComponentManager.java +0 -215
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/RenderMode.java +0 -42
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/LocationEvent.java +0 -100
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLLocationModule.java +0 -160
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
package com.mapbox.rctmgl.events
|
|
2
|
+
|
|
3
|
+
import android.location.Location
|
|
4
|
+
import com.facebook.react.bridge.Arguments
|
|
5
|
+
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
|
|
6
|
+
import com.mapbox.rctmgl.events.IEvent
|
|
7
|
+
import com.mapbox.rctmgl.events.constants.EventKeys
|
|
8
|
+
import com.mapbox.rctmgl.events.constants.EventTypes
|
|
9
|
+
import com.mapbox.rctmgl.events.LocationEvent
|
|
10
|
+
import com.facebook.react.bridge.WritableMap
|
|
11
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
12
|
+
import java.util.*
|
|
13
|
+
|
|
14
|
+
class LocationEvent(private val location: Location, private val mapView: RCTMGLMapView?) : IEvent {
|
|
15
|
+
val uUID: UUID
|
|
16
|
+
|
|
17
|
+
init {
|
|
18
|
+
uUID = UUID.randomUUID()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(location: Location) : this(location, null) {}
|
|
22
|
+
|
|
23
|
+
override fun getID(): Int {
|
|
24
|
+
return mapView?.id ?: -1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override fun getKey(): String {
|
|
28
|
+
return EventKeys.USER_LOCATION_UPDATE
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override fun getType(): String {
|
|
32
|
+
return EventTypes.USER_LOCATION_UPDATED
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun getTimestamp(): Long {
|
|
36
|
+
return System.currentTimeMillis()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override fun equals(event: IEvent): Boolean {
|
|
40
|
+
val other = event as LocationEvent
|
|
41
|
+
return uUID == other.uUID
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fun equals(event: LocationEvent): Boolean {
|
|
45
|
+
return uUID == event.uUID
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override fun getPayload(): WritableMap {
|
|
49
|
+
val positionProperties: WritableMap = WritableNativeMap()
|
|
50
|
+
val coords: WritableMap = WritableNativeMap()
|
|
51
|
+
coords.putDouble("longitude", location.longitude)
|
|
52
|
+
coords.putDouble("latitude", location.latitude)
|
|
53
|
+
coords.putDouble("altitude", location.altitude)
|
|
54
|
+
coords.putDouble("accuracy", location.accuracy.toDouble())
|
|
55
|
+
// A better solution will be to pull the heading from the compass engine,
|
|
56
|
+
// unfortunately the api is not publicly available in the mapbox sdk
|
|
57
|
+
coords.putDouble("heading", location.bearing.toDouble())
|
|
58
|
+
coords.putDouble("course", location.bearing.toDouble())
|
|
59
|
+
coords.putDouble("speed", location.speed.toDouble())
|
|
60
|
+
positionProperties.putMap("coords", coords)
|
|
61
|
+
positionProperties.putDouble("timestamp", location.time.toDouble())
|
|
62
|
+
return positionProperties
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override fun toJSON(): WritableMap {
|
|
66
|
+
val map = Arguments.createMap()
|
|
67
|
+
map.putString("type", type)
|
|
68
|
+
map.putMap("payload", payload)
|
|
69
|
+
return map
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
override fun canCoalesce(): Boolean {
|
|
73
|
+
return true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -10,16 +10,15 @@ import com.mapbox.android.core.location.LocationEngineCallback
|
|
|
10
10
|
import com.mapbox.android.core.location.LocationEngineResult
|
|
11
11
|
import com.mapbox.maps.plugin.locationcomponent.LocationConsumer
|
|
12
12
|
import com.mapbox.android.core.location.LocationEngineRequest
|
|
13
|
-
import com.mapbox.rctmgl.location.LocationProviderForEngine
|
|
14
13
|
import com.mapbox.android.core.location.LocationEngineProvider
|
|
15
14
|
import com.mapbox.android.core.permissions.PermissionsManager
|
|
16
15
|
import android.os.Looper
|
|
17
16
|
import android.util.Log
|
|
18
17
|
import com.mapbox.geojson.Point
|
|
19
18
|
import com.mapbox.maps.plugin.locationcomponent.LocationProvider
|
|
20
|
-
import java.lang.Exception
|
|
21
19
|
import java.lang.ref.WeakReference
|
|
22
20
|
import java.util.ArrayList
|
|
21
|
+
import kotlin.Exception
|
|
23
22
|
|
|
24
23
|
internal class LocationProviderForEngine(var mEngine: LocationEngine?) : LocationProvider, LocationEngineCallback<LocationEngineResult> {
|
|
25
24
|
var mConsumers = ArrayList<LocationConsumer>()
|
|
@@ -51,8 +50,8 @@ internal class LocationProviderForEngine(var mEngine: LocationEngine?) : Locatio
|
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
// * LocationEngineCallback
|
|
54
|
-
override fun onSuccess(locationEngineResult: LocationEngineResult) {
|
|
55
|
-
val location = locationEngineResult
|
|
53
|
+
override fun onSuccess(locationEngineResult: LocationEngineResult?) {
|
|
54
|
+
val location = locationEngineResult?.lastLocation
|
|
56
55
|
location?.let { notifyLocationUpdates(it) }
|
|
57
56
|
}
|
|
58
57
|
|
|
@@ -68,6 +67,11 @@ class LocationManager private constructor(private val context: Context) : Locati
|
|
|
68
67
|
private var lastLocation: Location? = null
|
|
69
68
|
private var locationEngineRequest: LocationEngineRequest? = null
|
|
70
69
|
private var locationProvider: LocationProviderForEngine? = null
|
|
70
|
+
private var nStarts : Int = 0;
|
|
71
|
+
private var isPaused : Boolean = false;
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
71
75
|
val provider: LocationProvider
|
|
72
76
|
get() {
|
|
73
77
|
if (locationProvider == null) {
|
|
@@ -80,6 +84,41 @@ class LocationManager private constructor(private val context: Context) : Locati
|
|
|
80
84
|
fun onLocationChange(location: Location?)
|
|
81
85
|
}
|
|
82
86
|
|
|
87
|
+
|
|
88
|
+
/// public interface
|
|
89
|
+
|
|
90
|
+
fun startCounted() {
|
|
91
|
+
nStarts += 1;
|
|
92
|
+
if (nStarts == 1) {
|
|
93
|
+
enable(false);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fun stopCounted() {
|
|
98
|
+
nStarts -= 1;
|
|
99
|
+
if (nStarts == 0) {
|
|
100
|
+
dispose();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fun pause() {
|
|
105
|
+
isPaused = true
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
fun resume() {
|
|
109
|
+
isPaused = false
|
|
110
|
+
if (nStarts > 0) {
|
|
111
|
+
enable(false)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
fun destroy() {
|
|
116
|
+
dispose();
|
|
117
|
+
nStarts = -1000;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
////
|
|
121
|
+
|
|
83
122
|
private fun buildEngineRequest() {
|
|
84
123
|
engine = LocationEngineProvider.getBestLocationEngine(context.applicationContext)
|
|
85
124
|
locationEngineRequest = LocationEngineRequest.Builder(DEFAULT_INTERVAL_MILLIS)
|
|
@@ -103,10 +142,14 @@ class LocationManager private constructor(private val context: Context) : Locati
|
|
|
103
142
|
|
|
104
143
|
fun setMinDisplacement(minDisplacement: Float) {
|
|
105
144
|
mMinDisplacement = minDisplacement
|
|
145
|
+
|
|
146
|
+
if (isActive) {
|
|
147
|
+
enable(true)
|
|
148
|
+
}
|
|
106
149
|
}
|
|
107
150
|
|
|
108
151
|
@SuppressLint("MissingPermission")
|
|
109
|
-
fun enable() {
|
|
152
|
+
private fun enable(refresh: Boolean) {
|
|
110
153
|
if (!PermissionsManager.areLocationPermissionsGranted(context)) {
|
|
111
154
|
return
|
|
112
155
|
}
|
|
@@ -126,17 +169,16 @@ class LocationManager private constructor(private val context: Context) : Locati
|
|
|
126
169
|
isActive = true
|
|
127
170
|
}
|
|
128
171
|
|
|
129
|
-
fun disable() {
|
|
172
|
+
private fun disable() {
|
|
130
173
|
engine?.removeLocationUpdates(this)
|
|
131
174
|
isActive = false
|
|
132
175
|
}
|
|
133
176
|
|
|
134
|
-
fun dispose() {
|
|
177
|
+
private fun dispose() {
|
|
135
178
|
if (engine == null) {
|
|
136
179
|
return
|
|
137
180
|
}
|
|
138
181
|
disable()
|
|
139
|
-
engine?.removeLocationUpdates(this)
|
|
140
182
|
}
|
|
141
183
|
|
|
142
184
|
fun isActive(): Boolean {
|
|
@@ -149,12 +191,24 @@ class LocationManager private constructor(private val context: Context) : Locati
|
|
|
149
191
|
} else lastLocation
|
|
150
192
|
|
|
151
193
|
@SuppressLint("MissingPermission")
|
|
152
|
-
fun getLastKnownLocation(callback: LocationEngineCallback<LocationEngineResult
|
|
194
|
+
fun getLastKnownLocation(callback: LocationEngineCallback<LocationEngineResult>) {
|
|
153
195
|
if (engine == null) {
|
|
154
196
|
callback.onFailure(Exception("LocationEngine not initialized"))
|
|
155
197
|
}
|
|
156
198
|
try {
|
|
157
|
-
engine?.getLastLocation(
|
|
199
|
+
engine?.getLastLocation(object : LocationEngineCallback<LocationEngineResult> {
|
|
200
|
+
override fun onSuccess(result: LocationEngineResult?) {
|
|
201
|
+
if (result == null) {
|
|
202
|
+
callback.onFailure( NullPointerException("LocationEngineResult is null"))
|
|
203
|
+
} else {
|
|
204
|
+
callback.onSuccess(result)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
override fun onFailure(exception: Exception) {
|
|
209
|
+
callback.onFailure(exception)
|
|
210
|
+
}
|
|
211
|
+
})
|
|
158
212
|
} catch (exception: Exception) {
|
|
159
213
|
Log.w(LOG_TAG, exception)
|
|
160
214
|
callback.onFailure(exception)
|
|
@@ -172,8 +226,8 @@ class LocationManager private constructor(private val context: Context) : Locati
|
|
|
172
226
|
// FMTODO handle this.
|
|
173
227
|
}
|
|
174
228
|
|
|
175
|
-
override fun onSuccess(result: LocationEngineResult) {
|
|
176
|
-
onLocationChanged(result
|
|
229
|
+
override fun onSuccess(result: LocationEngineResult?) {
|
|
230
|
+
onLocationChanged(result?.lastLocation)
|
|
177
231
|
if (locationProvider != null) {
|
|
178
232
|
locationProvider!!.onSuccess(result)
|
|
179
233
|
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
package com.mapbox.rctmgl.modules
|
|
2
|
+
|
|
3
|
+
import android.location.Location
|
|
4
|
+
import com.facebook.react.bridge.*
|
|
5
|
+
import com.mapbox.rctmgl.location.LocationManager
|
|
6
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
7
|
+
import com.mapbox.rctmgl.location.LocationManager.OnUserLocationChange
|
|
8
|
+
import com.mapbox.rctmgl.events.LocationEvent
|
|
9
|
+
import com.mapbox.android.core.location.LocationEngineCallback
|
|
10
|
+
import com.mapbox.android.core.location.LocationEngineResult
|
|
11
|
+
import com.mapbox.rctmgl.events.EventEmitter
|
|
12
|
+
import com.mapbox.rctmgl.location.LocationManager.Companion.getInstance
|
|
13
|
+
import java.lang.Exception
|
|
14
|
+
|
|
15
|
+
@ReactModule(name = RCTMGLLocationModule.REACT_CLASS)
|
|
16
|
+
class RCTMGLLocationModule(reactContext: ReactApplicationContext) :
|
|
17
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
18
|
+
private var isEnabled = false
|
|
19
|
+
private var mMinDisplacement = 0f
|
|
20
|
+
private val locationManager: LocationManager? = getInstance(reactContext)
|
|
21
|
+
private var mLastLocation: Location? = null
|
|
22
|
+
|
|
23
|
+
private val lifecycleEventListener: LifecycleEventListener = object : LifecycleEventListener {
|
|
24
|
+
override fun onHostResume() {
|
|
25
|
+
if (isEnabled) {
|
|
26
|
+
locationManager?.resume()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun onHostPause() {
|
|
31
|
+
locationManager?.pause()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override fun onHostDestroy() {
|
|
35
|
+
locationManager?.destroy()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private val onUserLocationChangeCallback: OnUserLocationChange = object : OnUserLocationChange {
|
|
40
|
+
override fun onLocationChange(location: Location?) {
|
|
41
|
+
var changed = (mLastLocation != null) != (location != null)
|
|
42
|
+
val lastLocation = mLastLocation
|
|
43
|
+
if (lastLocation != null && location != null) {
|
|
44
|
+
if (
|
|
45
|
+
lastLocation.latitude != location.latitude ||
|
|
46
|
+
lastLocation.longitude != location.longitude ||
|
|
47
|
+
lastLocation.altitude != location.altitude ||
|
|
48
|
+
lastLocation.accuracy != location.accuracy ||
|
|
49
|
+
lastLocation.bearing != location.bearing
|
|
50
|
+
) {
|
|
51
|
+
changed = true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
mLastLocation = location
|
|
55
|
+
if (changed && (location != null)) {
|
|
56
|
+
val locationEvent = LocationEvent(location)
|
|
57
|
+
val emitter = EventEmitter.getModuleEmitter(reactApplicationContext)
|
|
58
|
+
emitter?.emit(LOCATION_UPDATE, locationEvent.payload)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
init {
|
|
64
|
+
reactContext.addLifecycleEventListener(lifecycleEventListener)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
override fun getName(): String {
|
|
68
|
+
return REACT_CLASS
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@ReactMethod
|
|
72
|
+
fun start(minDisplacement: Float) {
|
|
73
|
+
isEnabled = true
|
|
74
|
+
mMinDisplacement = minDisplacement
|
|
75
|
+
locationManager?.startCounted()
|
|
76
|
+
startLocationManager()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@ReactMethod
|
|
80
|
+
fun setMinDisplacement(minDisplacement: Float) {
|
|
81
|
+
if (mMinDisplacement == minDisplacement) return
|
|
82
|
+
mMinDisplacement = minDisplacement
|
|
83
|
+
if (isEnabled) {
|
|
84
|
+
|
|
85
|
+
// set minimal displacement in the manager
|
|
86
|
+
locationManager!!.setMinDisplacement(mMinDisplacement)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@ReactMethod
|
|
91
|
+
fun stop() {
|
|
92
|
+
stopLocationManager()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@ReactMethod
|
|
96
|
+
fun getLastKnownLocation(promise: Promise) {
|
|
97
|
+
locationManager!!.getLastKnownLocation(
|
|
98
|
+
object : LocationEngineCallback<LocationEngineResult> {
|
|
99
|
+
override fun onSuccess(result: LocationEngineResult) {
|
|
100
|
+
val location = result.lastLocation
|
|
101
|
+
if (location != null) {
|
|
102
|
+
val locationEvent = LocationEvent(location)
|
|
103
|
+
promise.resolve(locationEvent.payload)
|
|
104
|
+
} else {
|
|
105
|
+
promise.resolve(null)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
override fun onFailure(exception: Exception) {
|
|
110
|
+
promise.reject(exception)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@ReactMethod
|
|
117
|
+
fun addListener(eventName: String?) {
|
|
118
|
+
// Required for rn built in EventEmitter Calls.
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@ReactMethod
|
|
122
|
+
fun removeListeners(count: Int?) {
|
|
123
|
+
// Required for rn built in EventEmitter Calls.
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private fun startLocationManager() {
|
|
127
|
+
mLastLocation = null;
|
|
128
|
+
locationManager!!.addLocationListener(onUserLocationChangeCallback)
|
|
129
|
+
locationManager.setMinDisplacement(mMinDisplacement)
|
|
130
|
+
locationManager.startCounted()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private fun stopLocationManager() {
|
|
134
|
+
if (!isEnabled) {
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
locationManager!!.removeLocationListener(onUserLocationChangeCallback)
|
|
138
|
+
locationManager.stopCounted()
|
|
139
|
+
isEnabled = false
|
|
140
|
+
mLastLocation = null
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
companion object {
|
|
144
|
+
const val REACT_CLASS = "RCTMGLLocationModule"
|
|
145
|
+
const val LOCATION_UPDATE = "MapboxUserLocationUpdate"
|
|
146
|
+
}
|
|
147
|
+
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/CoordinateBounds.kt
CHANGED
|
@@ -10,14 +10,8 @@ fun CoordinateBounds.toReadableArray() : ReadableArray {
|
|
|
10
10
|
val array = Arguments.createArray()
|
|
11
11
|
val ne = northeast
|
|
12
12
|
val sw = southwest
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
}
|
|
13
|
+
|
|
14
|
+
array.pushArray(GeoJSONUtils.fromLatLng(LatLng(ne.latitude(), ne.longitude())));
|
|
15
|
+
array.pushArray(GeoJSONUtils.fromLatLng(LatLng(sw.latitude(), sw.longitude())));
|
|
22
16
|
return array
|
|
23
17
|
}
|
|
@@ -33,7 +33,9 @@ class RCTMGLBackgroundLayer: RCTMGLLayer {
|
|
|
33
33
|
styler.backgroundLayer(
|
|
34
34
|
layer: &styleLayer,
|
|
35
35
|
reactStyle: reactStyle,
|
|
36
|
-
applyUpdater: { (updater) in
|
|
36
|
+
applyUpdater: { (updater) in logged("RCTMGLBackgroundLayer.addStyles") {
|
|
37
|
+
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
|
|
38
|
+
}},
|
|
37
39
|
isValid: { return self.isAddedToMap() })
|
|
38
40
|
self.styleLayer = styleLayer
|
|
39
41
|
}
|
|
@@ -34,7 +34,9 @@ class RCTMGLCircleLayer: RCTMGLVectorLayer {
|
|
|
34
34
|
styler.circleLayer(
|
|
35
35
|
layer: &styleLayer,
|
|
36
36
|
reactStyle: reactStyle,
|
|
37
|
-
applyUpdater: { (updater) in
|
|
37
|
+
applyUpdater: { (updater) in logged("RCTMGLCircleLayer.updateLayer") {
|
|
38
|
+
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
|
|
39
|
+
}},
|
|
38
40
|
isValid: { return self.isAddedToMap() })
|
|
39
41
|
self.styleLayer = styleLayer
|
|
40
42
|
}
|
|
@@ -33,7 +33,9 @@ class RCTMGLFillExtrusionLayer: RCTMGLVectorLayer {
|
|
|
33
33
|
styler.fillExtrusionLayer(
|
|
34
34
|
layer: &styleLayer,
|
|
35
35
|
reactStyle: reactStyle,
|
|
36
|
-
applyUpdater: { (updater) in
|
|
36
|
+
applyUpdater: { (updater) in logged("RCTMGLFillExtrusionLayer.updateLayer") {
|
|
37
|
+
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
|
|
38
|
+
}},
|
|
37
39
|
isValid: { return self.isAddedToMap() })
|
|
38
40
|
self.styleLayer = styleLayer
|
|
39
41
|
}
|
|
@@ -34,7 +34,9 @@ class RCTMGLFillLayer: RCTMGLVectorLayer {
|
|
|
34
34
|
styler.fillLayer(
|
|
35
35
|
layer: &styleLayer,
|
|
36
36
|
reactStyle: reactStyle ?? [:],
|
|
37
|
-
applyUpdater: { (updater) in
|
|
37
|
+
applyUpdater: { (updater) in logged("RCTMGLFillLayer.updateLayer") {
|
|
38
|
+
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout FillLayer) in updater(&layer) }
|
|
39
|
+
}},
|
|
38
40
|
isValid: { return self.isAddedToMap() }
|
|
39
41
|
)
|
|
40
42
|
self.styleLayer = styleLayer
|
|
@@ -34,7 +34,9 @@ class RCTMGLHeatmapLayer: RCTMGLVectorLayer {
|
|
|
34
34
|
styler.heatmapLayer(
|
|
35
35
|
layer: &styleLayer,
|
|
36
36
|
reactStyle: reactStyle!,
|
|
37
|
-
applyUpdater: { (updater) in
|
|
37
|
+
applyUpdater: { (updater) in logged("RCTMGLHeatmapLayer.updateLayer") {
|
|
38
|
+
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout HeatmapLayer) in updater(&layer) }
|
|
39
|
+
}},
|
|
38
40
|
isValid: { return self.isAddedToMap() }
|
|
39
41
|
)
|
|
40
42
|
self.styleLayer = styleLayer
|
|
@@ -232,8 +232,6 @@ class RCTMGLLayer : UIView, RCTMGLMapComponent, RCTMGLSourceConsumer {
|
|
|
232
232
|
} catch {
|
|
233
233
|
Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
|
|
234
234
|
}
|
|
235
|
-
} else {
|
|
236
|
-
layer.filter = nil
|
|
237
235
|
}
|
|
238
236
|
|
|
239
237
|
if let minZoom = minZoomLevel {
|
|
@@ -37,7 +37,9 @@ class RCTMGLLineLayer: RCTMGLVectorLayer {
|
|
|
37
37
|
styler.lineLayer(
|
|
38
38
|
layer: &styleLayer,
|
|
39
39
|
reactStyle: reactStyle,
|
|
40
|
-
applyUpdater: { (updater) in
|
|
40
|
+
applyUpdater: { (updater) in logged("RCTMGLLineLayer.updateLayer") {
|
|
41
|
+
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
|
|
42
|
+
}},
|
|
41
43
|
isValid: {
|
|
42
44
|
return self.isAddedToMap()
|
|
43
45
|
})
|
|
@@ -73,12 +73,20 @@ class Logger {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
func errorMessage(_ error: Error) -> String {
|
|
77
|
+
if case DecodingError.typeMismatch(let type, let context) = error {
|
|
78
|
+
return "\(error.localizedDescription) \(context.codingPath) \(context.debugDescription)"
|
|
79
|
+
} else {
|
|
80
|
+
return "\(error.localizedDescription)"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
76
84
|
func logged<T>(_ msg: String, info: (() -> String)? = nil, level: Logger.LogLevel = .error, rejecter: RCTPromiseRejectBlock? = nil, fn : () throws -> T) -> T? {
|
|
77
85
|
do {
|
|
78
86
|
return try fn()
|
|
79
87
|
} catch {
|
|
80
|
-
Logger.log(level:level, message: "\(msg) \(info?() ?? "") \(error
|
|
81
|
-
rejecter?(msg, "\(info?() ?? "") \(error
|
|
88
|
+
Logger.log(level:level, message: "\(msg) \(info?() ?? "") \(errorMessage(error))")
|
|
89
|
+
rejecter?(msg, "\(info?() ?? "") \(errorMessage(error))", error)
|
|
82
90
|
return nil
|
|
83
91
|
}
|
|
84
92
|
}
|
|
@@ -28,7 +28,9 @@ class RCTMGLRasterLayer: RCTMGLLayer {
|
|
|
28
28
|
styler.rasterLayer(
|
|
29
29
|
layer: &styleLayer,
|
|
30
30
|
reactStyle: reactStyle!,
|
|
31
|
-
applyUpdater:{ (updater) in
|
|
31
|
+
applyUpdater:{ (updater) in logged("RCTMGLRasterLayer.updateLayer") {
|
|
32
|
+
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
|
|
33
|
+
}},
|
|
32
34
|
isValid: { return self.isAddedToMap() }
|
|
33
35
|
)
|
|
34
36
|
self.styleLayer = styleLayer
|
|
@@ -32,7 +32,9 @@ class RCTMGLSkyLayer: RCTMGLLayer {
|
|
|
32
32
|
styler.skyLayer(
|
|
33
33
|
layer: &styleLayer,
|
|
34
34
|
reactStyle: reactStyle,
|
|
35
|
-
applyUpdater: { (updater) in
|
|
35
|
+
applyUpdater: { (updater) in logged("RCTMGLSkyLayer.addStyles") {
|
|
36
|
+
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
|
|
37
|
+
}},
|
|
36
38
|
isValid: {
|
|
37
39
|
return self.isAddedToMap()
|
|
38
40
|
}
|
|
@@ -61,9 +61,11 @@ func fillLayer(layer: inout FillLayer, reactStyle:Dictionary<String, Any>, apply
|
|
|
61
61
|
if let image = image {
|
|
62
62
|
DispatchQueue.main.sync {
|
|
63
63
|
if (isValid()) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
logged("Fill.FillPattern.addImage") {
|
|
65
|
+
try self.style.addImage(image, id:imageURI!, stretchX: [], stretchY: []);
|
|
66
|
+
applyUpdater { (layer: inout FillLayer) in
|
|
67
|
+
self.setFillPattern(&layer, styleValue:styleValue);
|
|
68
|
+
}
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -151,9 +153,11 @@ func lineLayer(layer: inout LineLayer, reactStyle:Dictionary<String, Any>, apply
|
|
|
151
153
|
if let image = image {
|
|
152
154
|
DispatchQueue.main.sync {
|
|
153
155
|
if (isValid()) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
logged("Line.LinePattern.addImage") {
|
|
157
|
+
try self.style.addImage(image, id:imageURI!, stretchX: [], stretchY: []);
|
|
158
|
+
applyUpdater { (layer: inout LineLayer) in
|
|
159
|
+
self.setLinePattern(&layer, styleValue:styleValue);
|
|
160
|
+
}
|
|
157
161
|
}
|
|
158
162
|
}
|
|
159
163
|
}
|
|
@@ -223,9 +227,11 @@ func symbolLayer(layer: inout SymbolLayer, reactStyle:Dictionary<String, Any>, a
|
|
|
223
227
|
if let image = image {
|
|
224
228
|
DispatchQueue.main.sync {
|
|
225
229
|
if (isValid()) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
230
|
+
logged("Symbol.IconImage.addImage") {
|
|
231
|
+
try self.style.addImage(image, id:imageURI!, stretchX: [], stretchY: []);
|
|
232
|
+
applyUpdater { (layer: inout SymbolLayer) in
|
|
233
|
+
self.setIconImage(&layer, styleValue:styleValue);
|
|
234
|
+
}
|
|
229
235
|
}
|
|
230
236
|
}
|
|
231
237
|
}
|
|
@@ -493,9 +499,11 @@ func fillExtrusionLayer(layer: inout FillExtrusionLayer, reactStyle:Dictionary<S
|
|
|
493
499
|
if let image = image {
|
|
494
500
|
DispatchQueue.main.sync {
|
|
495
501
|
if (isValid()) {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
502
|
+
logged("FillExtrusion.FillExtrusionPattern.addImage") {
|
|
503
|
+
try self.style.addImage(image, id:imageURI!, stretchX: [], stretchY: []);
|
|
504
|
+
applyUpdater { (layer: inout FillExtrusionLayer) in
|
|
505
|
+
self.setFillExtrusionPattern(&layer, styleValue:styleValue);
|
|
506
|
+
}
|
|
499
507
|
}
|
|
500
508
|
}
|
|
501
509
|
}
|
|
@@ -647,9 +655,11 @@ func backgroundLayer(layer: inout BackgroundLayer, reactStyle:Dictionary<String,
|
|
|
647
655
|
if let image = image {
|
|
648
656
|
DispatchQueue.main.sync {
|
|
649
657
|
if (isValid()) {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
658
|
+
logged("Background.BackgroundPattern.addImage") {
|
|
659
|
+
try self.style.addImage(image, id:imageURI!, stretchX: [], stretchY: []);
|
|
660
|
+
applyUpdater { (layer: inout BackgroundLayer) in
|
|
661
|
+
self.setBackgroundPattern(&layer, styleValue:styleValue);
|
|
662
|
+
}
|
|
653
663
|
}
|
|
654
664
|
}
|
|
655
665
|
}
|
|
@@ -35,7 +35,9 @@ class RCTMGLSymbolLayer: RCTMGLVectorLayer {
|
|
|
35
35
|
styler.symbolLayer(
|
|
36
36
|
layer: &styleLayer,
|
|
37
37
|
reactStyle: reactStyle,
|
|
38
|
-
applyUpdater: { (updater) in
|
|
38
|
+
applyUpdater: { (updater) in logged("RCTMGLSymbolLayer.updateLayer") {
|
|
39
|
+
try style.updateLayer(withId: self.id, type: LayerType.self) { (layer: inout LayerType) in updater(&layer) }
|
|
40
|
+
}},
|
|
39
41
|
isValid: {
|
|
40
42
|
return self.isAddedToMap()
|
|
41
43
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -14,7 +14,7 @@ import { makeLatLngBounds, makePoint } from '../utils/geoUtils';
|
|
|
14
14
|
|
|
15
15
|
const NativeModule = NativeModules.MGLModule;
|
|
16
16
|
|
|
17
|
-
export
|
|
17
|
+
export enum UserTrackingMode {
|
|
18
18
|
Follow = 'normal',
|
|
19
19
|
FollowWithHeading = 'compass',
|
|
20
20
|
FollowWithCourse = 'course',
|
|
Binary file
|
|
Binary file
|