@rnmapbox/maps 10.0.0-beta.78 → 10.0.0-beta.80
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 +8 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCamera.kt +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +48 -8
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapViewManager.kt +18 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/events/constants/EventTypes.java +5 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLModule.kt +4 -2
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/GeoJSONUtils.kt +4 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/Point.kt +5 -1
- package/ios/RCTMGL-v10/RCTMGLCamera.swift +3 -3
- package/ios/RCTMGL-v10/RCTMGLInteractiveElement.swift +3 -1
- package/ios/RCTMGL-v10/RCTMGLLocationModule.swift +70 -47
- package/ios/RCTMGL-v10/RCTMGLLogging.swift +3 -1
- package/ios/RCTMGL-v10/RCTMGLOfflineModule.m +2 -0
- package/ios/RCTMGL-v10/RCTMGLOfflineModule.swift +31 -0
- package/ios/RCTMGL-v10/RCTMGLPointAnnotation.swift +5 -1
- package/lib/commonjs/components/MapView.js +38 -31
- package/lib/commonjs/components/MapView.js.map +1 -1
- package/lib/commonjs/components/PointAnnotation.js +2 -0
- package/lib/commonjs/components/PointAnnotation.js.map +1 -1
- package/lib/commonjs/utils/checkRequiredProps.js +14 -0
- package/lib/commonjs/utils/checkRequiredProps.js.map +1 -0
- package/lib/module/components/MapView.js +38 -31
- package/lib/module/components/MapView.js.map +1 -1
- package/lib/module/components/PointAnnotation.js +2 -0
- package/lib/module/components/PointAnnotation.js.map +1 -1
- package/lib/module/utils/checkRequiredProps.js +8 -0
- package/lib/module/utils/checkRequiredProps.js.map +1 -0
- package/lib/typescript/components/MapView.d.ts +6 -7
- package/lib/typescript/components/MapView.d.ts.map +1 -1
- package/lib/typescript/components/PointAnnotation.d.ts.map +1 -1
- package/lib/typescript/utils/checkRequiredProps.d.ts +8 -0
- package/lib/typescript/utils/checkRequiredProps.d.ts.map +1 -0
- package/package.json +3 -2
- package/rnmapbox-maps.podspec +3 -0
- package/src/components/MapView.tsx +50 -45
- package/src/components/PointAnnotation.tsx +2 -0
- package/src/utils/checkRequiredProps.ts +17 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
def defaultMapboxMapsImpl = "maplibre"
|
|
2
|
+
def defaultMapboxMapsVersion = "10.11.2"
|
|
2
3
|
|
|
3
4
|
def safeExtGet(prop, fallback) {
|
|
4
5
|
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
@@ -8,6 +9,10 @@ def safeExtGet(prop, fallback) {
|
|
|
8
9
|
if (rootProject.ext.has('expoRNMapboxMapsImpl')) {
|
|
9
10
|
rootProject.ext.set('RNMapboxMapsImpl', rootProject.ext.get('expoRNMapboxMapsImpl'))
|
|
10
11
|
}
|
|
12
|
+
if (rootProject.ext.has('expoRNMapboxMapsVersion')) {
|
|
13
|
+
rootProject.ext.set('RNMapboxMapsVersion', rootProject.ext.get('expoRNMapboxMapsVersion'))
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
|
|
12
17
|
buildscript {
|
|
13
18
|
repositories {
|
|
@@ -28,6 +33,7 @@ if (safeExtGet("RNMapboxMapsImpl", defaultMapboxMapsImpl) == "mapbox") {
|
|
|
28
33
|
|
|
29
34
|
android {
|
|
30
35
|
if (safeExtGet("RNMapboxMapsImpl", defaultMapboxMapsImpl) == "maplibre") {
|
|
36
|
+
logger.warn('@rnmapbox/maps: Maplibre implementation is DEPRECATED and will be removed, set RNMapboxMapsImpl to mapbox- see https://github.com/rnmapbox/maps/wiki/Deprecated-RNMapboxImpl-Maplibre#android')
|
|
31
37
|
sourceSets {
|
|
32
38
|
main {
|
|
33
39
|
java.srcDirs = ['src/main/java-mapboxgl/common','src/main/java-mapboxgl/maplibre']
|
|
@@ -35,6 +41,7 @@ android {
|
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
43
|
else if (safeExtGet("RNMapboxMapsImpl", defaultMapboxMapsImpl) == "mapbox-gl") {
|
|
44
|
+
logger.warn('@rnmapbox/maps: Maplibre implementation is DEPRECATED and will be removed, set RNMapboxMapsImpl to mapbox - see https://github.com/rnmapbox/maps/wiki/Deprecated-RNMapboxImpl-Maplibre#android')
|
|
38
45
|
sourceSets {
|
|
39
46
|
main {
|
|
40
47
|
java.srcDirs = ['src/main/java-mapboxgl/common','src/main/java-mapboxgl/mapbox']
|
|
@@ -130,7 +137,7 @@ dependencies {
|
|
|
130
137
|
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:5.1.0'
|
|
131
138
|
}
|
|
132
139
|
else if (safeExtGet("RNMapboxMapsImpl", defaultMapboxMapsImpl) == "mapbox") {
|
|
133
|
-
implementation
|
|
140
|
+
implementation "com.mapbox.maps:android:${safeExtGet("RNMapboxMapsVersion", defaultMapboxMapsVersion)}"
|
|
134
141
|
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:6.10.0'
|
|
135
142
|
implementation 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0'
|
|
136
143
|
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCamera.kt
CHANGED
|
@@ -78,7 +78,7 @@ class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCa
|
|
|
78
78
|
|
|
79
79
|
override fun onAnimationCancel(animator: Animator) {
|
|
80
80
|
if (!hasSentFirstRegion) {
|
|
81
|
-
mMapView
|
|
81
|
+
mMapView?.sendRegionChangeEvent(false)
|
|
82
82
|
hasSentFirstRegion = true
|
|
83
83
|
}
|
|
84
84
|
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt
CHANGED
|
@@ -66,10 +66,7 @@ import com.mapbox.rctmgl.events.IEvent
|
|
|
66
66
|
import com.mapbox.rctmgl.events.MapChangeEvent
|
|
67
67
|
import com.mapbox.rctmgl.events.MapClickEvent
|
|
68
68
|
import com.mapbox.rctmgl.events.constants.EventTypes
|
|
69
|
-
import com.mapbox.rctmgl.utils
|
|
70
|
-
import com.mapbox.rctmgl.utils.GeoJSONUtils
|
|
71
|
-
import com.mapbox.rctmgl.utils.LatLng
|
|
72
|
-
import com.mapbox.rctmgl.utils.Logger
|
|
69
|
+
import com.mapbox.rctmgl.utils.*
|
|
73
70
|
import com.mapbox.rctmgl.utils.extensions.toReadableArray
|
|
74
71
|
import org.json.JSONException
|
|
75
72
|
import org.json.JSONObject
|
|
@@ -178,7 +175,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
178
175
|
|
|
179
176
|
private var styleLoaded = false
|
|
180
177
|
|
|
181
|
-
private
|
|
178
|
+
private var mHandledMapChangedEvents: HashSet<String>? = null
|
|
182
179
|
private var mAnnotationClicked = false
|
|
183
180
|
private var mAnnotationDragged = false
|
|
184
181
|
private var mLocationComponentManager: LocationComponentManager? = null
|
|
@@ -267,10 +264,12 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
267
264
|
|
|
268
265
|
map.addOnCameraChangeListener(OnCameraChangeListener { cameraChangedEventData ->
|
|
269
266
|
handleMapChangedEvent(EventTypes.REGION_IS_CHANGING)
|
|
267
|
+
handleMapChangedEvent(EventTypes.CAMERA_CHANGED)
|
|
270
268
|
})
|
|
271
269
|
|
|
272
270
|
map.addOnMapIdleListener(OnMapIdleListener { mapIdleEventData ->
|
|
273
271
|
sendRegionDidChangeEvent()
|
|
272
|
+
handleMapChangedEvent(EventTypes.MAP_IDLE);
|
|
274
273
|
})
|
|
275
274
|
|
|
276
275
|
val gesturesPlugin: GesturesPlugin = this.gestures
|
|
@@ -426,9 +425,9 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
426
425
|
// endregion
|
|
427
426
|
|
|
428
427
|
fun sendRegionChangeEvent(isAnimated: Boolean) {
|
|
429
|
-
val
|
|
428
|
+
val didChangeEvent = MapChangeEvent(this, EventTypes.REGION_DID_CHANGE,
|
|
430
429
|
makeRegionPayload(isAnimated))
|
|
431
|
-
mManager.handleEvent(
|
|
430
|
+
mManager.handleEvent(didChangeEvent)
|
|
432
431
|
mCameraChangeTracker.setReason(CameraChangeReason.NONE)
|
|
433
432
|
}
|
|
434
433
|
|
|
@@ -719,6 +718,8 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
719
718
|
waiters.add(callback)
|
|
720
719
|
}
|
|
721
720
|
|
|
721
|
+
// region Events
|
|
722
|
+
|
|
722
723
|
fun sendRegionDidChangeEvent() {
|
|
723
724
|
handleMapChangedEvent(EventTypes.REGION_DID_CHANGE)
|
|
724
725
|
mCameraChangeTracker.setReason(CameraChangeReason.NONE)
|
|
@@ -726,16 +727,52 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
726
727
|
|
|
727
728
|
private fun handleMapChangedEvent(eventType: String) {
|
|
728
729
|
if (!canHandleEvent(eventType)) return
|
|
730
|
+
|
|
729
731
|
val event: IEvent
|
|
730
732
|
event = when (eventType) {
|
|
731
733
|
EventTypes.REGION_WILL_CHANGE, EventTypes.REGION_DID_CHANGE, EventTypes.REGION_IS_CHANGING -> MapChangeEvent(this, eventType, makeRegionPayload(null))
|
|
734
|
+
EventTypes.CAMERA_CHANGED, EventTypes.MAP_IDLE -> MapChangeEvent(this, eventType, makeCameraPayload())
|
|
732
735
|
else -> MapChangeEvent(this, eventType)
|
|
733
736
|
}
|
|
734
737
|
mManager.handleEvent(event)
|
|
735
738
|
}
|
|
736
739
|
|
|
740
|
+
fun setHandledMapChangedEvents(events: Array<String>) {
|
|
741
|
+
mHandledMapChangedEvents = HashSet<String>(events.asList())
|
|
742
|
+
}
|
|
743
|
+
|
|
737
744
|
private fun canHandleEvent(event: String): Boolean {
|
|
738
|
-
|
|
745
|
+
val changedEvents = mHandledMapChangedEvents
|
|
746
|
+
return changedEvents == null || changedEvents.contains(event)
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
private fun makeCameraPayload(): WritableMap {
|
|
750
|
+
val position = mMap?.cameraState ?: return WritableNativeMap()
|
|
751
|
+
val properties = WritableNativeMap()
|
|
752
|
+
properties.putDouble("zoom", position.zoom)
|
|
753
|
+
properties.putDouble("heading", position.bearing)
|
|
754
|
+
properties.putDouble("pitch", position.pitch)
|
|
755
|
+
properties.putArray("center", position.center.toReadableArray())
|
|
756
|
+
try {
|
|
757
|
+
val bounds = mMap.coordinateBoundsForCamera(position.toCameraOptions())
|
|
758
|
+
|
|
759
|
+
val boundsMap = WritableNativeMap()
|
|
760
|
+
boundsMap.putArray("ne", bounds.northeast.toReadableArray())
|
|
761
|
+
boundsMap.putArray("sw", bounds.southwest.toReadableArray())
|
|
762
|
+
|
|
763
|
+
properties.putMap("bounds", boundsMap)
|
|
764
|
+
} catch (ex: Exception) {
|
|
765
|
+
Logger.e(LOG_TAG, "An error occurred while attempting to make the region", ex)
|
|
766
|
+
}
|
|
767
|
+
val gestures = WritableNativeMap()
|
|
768
|
+
gestures.putBoolean("isGestureActive", mCameraChangeTracker.isUserInteraction)
|
|
769
|
+
// gestures.putBoolean("isAnimatingFromGesture", if (null == isAnimated) mCameraChangeTracker.isAnimated else isAnimated)
|
|
770
|
+
|
|
771
|
+
val state: WritableMap = WritableNativeMap()
|
|
772
|
+
state.putMap("properties", properties)
|
|
773
|
+
state.putMap("gestures", gestures)
|
|
774
|
+
|
|
775
|
+
return state
|
|
739
776
|
}
|
|
740
777
|
|
|
741
778
|
private fun makeRegionPayload(isAnimated: Boolean?): WritableMap {
|
|
@@ -757,6 +794,8 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
757
794
|
return GeoJSONUtils.toPointFeature(latLng, properties)
|
|
758
795
|
}
|
|
759
796
|
|
|
797
|
+
// endregion
|
|
798
|
+
|
|
760
799
|
/**
|
|
761
800
|
* Adds the marker image to the map for use as a SymbolLayer icon
|
|
762
801
|
*/
|
|
@@ -1271,6 +1310,7 @@ open class RCTMGLMapView(private val mContext: Context, var mManager: RCTMGLMapV
|
|
|
1271
1310
|
super.onAttachedToWindow()
|
|
1272
1311
|
}
|
|
1273
1312
|
|
|
1313
|
+
|
|
1274
1314
|
// endregion
|
|
1275
1315
|
}
|
|
1276
1316
|
|
|
@@ -23,6 +23,19 @@ import com.mapbox.rctmgl.utils.extensions.toScreenCoordinate
|
|
|
23
23
|
import java.lang.Exception
|
|
24
24
|
import java.util.HashMap
|
|
25
25
|
|
|
26
|
+
fun ReadableArray.forEachString(action: (String) -> Unit) {
|
|
27
|
+
for (i in 0 until size()) {
|
|
28
|
+
action(getString(i))
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fun ReadableArray.asArrayString(): Array<String> {
|
|
33
|
+
val result = Array<String>(size()) {
|
|
34
|
+
getString(it)
|
|
35
|
+
}
|
|
36
|
+
return result
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
open class RCTMGLMapViewManager(context: ReactApplicationContext?) :
|
|
27
40
|
AbstractEventEmitter<RCTMGLMapView?>(context) {
|
|
28
41
|
private val mViews: MutableMap<Int, RCTMGLMapView>
|
|
@@ -295,6 +308,11 @@ open class RCTMGLMapViewManager(context: ReactApplicationContext?) :
|
|
|
295
308
|
METHOD_TAKE_SNAP -> {
|
|
296
309
|
mapView.takeSnap(args!!.getString(0), args!!.getBoolean(1))
|
|
297
310
|
}
|
|
311
|
+
METHOD_SET_HANDLED_MAP_EVENTS -> {
|
|
312
|
+
args?.let {
|
|
313
|
+
mapView.setHandledMapChangedEvents(args.asArrayString());
|
|
314
|
+
}
|
|
315
|
+
}
|
|
298
316
|
}
|
|
299
317
|
/*
|
|
300
318
|
switch (commandID) {
|
|
@@ -7,10 +7,14 @@ public class EventTypes {
|
|
|
7
7
|
public static final String MAP_USER_TRACKING_MODE_CHANGE = "usertrackingmodechange";
|
|
8
8
|
|
|
9
9
|
public static final String REGION_WILL_CHANGE = "regionwillchange";
|
|
10
|
-
public static final String REGION_IS_CHANGING = "regionischanging";
|
|
10
|
+
public static final String REGION_IS_CHANGING = "regionischanging"; // deprecated
|
|
11
|
+
public static final String CAMERA_CHANGED = "camerachanged";
|
|
11
12
|
public static final String REGION_DID_CHANGE = "regiondidchange";
|
|
13
|
+
public static final String MAP_IDLE = "mapidle";
|
|
12
14
|
public static final String USER_LOCATION_UPDATED = "userlocationdupdated";
|
|
13
15
|
|
|
16
|
+
|
|
17
|
+
|
|
14
18
|
public static final String WILL_START_LOADING_MAP = "willstartloadingmap";
|
|
15
19
|
public static final String DID_FINISH_LOADING_MAP = "didfinishloadingmap";
|
|
16
20
|
public static final String DID_FAIL_LOADING_MAP = "didfailloadingmap";
|
|
@@ -52,8 +52,10 @@ class RCTMGLModule(private val mReactContext: ReactApplicationContext) : ReactCo
|
|
|
52
52
|
eventTypes["MapClick"] = EventTypes.MAP_CLICK
|
|
53
53
|
eventTypes["MapLongClick"] = EventTypes.MAP_LONG_CLICK
|
|
54
54
|
eventTypes["RegionWillChange"] = EventTypes.REGION_WILL_CHANGE
|
|
55
|
-
eventTypes["RegionIsChanging"] = EventTypes.REGION_IS_CHANGING
|
|
56
|
-
eventTypes["
|
|
55
|
+
eventTypes["RegionIsChanging"] = EventTypes.REGION_IS_CHANGING // deprecated
|
|
56
|
+
eventTypes["CameraChanged"] = EventTypes.CAMERA_CHANGED
|
|
57
|
+
eventTypes["RegionDidChange"] = EventTypes.REGION_DID_CHANGE // deprecated
|
|
58
|
+
eventTypes["MapIdle"] = EventTypes.MAP_IDLE
|
|
57
59
|
eventTypes["UserLocationUpdated"] = EventTypes.USER_LOCATION_UPDATED
|
|
58
60
|
eventTypes["WillStartLoadingMap"] = EventTypes.WILL_START_LOADING_MAP
|
|
59
61
|
eventTypes["DidFinishLoadingMap"] = EventTypes.DID_FINISH_LOADING_MAP
|
|
@@ -10,8 +10,11 @@ import com.mapbox.maps.CameraBounds
|
|
|
10
10
|
import com.mapbox.rctmgl.utils.LatLngBounds
|
|
11
11
|
import com.mapbox.turf.TurfMeasurement
|
|
12
12
|
import com.mapbox.rctmgl.utils.LatLngQuad
|
|
13
|
+
import com.mapbox.rctmgl.utils.extensions.toReadableArray
|
|
13
14
|
import java.util.ArrayList
|
|
14
15
|
|
|
16
|
+
|
|
17
|
+
|
|
15
18
|
object GeoJSONUtils {
|
|
16
19
|
@JvmStatic
|
|
17
20
|
fun fromFeature(feature: Feature): WritableMap {
|
|
@@ -78,7 +81,7 @@ object GeoJSONUtils {
|
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
private fun coordinatesL(points: List<Point>): WritableArray {
|
|
81
|
-
return fromList(points.map {
|
|
84
|
+
return fromList(points.map { it.toReadableArray() })
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
private fun coordinatesLL(points: List<List<Point>>): WritableArray {
|
|
@@ -217,7 +217,7 @@ class RCTMGLCamera : RCTMGLMapComponentBase {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
func
|
|
220
|
+
func _disableUserTracking(_ map: MapView) {
|
|
221
221
|
map.viewport.idle()
|
|
222
222
|
}
|
|
223
223
|
|
|
@@ -263,12 +263,12 @@ class RCTMGLCamera : RCTMGLMapComponentBase {
|
|
|
263
263
|
let userTrackingMode = UserTrackingMode(rawValue: self.followUserMode ?? UserTrackingMode.normal.rawValue)
|
|
264
264
|
guard let userTrackingMode = userTrackingMode else {
|
|
265
265
|
Logger.error("RCTMGLCamera: Unexpected followUserMode \(optional: self.followUserMode)")
|
|
266
|
-
self.
|
|
266
|
+
self._disableUserTracking(map)
|
|
267
267
|
return
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
guard self.followUserLocation && userTrackingMode != .none else {
|
|
271
|
-
self.
|
|
271
|
+
self._disableUserTracking(map)
|
|
272
272
|
return
|
|
273
273
|
}
|
|
274
274
|
|
|
@@ -2,7 +2,6 @@ import MapboxMaps
|
|
|
2
2
|
|
|
3
3
|
@objc
|
|
4
4
|
class RCTMGLInteractiveElement : UIView, RCTMGLMapComponent {
|
|
5
|
-
|
|
6
5
|
weak var map : RCTMGLMapView? = nil
|
|
7
6
|
|
|
8
7
|
static let hitboxDefault = 44.0
|
|
@@ -48,6 +47,9 @@ class RCTMGLInteractiveElement : UIView, RCTMGLMapComponent {
|
|
|
48
47
|
|
|
49
48
|
// MARK: - RCTMGLMapComponent
|
|
50
49
|
func addToMap(_ map: RCTMGLMapView, style: Style) {
|
|
50
|
+
if (self.id == nil) {
|
|
51
|
+
Logger.log(level: .error, message: "id is required on \(self) but not specified")
|
|
52
|
+
}
|
|
51
53
|
self.map = map
|
|
52
54
|
}
|
|
53
55
|
|
|
@@ -38,31 +38,50 @@ internal class EmptyLocationProviderDelegate: LocationProviderDelegate {
|
|
|
38
38
|
func locationProviderDidChangeAuthorization(_ provider: LocationProvider) {}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
protocol
|
|
42
|
-
func locationManager(_ locationManager:
|
|
41
|
+
protocol LocationProviderRCTMGLDelegate : AnyObject {
|
|
42
|
+
func locationManager(_ locationManager: LocationProviderRCTMGL, didUpdateLocation: RCTMGLLocation)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
/// LocationProviderRCTMGL listens to updates from a locationProvider and implements the LocationProvider interface itself
|
|
46
|
+
/// So it can be source of both updates to Mapbox mapView.location, and camera location updates as well as source to updates
|
|
47
|
+
/// to RCTMGLLocationModules.
|
|
48
|
+
class LocationProviderRCTMGL : LocationProviderDelegate {
|
|
46
49
|
enum LocationUpdateType {
|
|
47
50
|
case heading
|
|
48
51
|
case location
|
|
49
52
|
}
|
|
50
|
-
|
|
53
|
+
|
|
51
54
|
var provider: LocationProvider
|
|
52
55
|
|
|
53
56
|
var lastKnownLocation : CLLocation?
|
|
54
57
|
var lastKnownHeading : CLHeading?
|
|
55
58
|
var shouldRequestAlwaysAuthorization: Bool?
|
|
56
59
|
|
|
57
|
-
weak var delegate:
|
|
60
|
+
weak var delegate: LocationProviderRCTMGLDelegate?
|
|
58
61
|
weak var locationProviderDelage: LocationProviderDelegate?
|
|
59
62
|
|
|
60
63
|
var headingSimulator: Timer? = nil
|
|
61
64
|
var simulatedHeading: Double = 0.0
|
|
62
65
|
var simulatedHeadingIncrement: Double = 1.0
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
struct Status {
|
|
69
|
+
var provider = (updatingLocation: false, updatingHeading: false)
|
|
70
|
+
var rctmglModule = false
|
|
71
|
+
|
|
72
|
+
var shouldUpdateLocation: Bool {
|
|
73
|
+
return provider.updatingLocation || rctmglModule
|
|
74
|
+
}
|
|
75
|
+
var shouldUpdateHeading: Bool {
|
|
76
|
+
return provider.updatingHeading || rctmglModule
|
|
77
|
+
}
|
|
78
|
+
}
|
|
63
79
|
|
|
64
|
-
var
|
|
65
|
-
|
|
80
|
+
var started = Status(provider: (updatingLocation: false, updatingHeading: false), rctmglModule: false) {
|
|
81
|
+
didSet {
|
|
82
|
+
_syncStarted(oldValue: oldValue, started: started)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
66
85
|
|
|
67
86
|
init() {
|
|
68
87
|
provider = AppleLocationProvider()
|
|
@@ -84,23 +103,36 @@ class RCTMGLLocationManager : LocationProviderDelegate {
|
|
|
84
103
|
provider.requestAlwaysAuthorization()
|
|
85
104
|
}
|
|
86
105
|
provider.requestWhenInUseAuthorization()
|
|
87
|
-
|
|
88
|
-
provider.startUpdatingHeading()
|
|
89
|
-
provider.startUpdatingLocation()
|
|
106
|
+
started.rctmglModule = true
|
|
90
107
|
}
|
|
91
108
|
|
|
92
109
|
func stop() {
|
|
93
|
-
|
|
94
|
-
|
|
110
|
+
started.rctmglModule = false
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
func _syncStarted(oldValue: Status, started: Status) {
|
|
114
|
+
var stoppedSomething = false
|
|
115
|
+
if (oldValue.shouldUpdateLocation != started.shouldUpdateLocation) {
|
|
116
|
+
if started.shouldUpdateLocation {
|
|
117
|
+
provider.setDelegate(self)
|
|
118
|
+
provider.startUpdatingLocation()
|
|
119
|
+
} else {
|
|
120
|
+
provider.stopUpdatingLocation()
|
|
121
|
+
stoppedSomething = true
|
|
122
|
+
}
|
|
95
123
|
}
|
|
96
|
-
|
|
97
|
-
|
|
124
|
+
|
|
125
|
+
if (oldValue.shouldUpdateHeading != started.shouldUpdateHeading) {
|
|
126
|
+
if started.shouldUpdateHeading {
|
|
127
|
+
provider.setDelegate(self)
|
|
128
|
+
provider.startUpdatingHeading()
|
|
129
|
+
} else {
|
|
130
|
+
provider.stopUpdatingHeading()
|
|
131
|
+
stoppedSomething = true
|
|
132
|
+
}
|
|
98
133
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
func _clearProviderDelegateIfNotListening() {
|
|
103
|
-
if !startUpdatingHeadingCalled && !startUpdatingLocationCalled {
|
|
134
|
+
|
|
135
|
+
if stoppedSomething && !started.shouldUpdateLocation && !started.shouldUpdateHeading {
|
|
104
136
|
provider.setDelegate(EmptyLocationProviderDelegate())
|
|
105
137
|
}
|
|
106
138
|
}
|
|
@@ -159,7 +191,7 @@ class RCTMGLLocationManager : LocationProviderDelegate {
|
|
|
159
191
|
|
|
160
192
|
// MARK: LocationProvider
|
|
161
193
|
|
|
162
|
-
extension
|
|
194
|
+
extension LocationProviderRCTMGL: LocationProvider {
|
|
163
195
|
var locationProviderOptions: LocationOptions {
|
|
164
196
|
get {
|
|
165
197
|
provider.locationProviderOptions
|
|
@@ -209,15 +241,11 @@ extension RCTMGLLocationManager: LocationProvider {
|
|
|
209
241
|
}
|
|
210
242
|
|
|
211
243
|
func startUpdatingLocation() {
|
|
212
|
-
|
|
213
|
-
provider.startUpdatingLocation()
|
|
244
|
+
started.provider.updatingLocation = true
|
|
214
245
|
}
|
|
215
246
|
|
|
216
247
|
func stopUpdatingLocation() {
|
|
217
|
-
provider.
|
|
218
|
-
startUpdatingLocationCalled = false
|
|
219
|
-
|
|
220
|
-
_clearProviderDelegateIfNotListening()
|
|
248
|
+
started.provider.updatingLocation = false
|
|
221
249
|
}
|
|
222
250
|
|
|
223
251
|
var headingOrientation: CLDeviceOrientation {
|
|
@@ -230,15 +258,11 @@ extension RCTMGLLocationManager: LocationProvider {
|
|
|
230
258
|
}
|
|
231
259
|
|
|
232
260
|
func startUpdatingHeading() {
|
|
233
|
-
|
|
234
|
-
provider.startUpdatingHeading()
|
|
261
|
+
started.provider.updatingHeading = true
|
|
235
262
|
}
|
|
236
263
|
|
|
237
264
|
func stopUpdatingHeading() {
|
|
238
|
-
|
|
239
|
-
provider.stopUpdatingHeading()
|
|
240
|
-
|
|
241
|
-
_clearProviderDelegateIfNotListening()
|
|
265
|
+
started.provider.updatingHeading = false
|
|
242
266
|
}
|
|
243
267
|
|
|
244
268
|
func dismissHeadingCalibrationDisplay() {
|
|
@@ -273,7 +297,7 @@ final public class SimulatedHeading: CLHeading {
|
|
|
273
297
|
}
|
|
274
298
|
}
|
|
275
299
|
|
|
276
|
-
extension
|
|
300
|
+
extension LocationProviderRCTMGL {
|
|
277
301
|
func simulateHeading(changesPerSecond: Int, increment: Double) {
|
|
278
302
|
self.simulatedHeadingIncrement = increment
|
|
279
303
|
DispatchQueue.main.async {
|
|
@@ -294,18 +318,18 @@ extension RCTMGLLocationManager {
|
|
|
294
318
|
}
|
|
295
319
|
}
|
|
296
320
|
|
|
297
|
-
|
|
321
|
+
// LocationModule is a sigleton class
|
|
298
322
|
@objc(RCTMGLLocationModule)
|
|
299
|
-
class RCTMGLLocationModule: RCTEventEmitter,
|
|
323
|
+
class RCTMGLLocationModule: RCTEventEmitter, LocationProviderRCTMGLDelegate {
|
|
300
324
|
|
|
301
325
|
static weak var shared : RCTMGLLocationModule? = nil
|
|
302
326
|
|
|
303
|
-
var
|
|
327
|
+
var locationProviderRCTMGL : LocationProviderRCTMGL
|
|
304
328
|
var hasListener = false
|
|
305
329
|
|
|
306
330
|
var locationProvider : LocationProvider {
|
|
307
331
|
get {
|
|
308
|
-
return
|
|
332
|
+
return locationProviderRCTMGL
|
|
309
333
|
}
|
|
310
334
|
}
|
|
311
335
|
|
|
@@ -318,9 +342,9 @@ class RCTMGLLocationModule: RCTEventEmitter, RCTMGLLocationManagerDelegate {
|
|
|
318
342
|
)
|
|
319
343
|
|
|
320
344
|
override init() {
|
|
321
|
-
|
|
345
|
+
locationProviderRCTMGL = LocationProviderRCTMGL()
|
|
322
346
|
super.init()
|
|
323
|
-
|
|
347
|
+
locationProviderRCTMGL.delegate = self
|
|
324
348
|
RCTMGLLocationModule.shared = self
|
|
325
349
|
}
|
|
326
350
|
|
|
@@ -340,12 +364,12 @@ class RCTMGLLocationModule: RCTEventEmitter, RCTMGLLocationManagerDelegate {
|
|
|
340
364
|
}
|
|
341
365
|
|
|
342
366
|
@objc func start(_ minDisplacement: CLLocationDistance) {
|
|
343
|
-
if minDisplacement >= 0.0 {
|
|
344
|
-
|
|
367
|
+
if minDisplacement >= 0.0 { locationProviderRCTMGL.setDistanceFilter(minDisplacement) }
|
|
368
|
+
locationProviderRCTMGL.start()
|
|
345
369
|
}
|
|
346
370
|
|
|
347
371
|
@objc func stop() {
|
|
348
|
-
|
|
372
|
+
locationProviderRCTMGL.stop()
|
|
349
373
|
}
|
|
350
374
|
|
|
351
375
|
@objc func getLastKnownLocation() -> RCTMGLLocation? {
|
|
@@ -353,15 +377,15 @@ class RCTMGLLocationModule: RCTEventEmitter, RCTMGLLocationManagerDelegate {
|
|
|
353
377
|
}
|
|
354
378
|
|
|
355
379
|
@objc func setMinDisplacement(_ minDisplacement: CLLocationDistance) {
|
|
356
|
-
|
|
380
|
+
locationProviderRCTMGL.setDistanceFilter(minDisplacement)
|
|
357
381
|
}
|
|
358
382
|
|
|
359
383
|
@objc func setRequestsAlwaysUse(_ requestsAlwaysUse: Bool) {
|
|
360
|
-
|
|
384
|
+
locationProviderRCTMGL.setRequestsAlwaysUse(requestsAlwaysUse);
|
|
361
385
|
}
|
|
362
386
|
|
|
363
387
|
@objc func simulateHeading(_ changesPerSecond: NSNumber, increment: NSNumber) {
|
|
364
|
-
|
|
388
|
+
locationProviderRCTMGL.simulateHeading(changesPerSecond: changesPerSecond.intValue, increment: increment.doubleValue)
|
|
365
389
|
}
|
|
366
390
|
|
|
367
391
|
@objc
|
|
@@ -376,7 +400,7 @@ class RCTMGLLocationModule: RCTEventEmitter, RCTMGLLocationManagerDelegate {
|
|
|
376
400
|
hasListener = false
|
|
377
401
|
}
|
|
378
402
|
|
|
379
|
-
func locationManager(_ locationManager:
|
|
403
|
+
func locationManager(_ locationManager: LocationProviderRCTMGL, didUpdateLocation location: RCTMGLLocation) {
|
|
380
404
|
guard hasListener, let _ = bridge else {
|
|
381
405
|
return
|
|
382
406
|
}
|
|
@@ -416,7 +440,6 @@ class RCTMGLLocationModule: RCTEventEmitter, RCTMGLLocationManagerDelegate {
|
|
|
416
440
|
|
|
417
441
|
return false;
|
|
418
442
|
}
|
|
419
|
-
|
|
420
443
|
}
|
|
421
444
|
|
|
422
445
|
|
|
@@ -74,8 +74,10 @@ class Logger {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
func errorMessage(_ error: Error) -> String {
|
|
77
|
-
if case DecodingError.typeMismatch(let
|
|
77
|
+
if case DecodingError.typeMismatch(let _, let context) = error {
|
|
78
78
|
return "\(error.localizedDescription) \(context.codingPath) \(context.debugDescription)"
|
|
79
|
+
} else if let mapError = error as? MapError {
|
|
80
|
+
return "MapError: \(mapError.errorDescription)"
|
|
79
81
|
} else {
|
|
80
82
|
return "\(error.localizedDescription)"
|
|
81
83
|
}
|
|
@@ -29,4 +29,6 @@ RCT_EXTERN_METHOD(deletePack:(NSString *)name
|
|
|
29
29
|
|
|
30
30
|
RCT_EXTERN_METHOD(migrateOfflineCache:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
31
31
|
|
|
32
|
+
RCT_EXTERN_METHOD(resetDatabase:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
33
|
+
|
|
32
34
|
@end
|
|
@@ -572,6 +572,37 @@ class RCTMGLOfflineModule: RCTEventEmitter {
|
|
|
572
572
|
reject("migrateOfflineCache", error.localizedDescription, error)
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
|
+
|
|
576
|
+
@objc
|
|
577
|
+
func resetDatabase(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
578
|
+
self.tileStore.allTileRegions { result in
|
|
579
|
+
switch result {
|
|
580
|
+
case .success(let regions):
|
|
581
|
+
regions.forEach { region in
|
|
582
|
+
self.tileStore.removeTileRegion(forId: region.id)
|
|
583
|
+
}
|
|
584
|
+
self.offlineManager.allStylePacks { result in
|
|
585
|
+
switch result {
|
|
586
|
+
case .success(let packs):
|
|
587
|
+
packs.forEach { pack in
|
|
588
|
+
if let url = logged("RCTMGLOfflineModule.resetDatabase invalid styleURI",fn: { return URL(string: pack.styleURI) }),
|
|
589
|
+
let styleUri = logged("RCTMGLOfflineModule.resetDatabase invalid styleURI2", fn: { return StyleURI(url: url) }) {
|
|
590
|
+
self.offlineManager.removeStylePack(for: styleUri)
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
resolve(nil)
|
|
594
|
+
case .failure(let error):
|
|
595
|
+
Logger.log(level:.error, message: "RCTMGLOfflineModule.resetDatabase/allStylePacks \(error.localizedDescription) \(error)")
|
|
596
|
+
reject("RCTMGLOfflineModule.resetDatabase/allStylePacks", error.localizedDescription, error)
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
case .failure(let error):
|
|
600
|
+
Logger.log(level:.error, message: "RCTMGLOfflineModule.resetDatabase/allTileRegions \(error.localizedDescription) \(error)")
|
|
601
|
+
reject("RCTMGLOfflineModule.resetDatabase/allTileRegions", error.localizedDescription, error)
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
}
|
|
605
|
+
}
|
|
575
606
|
}
|
|
576
607
|
|
|
577
608
|
// MARK: progress throttle
|
|
@@ -207,6 +207,7 @@ class RCTMGLPointAnnotation : RCTMGLInteractiveElement {
|
|
|
207
207
|
// MARK: - RCTMGLMapComponent
|
|
208
208
|
|
|
209
209
|
override func addToMap(_ map: RCTMGLMapView, style: Style) {
|
|
210
|
+
super.addToMap(map, style: style)
|
|
210
211
|
self.map = map
|
|
211
212
|
addIfPossible()
|
|
212
213
|
}
|
|
@@ -235,7 +236,10 @@ extension RCTMGLPointAnnotation {
|
|
|
235
236
|
|
|
236
237
|
@discardableResult
|
|
237
238
|
func addIfPossible() -> Bool {
|
|
238
|
-
if !added
|
|
239
|
+
if !added
|
|
240
|
+
&& annotation.point.coordinates.isValid()
|
|
241
|
+
&& (logged("PointAnnotation: missing id attribute") { return id }) != nil,
|
|
242
|
+
let pointAnnotationManager = map?.pointAnnotationManager {
|
|
239
243
|
pointAnnotationManager.add(annotation)
|
|
240
244
|
added = true
|
|
241
245
|
return true
|