@rnmapbox/maps 10.0.0-beta.39 → 10.0.0-beta.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/AbstractMapFeature.kt +10 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraUpdateItem.kt +135 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraUpdateQueue.kt +68 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCamera.kt +498 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCameraManager.kt +114 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/UserLocation.java +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/UserTrackingMode.java +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTSource.kt +14 -9
- package/docs/Annotation.md +1 -1
- package/docs/Atmosphere.md +1 -1
- package/docs/BackgroundLayer.md +1 -1
- package/docs/Callout.md +1 -1
- package/docs/Camera.md +1 -1
- package/docs/CircleLayer.md +1 -1
- package/docs/FillExtrusionLayer.md +1 -1
- package/docs/FillLayer.md +1 -1
- package/docs/HeadingIndicator.md +1 -1
- package/docs/HeatmapLayer.md +1 -1
- package/docs/ImageSource.md +1 -1
- package/docs/Images.md +1 -1
- package/docs/Light.md +1 -1
- package/docs/LineLayer.md +1 -1
- package/docs/MapView.md +1 -1
- package/docs/MarkerView.md +1 -1
- package/docs/NativeUserLocation.md +1 -1
- package/docs/PointAnnotation.md +12 -10
- package/docs/RasterDemSource.md +1 -1
- package/docs/RasterLayer.md +1 -1
- package/docs/RasterSource.md +1 -1
- package/docs/ShapeSource.md +1 -1
- package/docs/SkyLayer.md +1 -1
- package/docs/Style.md +1 -1
- package/docs/SymbolLayer.md +1 -1
- package/docs/Terrain.md +1 -1
- package/docs/UserLocation.md +1 -1
- package/docs/VectorSource.md +1 -1
- package/docs/docs.json +44 -23
- package/index.d.ts +3 -19
- package/ios/RCTMGL-v10/RCTMGLCamera.swift +11 -1
- package/javascript/components/MarkerView.tsx +12 -1
- package/javascript/components/{NativeBridgeComponent.js → NativeBridgeComponent.tsx} +33 -10
- package/javascript/components/PointAnnotation.tsx +231 -0
- package/javascript/utils/index.d.ts +11 -3
- package/package.json +8 -8
- package/scripts/autogenHelpers/DocJSONBuilder.js +68 -12
- package/scripts/templates/component.md.ejs +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/AbstractMapFeature.java +0 -15
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraUpdateItem.java +0 -167
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraUpdateQueue.java +0 -73
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCamera.java +0 -662
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCameraManager.java +0 -102
- package/javascript/components/PointAnnotation.d.ts +0 -13
- package/javascript/components/PointAnnotation.js +0 -217
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
package com.mapbox.rctmgl.components.camera
|
|
2
|
+
|
|
3
|
+
import android.animation.Animator
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.location.Location
|
|
6
|
+
import com.mapbox.rctmgl.utils.GeoJSONUtils.toPoint
|
|
7
|
+
import com.mapbox.maps.plugin.gestures.gestures
|
|
8
|
+
import com.mapbox.rctmgl.location.LocationManager.Companion.getInstance
|
|
9
|
+
import com.mapbox.maps.plugin.animation.camera
|
|
10
|
+
import com.mapbox.rctmgl.utils.GeoJSONUtils.toLocation
|
|
11
|
+
import com.mapbox.maps.plugin.animation.MapAnimationOptions.Builder
|
|
12
|
+
import com.mapbox.maps.plugin.animation.flyTo
|
|
13
|
+
import com.mapbox.rctmgl.components.camera.RCTMGLCameraManager
|
|
14
|
+
import com.mapbox.rctmgl.components.AbstractMapFeature
|
|
15
|
+
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
|
|
16
|
+
import com.mapbox.rctmgl.components.camera.CameraStop
|
|
17
|
+
import com.mapbox.rctmgl.components.camera.CameraUpdateQueue
|
|
18
|
+
import com.mapbox.rctmgl.components.location.LocationComponentManager
|
|
19
|
+
import com.mapbox.rctmgl.utils.LatLngBounds
|
|
20
|
+
import com.mapbox.rctmgl.location.LocationManager.OnUserLocationChange
|
|
21
|
+
import com.mapbox.rctmgl.utils.GeoJSONUtils
|
|
22
|
+
import com.mapbox.maps.plugin.locationcomponent.OnIndicatorBearingChangedListener
|
|
23
|
+
import com.mapbox.maps.plugin.locationcomponent.OnIndicatorPositionChangedListener
|
|
24
|
+
import com.mapbox.rctmgl.components.camera.CameraUpdateItem
|
|
25
|
+
import com.mapbox.rctmgl.events.IEvent
|
|
26
|
+
import com.mapbox.rctmgl.events.MapChangeEvent
|
|
27
|
+
import com.mapbox.rctmgl.events.constants.EventTypes
|
|
28
|
+
import com.mapbox.rctmgl.components.camera.RCTMGLCamera
|
|
29
|
+
import com.mapbox.android.core.permissions.PermissionsManager
|
|
30
|
+
import com.mapbox.maps.plugin.animation.CameraAnimationsPlugin
|
|
31
|
+
import com.facebook.react.bridge.WritableMap
|
|
32
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
33
|
+
import com.mapbox.geojson.Point
|
|
34
|
+
import com.mapbox.maps.*
|
|
35
|
+
import com.mapbox.maps.plugin.PuckBearingSource
|
|
36
|
+
import com.mapbox.maps.plugin.locationcomponent.location
|
|
37
|
+
import com.mapbox.maps.plugin.locationcomponent.location2
|
|
38
|
+
import com.mapbox.maps.plugin.viewport.data.FollowPuckViewportStateBearing
|
|
39
|
+
import com.mapbox.maps.plugin.viewport.data.FollowPuckViewportStateOptions
|
|
40
|
+
import com.mapbox.maps.plugin.viewport.viewport
|
|
41
|
+
import com.mapbox.rctmgl.components.camera.constants.CameraMode
|
|
42
|
+
import com.mapbox.rctmgl.components.location.*
|
|
43
|
+
import com.mapbox.rctmgl.location.*
|
|
44
|
+
import com.mapbox.rctmgl.modules.RCTMGLLogging
|
|
45
|
+
import com.mapbox.rctmgl.utils.LatLng
|
|
46
|
+
import com.mapbox.rctmgl.utils.Logger
|
|
47
|
+
|
|
48
|
+
class RCTMGLCamera(private val mContext: Context, private val mManager: RCTMGLCameraManager) :
|
|
49
|
+
AbstractMapFeature(
|
|
50
|
+
mContext
|
|
51
|
+
) {
|
|
52
|
+
private var mMapView: RCTMGLMapView? = null
|
|
53
|
+
private var hasSentFirstRegion = false
|
|
54
|
+
private var mDefaultStop: CameraStop? = null
|
|
55
|
+
private var mCameraStop: CameraStop? = null
|
|
56
|
+
private val mCameraUpdateQueue: CameraUpdateQueue
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
// private LocationComponent mLocationComponent;
|
|
60
|
+
*/
|
|
61
|
+
private var mLocationComponentManager: LocationComponentManager? = null
|
|
62
|
+
private var mUserTrackingMode = 0
|
|
63
|
+
private var mUserTrackingState = UserTrackingState.POSSIBLE
|
|
64
|
+
private val mUserLocationVerticalAlignment = UserLocationVerticalAlignment.CENTER
|
|
65
|
+
private val mLocationManager: LocationManager?
|
|
66
|
+
private val mUserLocation: UserLocation = UserLocation()
|
|
67
|
+
private val mCenterCoordinate: ScreenCoordinate? = null
|
|
68
|
+
private val mAnimated = false
|
|
69
|
+
private val mHeading = 0.0
|
|
70
|
+
private var mFollowPitch : Double? = null
|
|
71
|
+
private var mFollowZoomLevel : Double? = null
|
|
72
|
+
private var mFollowHeading : Double? = null
|
|
73
|
+
private var mZoomLevel = -1.0
|
|
74
|
+
private var mMinZoomLevel = -1.0
|
|
75
|
+
private var mMaxZoomLevel = -1.0
|
|
76
|
+
private var mMaxBounds: LatLngBounds? = null
|
|
77
|
+
private var mFollowUserLocation = false
|
|
78
|
+
private var mFollowUserMode: String? = null
|
|
79
|
+
private val mLocationChangeListener: OnUserLocationChange = object : OnUserLocationChange {
|
|
80
|
+
override fun onLocationChange(nextLocation: Location?) {
|
|
81
|
+
if (mapboxMap == null || mLocationComponentManager == null || !mLocationComponentManager!!.hasLocationComponent() || !mFollowUserLocation) {
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
mUserLocation.currentLocation = nextLocation
|
|
85
|
+
sendUserLocationUpdateEvent(toPoint(nextLocation!!))
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
private val mLocationBearingChangedListener = OnIndicatorBearingChangedListener { v ->
|
|
89
|
+
if (mFollowUserLocation) {
|
|
90
|
+
mMapView!!.getMapboxMap().setCamera(CameraOptions.Builder().bearing(v).build())
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
private val mLocationPositionChangeListener = OnIndicatorPositionChangedListener { point ->
|
|
94
|
+
if (mFollowUserLocation) {
|
|
95
|
+
mMapView!!.getMapboxMap().setCamera(CameraOptions.Builder().center(point).build())
|
|
96
|
+
mMapView!!.gestures.focalPoint = mMapView!!.getMapboxMap().pixelForCoordinate(point)
|
|
97
|
+
sendUserLocationUpdateEvent(point)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
private val mCameraCallback: Animator.AnimatorListener = object : Animator.AnimatorListener {
|
|
101
|
+
override fun onAnimationStart(animator: Animator) {}
|
|
102
|
+
override fun onAnimationEnd(animator: Animator) {
|
|
103
|
+
if (!hasSentFirstRegion) {
|
|
104
|
+
mMapView!!.sendRegionChangeEvent(false)
|
|
105
|
+
hasSentFirstRegion = true
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
override fun onAnimationCancel(animator: Animator) {
|
|
110
|
+
if (!hasSentFirstRegion) {
|
|
111
|
+
mMapView!!.sendRegionChangeEvent(false)
|
|
112
|
+
hasSentFirstRegion = true
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
override fun onAnimationRepeat(animator: Animator) {}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
override fun addToMap(mapView: RCTMGLMapView) {
|
|
120
|
+
mMapView = mapView
|
|
121
|
+
setInitialCamera()
|
|
122
|
+
updateMaxMinZoomLevel()
|
|
123
|
+
updateMaxBounds()
|
|
124
|
+
mCameraStop?.let { updateCamera(it) }
|
|
125
|
+
if (mFollowUserLocation) {
|
|
126
|
+
// updateFollowLocation(mFollowUserLocation);
|
|
127
|
+
enableLocation()
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
override fun removeFromMap(mapView: RCTMGLMapView) {}
|
|
132
|
+
fun setStop(stop: CameraStop) {
|
|
133
|
+
mCameraStop = stop
|
|
134
|
+
mCameraStop!!.setCallback(mCameraCallback)
|
|
135
|
+
if (mMapView != null) {
|
|
136
|
+
mCameraStop?.let { updateCamera(it) }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
fun setDefaultStop(stop: CameraStop?) {
|
|
141
|
+
mDefaultStop = stop
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
fun setFollowPitch(pitch: Double) {
|
|
145
|
+
mFollowPitch = pitch
|
|
146
|
+
_updateViewportState();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fun setFollowZoomLevel(zoomLevel: Double) {
|
|
150
|
+
mFollowZoomLevel = zoomLevel
|
|
151
|
+
_updateViewportState();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
fun setFollowHeading(heading: Double) {
|
|
155
|
+
mFollowHeading = heading
|
|
156
|
+
_updateViewportState();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
fun setMaxBounds(bounds: LatLngBounds?) {
|
|
160
|
+
mMaxBounds = bounds
|
|
161
|
+
updateMaxBounds()
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private fun updateMaxBounds() {
|
|
165
|
+
/*
|
|
166
|
+
MapboxMap map = getMapboxMap();
|
|
167
|
+
if (map != null && mMaxBounds != null) {
|
|
168
|
+
map.setLatLngBoundsForCameraTarget(mMaxBounds);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
*/
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private fun updateMaxMinZoomLevel() {
|
|
175
|
+
/*
|
|
176
|
+
MapboxMap map = getMapboxMap();
|
|
177
|
+
if (map != null) {
|
|
178
|
+
if (mMinZoomLevel >= 0.0) {
|
|
179
|
+
map.setMinZoomPreference(mMinZoomLevel);
|
|
180
|
+
}
|
|
181
|
+
if (mMaxZoomLevel >= 0.0) {
|
|
182
|
+
map.setMaxZoomPreference(mMaxZoomLevel);
|
|
183
|
+
}
|
|
184
|
+
}*/
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private fun setInitialCamera() {
|
|
188
|
+
val map = mMapView!!.getMapboxMap()
|
|
189
|
+
if (mDefaultStop != null) {
|
|
190
|
+
mDefaultStop!!.setDuration(0)
|
|
191
|
+
mDefaultStop!!.setMode(CameraMode.NONE)
|
|
192
|
+
val item = mDefaultStop!!.toCameraUpdate(mMapView!!)
|
|
193
|
+
item.run()
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private fun updateCamera(cameraStop: CameraStop) {
|
|
198
|
+
mCameraUpdateQueue.offer(cameraStop)
|
|
199
|
+
mCameraUpdateQueue.execute(mMapView)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private fun updateUserTrackingMode(userTrackingMode: Int) {
|
|
203
|
+
/* v10todo
|
|
204
|
+
mUserLocation.setTrackingMode(userTrackingMode);
|
|
205
|
+
IEvent event = new MapUserTrackingModeEvent(this, userTrackingMode);
|
|
206
|
+
mManager.handleEvent(event);
|
|
207
|
+
*/
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private fun updateUserLocation(isAnimated: Boolean) {
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// NOTE: The direction of this is used for map rotation only, not location layer rotation
|
|
215
|
+
private val directionForUserLocationUpdate: Double
|
|
216
|
+
private get() {
|
|
217
|
+
// NOTE: The direction of this is used for map rotation only, not location layer rotation
|
|
218
|
+
val currentCamera = mMapView!!.getMapboxMap().cameraState
|
|
219
|
+
var direction = currentCamera.bearing
|
|
220
|
+
val userTrackingMode = mUserLocation.trackingMode
|
|
221
|
+
if (userTrackingMode == UserTrackingMode.FollowWithHeading || userTrackingMode == UserTrackingMode.FollowWithCourse) {
|
|
222
|
+
direction = mUserLocation.bearing
|
|
223
|
+
} else if (mHeading != 0.0) {
|
|
224
|
+
direction = mHeading
|
|
225
|
+
}
|
|
226
|
+
return direction
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private fun sendUserLocationUpdateEvent(point: Point?) {
|
|
230
|
+
if (point == null) {
|
|
231
|
+
return
|
|
232
|
+
}
|
|
233
|
+
val event: IEvent = MapChangeEvent(
|
|
234
|
+
this, EventTypes.USER_LOCATION_UPDATED, makeLocationChangePayload(
|
|
235
|
+
toLocation(point)
|
|
236
|
+
)
|
|
237
|
+
)
|
|
238
|
+
mManager.handleEvent(event)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private fun hasSetCenterCoordinate(): Boolean {
|
|
242
|
+
val state = mapboxMap!!.cameraState
|
|
243
|
+
val center = state.center
|
|
244
|
+
return center.latitude() != 0.0 && center.longitude() != 0.0
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
init {
|
|
248
|
+
mCameraUpdateQueue = CameraUpdateQueue()
|
|
249
|
+
mLocationManager = getInstance(mContext)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private fun enableLocation() {
|
|
253
|
+
if (!PermissionsManager.areLocationPermissionsGranted(mContext)) {
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
if (!mLocationManager!!.isActive()) {
|
|
257
|
+
mLocationManager.enable()
|
|
258
|
+
}
|
|
259
|
+
mMapView!!.getMapboxMap().getStyle {
|
|
260
|
+
enableLocationComponent(it)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private fun enableLocationComponent(style: Style) {
|
|
265
|
+
updateUserLocation(false)
|
|
266
|
+
updateLocationLayer(style)
|
|
267
|
+
val lastKnownLocation = mLocationManager!!.lastKnownLocation
|
|
268
|
+
mLocationManager.addLocationListener(mLocationChangeListener)
|
|
269
|
+
if (lastKnownLocation != null) {
|
|
270
|
+
mLocationChangeListener.onLocationChange(lastKnownLocation)
|
|
271
|
+
postDelayed({ mMapView!!.sendRegionDidChangeEvent() }, 200)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
private fun updateLocationLayer(style: Style) {
|
|
276
|
+
if (mLocationComponentManager == null) {
|
|
277
|
+
mLocationComponentManager = mMapView!!.locationComponentManager
|
|
278
|
+
}
|
|
279
|
+
mLocationComponentManager!!.update(style)
|
|
280
|
+
if (mFollowUserLocation) {
|
|
281
|
+
mLocationComponentManager!!.setCameraMode(
|
|
282
|
+
UserTrackingMode.getCameraMode(
|
|
283
|
+
mUserTrackingMode
|
|
284
|
+
)
|
|
285
|
+
)
|
|
286
|
+
}
|
|
287
|
+
mLocationComponentManager!!.setFollowUserLocation(mFollowUserLocation)
|
|
288
|
+
if (mFollowUserLocation) {
|
|
289
|
+
mLocationComponentManager!!.setCameraMode(
|
|
290
|
+
UserTrackingMode.getCameraMode(
|
|
291
|
+
mUserTrackingMode
|
|
292
|
+
)
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
/*
|
|
296
|
+
mLocationComponentManager.addOnCameraTrackingChangedListener(new OnCameraTrackingChangedListener() {
|
|
297
|
+
@Override public void onCameraTrackingChanged(int currentMode) {
|
|
298
|
+
int userTrackingMode = UserTrackingMode.NONE;
|
|
299
|
+
switch (currentMode) {
|
|
300
|
+
case CameraMode.NONE:
|
|
301
|
+
userTrackingMode = UserTrackingMode.NONE;
|
|
302
|
+
break;
|
|
303
|
+
case CameraMode.TRACKING:
|
|
304
|
+
userTrackingMode = UserTrackingMode.FOLLOW;
|
|
305
|
+
break;
|
|
306
|
+
case CameraMode.TRACKING_COMPASS:
|
|
307
|
+
userTrackingMode = UserTrackingMode.FollowWithHeading;
|
|
308
|
+
break;
|
|
309
|
+
case CameraMode.TRACKING_GPS:
|
|
310
|
+
userTrackingMode = UserTrackingMode.FollowWithCourse;
|
|
311
|
+
break;
|
|
312
|
+
default:
|
|
313
|
+
userTrackingMode = UserTrackingMode.NONE;
|
|
314
|
+
}
|
|
315
|
+
updateUserTrackingMode(userTrackingMode);
|
|
316
|
+
}
|
|
317
|
+
@Override public void onCameraTrackingDismissed() {
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
*/
|
|
321
|
+
} else {
|
|
322
|
+
mLocationComponentManager!!.setCameraMode(CameraMode.NONE)
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
fun setMinZoomLevel(zoomLevel: Double) {
|
|
327
|
+
mMinZoomLevel = zoomLevel
|
|
328
|
+
updateMaxMinZoomLevel()
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
fun setMaxZoomLevel(zoomLevel: Double) {
|
|
332
|
+
mMaxZoomLevel = zoomLevel
|
|
333
|
+
updateMaxMinZoomLevel()
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
fun setZoomLevel(zoomLevel: Double) {
|
|
337
|
+
mZoomLevel = zoomLevel
|
|
338
|
+
updateCameraPositionIfNeeded(false)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
private fun buildCamera(
|
|
342
|
+
previousPosition: CameraState,
|
|
343
|
+
shouldUpdateTarget: Boolean
|
|
344
|
+
): CameraOptions {
|
|
345
|
+
return if (shouldUpdateTarget) {
|
|
346
|
+
previousPosition.toCameraOptions(mCenterCoordinate)
|
|
347
|
+
} else {
|
|
348
|
+
previousPosition.toCameraOptions(null)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private fun updateCameraPositionIfNeeded(shouldUpdateTarget: Boolean) {
|
|
353
|
+
if (mMapView != null) {
|
|
354
|
+
val prevPosition = mapboxMap!!.cameraState
|
|
355
|
+
val cameraUpdate = /*CameraUpdateFactory.newCameraPosition(*/
|
|
356
|
+
buildCamera(prevPosition, shouldUpdateTarget)
|
|
357
|
+
if (mAnimated) {
|
|
358
|
+
mapboxMap!!.flyTo(cameraUpdate, null)
|
|
359
|
+
} else {
|
|
360
|
+
mapboxMap!!.setCamera(cameraUpdate)
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
fun setUserTrackingMode(userTrackingMode: Int) {
|
|
366
|
+
val oldTrackingMode = mUserTrackingMode
|
|
367
|
+
mUserTrackingMode = userTrackingMode
|
|
368
|
+
updateUserTrackingMode(userTrackingMode)
|
|
369
|
+
when (mUserTrackingMode) {
|
|
370
|
+
UserTrackingMode.NONE -> mUserTrackingState = UserTrackingState.POSSIBLE
|
|
371
|
+
UserTrackingMode.FOLLOW, UserTrackingMode.FollowWithCourse, UserTrackingMode.FollowWithHeading -> if (oldTrackingMode == UserTrackingMode.NONE) {
|
|
372
|
+
mUserTrackingState = UserTrackingState.POSSIBLE
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (mapboxMap != null) {
|
|
376
|
+
updateLocationLayer(mapboxMap!!.getStyle()!!)
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
fun setFollowUserLocation(value: Boolean) {
|
|
381
|
+
mFollowUserLocation = value
|
|
382
|
+
_updateViewportState()
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
fun _updateViewportState() {
|
|
386
|
+
mMapView?.let {
|
|
387
|
+
val map = it
|
|
388
|
+
val viewport = map.viewport;
|
|
389
|
+
if (mFollowUserLocation == false) {
|
|
390
|
+
viewport.idle()
|
|
391
|
+
mLocationManager?.disable()
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
mLocationManager?.let {
|
|
396
|
+
val provider = it.provider
|
|
397
|
+
|
|
398
|
+
map.location.setLocationProvider(provider);
|
|
399
|
+
map.location2.setLocationProvider(provider);
|
|
400
|
+
it.enable();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
val location = map.location2
|
|
404
|
+
val followOptions = FollowPuckViewportStateOptions.Builder()
|
|
405
|
+
val cameraState = map.getMapboxMap().cameraState
|
|
406
|
+
when (mFollowUserMode ?: "normal") {
|
|
407
|
+
"compass" -> {
|
|
408
|
+
location.puckBearingEnabled = true
|
|
409
|
+
location.puckBearingSource = PuckBearingSource.HEADING
|
|
410
|
+
followOptions.bearing(FollowPuckViewportStateBearing.SyncWithLocationPuck)
|
|
411
|
+
}
|
|
412
|
+
"course" -> {
|
|
413
|
+
location.puckBearingEnabled = true
|
|
414
|
+
location.puckBearingSource = PuckBearingSource.COURSE
|
|
415
|
+
followOptions.bearing(FollowPuckViewportStateBearing.SyncWithLocationPuck)
|
|
416
|
+
}
|
|
417
|
+
"normal" -> {
|
|
418
|
+
location.puckBearingEnabled = false
|
|
419
|
+
when(val it=mFollowHeading) {
|
|
420
|
+
null -> followOptions.bearing( FollowPuckViewportStateBearing.Constant(
|
|
421
|
+
cameraState.bearing
|
|
422
|
+
))
|
|
423
|
+
else -> followOptions.bearing( FollowPuckViewportStateBearing.Constant(
|
|
424
|
+
cameraState.bearing
|
|
425
|
+
))
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
else -> {
|
|
429
|
+
Logger.e("RCTMGLCamera", "unexpected follow mode: $mFollowUserMode")
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
when(val it=mFollowPitch) {
|
|
434
|
+
null -> followOptions.pitch(cameraState.pitch)
|
|
435
|
+
else -> followOptions.pitch(it)
|
|
436
|
+
}
|
|
437
|
+
when(val it=mFollowZoomLevel) {
|
|
438
|
+
null -> followOptions.zoom(cameraState.zoom)
|
|
439
|
+
else -> followOptions.zoom(mFollowZoomLevel)
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
val followState = viewport.makeFollowPuckViewportState(followOptions.build())
|
|
443
|
+
viewport.transitionTo(followState)
|
|
444
|
+
}
|
|
445
|
+
mapboxMap?.let {
|
|
446
|
+
it.getStyle()?.let {
|
|
447
|
+
updateLocationLayer(it)
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
fun setFollowUserMode(mode: String?) {
|
|
453
|
+
mFollowUserMode = mode
|
|
454
|
+
_updateViewportState()
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
private fun updatedFollowUserMode() {
|
|
458
|
+
if (mFollowUserLocation) {
|
|
459
|
+
setUserTrackingMode(UserTrackingMode.fromString(mFollowUserMode))
|
|
460
|
+
} else {
|
|
461
|
+
setUserTrackingMode(UserTrackingMode.NONE)
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
val mapboxMap: MapboxMap?
|
|
466
|
+
get() = if (mMapView == null) {
|
|
467
|
+
null
|
|
468
|
+
} else mMapView!!.getMapboxMap()
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Create a payload of the location data per the web api geolocation spec
|
|
472
|
+
* https://dev.w3.org/geo/api/spec-source.html#position
|
|
473
|
+
*
|
|
474
|
+
* @return
|
|
475
|
+
*/
|
|
476
|
+
private fun makeLocationChangePayload(location: Location): WritableMap {
|
|
477
|
+
val positionProperties: WritableMap = WritableNativeMap()
|
|
478
|
+
val coords: WritableMap = WritableNativeMap()
|
|
479
|
+
coords.putDouble("longitude", location.longitude)
|
|
480
|
+
coords.putDouble("latitude", location.latitude)
|
|
481
|
+
coords.putDouble("altitude", location.altitude)
|
|
482
|
+
coords.putDouble("accuracy", location.accuracy.toDouble())
|
|
483
|
+
// A better solution will be to pull the heading from the compass engine,
|
|
484
|
+
// unfortunately the api is not publicly available in the mapbox sdk
|
|
485
|
+
coords.putDouble("heading", location.bearing.toDouble())
|
|
486
|
+
coords.putDouble("course", location.bearing.toDouble())
|
|
487
|
+
coords.putDouble("speed", location.speed.toDouble())
|
|
488
|
+
positionProperties.putMap("coords", coords)
|
|
489
|
+
positionProperties.putDouble("timestamp", location.time.toDouble())
|
|
490
|
+
return positionProperties
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
companion object {
|
|
494
|
+
const val USER_LOCATION_CAMERA_MOVE_DURATION = 1000
|
|
495
|
+
const val minimumZoomLevelForUserTracking = 10.5
|
|
496
|
+
const val defaultZoomLevelForUserTracking = 14.0
|
|
497
|
+
}
|
|
498
|
+
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCameraManager.kt
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
package com.mapbox.rctmgl.components.camera
|
|
2
|
+
|
|
3
|
+
import com.mapbox.rctmgl.components.camera.CameraStop.Companion.fromReadableMap
|
|
4
|
+
import com.mapbox.maps.MapboxMap
|
|
5
|
+
import com.mapbox.maps.CameraOptions
|
|
6
|
+
import com.mapbox.maps.plugin.animation.CameraAnimationsPlugin
|
|
7
|
+
import android.view.animation.LinearInterpolator
|
|
8
|
+
import android.view.animation.AccelerateDecelerateInterpolator
|
|
9
|
+
import com.mapbox.rctmgl.components.camera.CameraStop
|
|
10
|
+
import com.mapbox.rctmgl.components.camera.CameraUpdateQueue.OnCompleteAllListener
|
|
11
|
+
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView
|
|
12
|
+
import com.mapbox.rctmgl.components.camera.CameraUpdateItem
|
|
13
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
14
|
+
import com.mapbox.rctmgl.components.AbstractEventEmitter
|
|
15
|
+
import com.mapbox.rctmgl.components.camera.RCTMGLCamera
|
|
16
|
+
import com.mapbox.rctmgl.components.camera.RCTMGLCameraManager
|
|
17
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
18
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
19
|
+
import com.facebook.react.bridge.ReadableMap
|
|
20
|
+
import java.lang.AssertionError
|
|
21
|
+
import java.util.HashMap
|
|
22
|
+
|
|
23
|
+
//import com.mapbox.rctmgl.utils.GeoJSONUtils;
|
|
24
|
+
class RCTMGLCameraManager(private val mContext: ReactApplicationContext) :
|
|
25
|
+
AbstractEventEmitter<RCTMGLCamera?>(
|
|
26
|
+
mContext
|
|
27
|
+
) {
|
|
28
|
+
override fun customEvents(): Map<String, String>? {
|
|
29
|
+
return HashMap()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override fun getName(): String {
|
|
33
|
+
return REACT_CLASS
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override fun createViewInstance(reactContext: ThemedReactContext): RCTMGLCamera {
|
|
37
|
+
return RCTMGLCamera(reactContext, this)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@ReactProp(name = "stop")
|
|
41
|
+
fun setStop(camera: RCTMGLCamera, map: ReadableMap?) {
|
|
42
|
+
if (map != null) {
|
|
43
|
+
val stop = fromReadableMap(mContext, map, null)
|
|
44
|
+
camera.setStop(stop)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@ReactProp(name = "defaultStop")
|
|
49
|
+
fun setDefaultStop(camera: RCTMGLCamera, map: ReadableMap?) {
|
|
50
|
+
if (map != null) {
|
|
51
|
+
val stop = fromReadableMap(mContext, map, null)
|
|
52
|
+
camera.setDefaultStop(stop)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/*v10todo
|
|
57
|
+
@ReactProp(name="maxBounds")
|
|
58
|
+
public void setMaxBounds(RCTMGLCamera camera, String value) {
|
|
59
|
+
if (value != null) {
|
|
60
|
+
FeatureCollection collection = FeatureCollection.fromJson(value);
|
|
61
|
+
camera.setMaxBounds(GeoJSONUtils.toLatLngBounds(collection));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
*/
|
|
65
|
+
@ReactProp(name = "userTrackingMode")
|
|
66
|
+
fun setUserTrackingMode(camera: RCTMGLCamera, userTrackingMode: Int) {
|
|
67
|
+
camera.setUserTrackingMode(userTrackingMode)
|
|
68
|
+
throw AssertionError("Unused code")
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@ReactProp(name = "followZoomLevel")
|
|
72
|
+
fun setZoomLevel(camera: RCTMGLCamera, zoomLevel: Double) {
|
|
73
|
+
camera.setZoomLevel(zoomLevel)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@ReactProp(name = "followUserLocation")
|
|
77
|
+
fun setFollowUserLocation(camera: RCTMGLCamera, value: Boolean) {
|
|
78
|
+
camera.setFollowUserLocation(value)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@ReactProp(name = "followUserMode")
|
|
82
|
+
fun setFollowUserMode(camera: RCTMGLCamera, value: String?) {
|
|
83
|
+
camera.setFollowUserMode(value)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@ReactProp(name = "minZoomLevel")
|
|
87
|
+
fun setMinZoomLevel(camera: RCTMGLCamera, value: Double) {
|
|
88
|
+
camera.setMinZoomLevel(value)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@ReactProp(name = "maxZoomLevel")
|
|
92
|
+
fun setMaxZoomLevel(camera: RCTMGLCamera, value: Double) {
|
|
93
|
+
camera.setMaxZoomLevel(value)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@ReactProp(name = "followPitch")
|
|
97
|
+
fun setFollowPitch(camera: RCTMGLCamera, value: Double) {
|
|
98
|
+
camera.setFollowPitch(value)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@ReactProp(name = "followHeading")
|
|
102
|
+
fun setFollowHeading(camera: RCTMGLCamera, value: Double) {
|
|
103
|
+
camera.setFollowHeading(value)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@ReactProp(name = "followZoomLevel")
|
|
107
|
+
fun setFollowZoomLevel(camera: RCTMGLCamera, value: Double) {
|
|
108
|
+
camera.setFollowZoomLevel(value)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
companion object {
|
|
112
|
+
const val REACT_CLASS = "RCTMGLCamera"
|
|
113
|
+
}
|
|
114
|
+
}
|
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/sources/RCTSource.kt
CHANGED
|
@@ -58,12 +58,14 @@ abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(co
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
protected fun addLayerToMap(layer: AbstractSourceConsumer?, childPosition: Int) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
mMapView?.let {
|
|
62
|
+
val mapView = it
|
|
63
|
+
layer?.let {
|
|
64
|
+
it.addToMap(mapView)
|
|
65
|
+
if (!mLayers.contains(it)) {
|
|
66
|
+
mLayers.add(childPosition, it)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -134,7 +136,7 @@ abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(co
|
|
|
134
136
|
if (mLayers.size > 0) {
|
|
135
137
|
for (i in mLayers.indices) {
|
|
136
138
|
val layer = mLayers[i]
|
|
137
|
-
layer.removeFromMap(
|
|
139
|
+
layer.removeFromMap(mapView)
|
|
138
140
|
}
|
|
139
141
|
}
|
|
140
142
|
if (mQueuedLayers != null) {
|
|
@@ -178,8 +180,11 @@ abstract class RCTSource<T : Source?>(context: Context?) : AbstractMapFeature(co
|
|
|
178
180
|
}
|
|
179
181
|
|
|
180
182
|
protected fun removeLayerFromMap(layer: AbstractSourceConsumer?, childPosition: Int) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
mMapView?.let {
|
|
184
|
+
val mapView = it
|
|
185
|
+
layer?.let {
|
|
186
|
+
it.removeFromMap(mapView)
|
|
187
|
+
}
|
|
183
188
|
}
|
|
184
189
|
if (mQueuedLayers != null && mQueuedLayers!!.size > 0) {
|
|
185
190
|
mQueuedLayers?.removeAt(childPosition)
|
package/docs/Annotation.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## props
|
|
6
6
|
| Prop | Type | Default | Required | Description |
|
|
7
|
-
| ---- |
|
|
7
|
+
| ---- | :-- | :----- | :------ | :---------- |
|
|
8
8
|
| id | `string` | `none` | `true` | FIX ME NO DESCRIPTION |
|
|
9
9
|
| animated | `bool` | `false` | `false` | FIX ME NO DESCRIPTION |
|
|
10
10
|
| animationDuration | `number` | `1000` | `false` | FIX ME NO DESCRIPTION |
|
package/docs/Atmosphere.md
CHANGED