@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
package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/RCTMGLCamera.java
DELETED
|
@@ -1,662 +0,0 @@
|
|
|
1
|
-
package com.mapbox.rctmgl.components.camera;
|
|
2
|
-
|
|
3
|
-
import android.animation.Animator;
|
|
4
|
-
import android.content.Context;
|
|
5
|
-
import android.location.Location;
|
|
6
|
-
|
|
7
|
-
/*
|
|
8
|
-
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
|
9
|
-
import com.mapbox.mapboxsdk.camera.CameraUpdate;
|
|
10
|
-
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
|
11
|
-
import com.mapbox.mapboxsdk.geometry.LatLng;
|
|
12
|
-
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
|
13
|
-
import com.mapbox.mapboxsdk.geometry.VisibleRegion;
|
|
14
|
-
import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener;
|
|
15
|
-
import com.mapbox.mapboxsdk.location.modes.CameraMode;
|
|
16
|
-
import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
|
17
|
-
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
|
18
|
-
import com.mapbox.mapboxsdk.maps.Style;
|
|
19
|
-
import com.mapbox.mapboxsdk.location.LocationComponent;
|
|
20
|
-
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
|
|
21
|
-
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
|
|
22
|
-
*?
|
|
23
|
-
*/
|
|
24
|
-
// import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
|
|
25
|
-
// import com.mapbox.maps.CameraOptions;
|
|
26
|
-
import com.mapbox.maps.CameraBounds;
|
|
27
|
-
import com.mapbox.maps.CameraOptions;
|
|
28
|
-
import com.mapbox.maps.CameraState;
|
|
29
|
-
import com.mapbox.maps.CoordinateBounds;
|
|
30
|
-
import com.mapbox.maps.ExtensionUtils;
|
|
31
|
-
import com.mapbox.maps.MapboxMap;
|
|
32
|
-
import com.mapbox.maps.ScreenCoordinate;
|
|
33
|
-
import com.mapbox.maps.Style;
|
|
34
|
-
import com.mapbox.maps.plugin.animation.CameraAnimationsPlugin;
|
|
35
|
-
import com.mapbox.maps.plugin.animation.CameraAnimationsUtils;
|
|
36
|
-
import com.mapbox.maps.plugin.animation.CameraOptionsUtilsKt;
|
|
37
|
-
import com.mapbox.maps.plugin.animation.MapAnimationOptions;
|
|
38
|
-
import com.mapbox.maps.plugin.delegates.MapPluginProviderDelegate;
|
|
39
|
-
import com.mapbox.maps.plugin.gestures.GesturesUtils;
|
|
40
|
-
import com.mapbox.maps.plugin.locationcomponent.LocationComponentPlugin;
|
|
41
|
-
import com.mapbox.maps.plugin.locationcomponent.LocationComponentUtils;
|
|
42
|
-
import com.mapbox.maps.plugin.locationcomponent.OnIndicatorBearingChangedListener;
|
|
43
|
-
import com.mapbox.maps.plugin.locationcomponent.OnIndicatorPositionChangedListener;
|
|
44
|
-
import com.mapbox.rctmgl.components.AbstractMapFeature;
|
|
45
|
-
// import com.mapbox.rctmgl.components.location.LocationComponentManager;
|
|
46
|
-
import com.mapbox.rctmgl.components.camera.constants.CameraMode;
|
|
47
|
-
import com.mapbox.rctmgl.components.location.LocationComponentManager;
|
|
48
|
-
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView;
|
|
49
|
-
import com.mapbox.rctmgl.events.IEvent;
|
|
50
|
-
//import com.mapbox.rctmgl.events.MapUserTrackingModeEvent;
|
|
51
|
-
//import com.mapbox.rctmgl.events.MapChangeEvent;
|
|
52
|
-
// import com.mapbox.rctmgl.location.LocationManager;
|
|
53
|
-
// import com.mapbox.rctmgl.location.UserLocation;
|
|
54
|
-
// import com.mapbox.rctmgl.location.UserLocationVerticalAlignment;
|
|
55
|
-
// import com.mapbox.rctmgl.location.UserTrackingMode;
|
|
56
|
-
// import com.mapbox.rctmgl.location.UserTrackingState;
|
|
57
|
-
// import com.mapbox.rctmgl.utils.GeoJSONUtils;
|
|
58
|
-
|
|
59
|
-
import com.mapbox.rctmgl.R;
|
|
60
|
-
|
|
61
|
-
// import com.mapbox.rctmgl.events.constants.EventTypes;
|
|
62
|
-
|
|
63
|
-
import com.facebook.react.bridge.WritableMap;
|
|
64
|
-
import com.facebook.react.bridge.WritableNativeMap;
|
|
65
|
-
|
|
66
|
-
import com.mapbox.geojson.Point;
|
|
67
|
-
|
|
68
|
-
import com.mapbox.android.core.permissions.PermissionsManager;
|
|
69
|
-
import com.mapbox.rctmgl.events.MapChangeEvent;
|
|
70
|
-
import com.mapbox.rctmgl.events.constants.EventTypes;
|
|
71
|
-
import com.mapbox.rctmgl.location.LocationManager;
|
|
72
|
-
import com.mapbox.rctmgl.location.UserLocation;
|
|
73
|
-
import com.mapbox.rctmgl.location.UserLocationVerticalAlignment;
|
|
74
|
-
import com.mapbox.rctmgl.location.UserTrackingMode;
|
|
75
|
-
import com.mapbox.rctmgl.location.UserTrackingState;
|
|
76
|
-
import com.mapbox.rctmgl.utils.GeoJSONUtils;
|
|
77
|
-
import com.mapbox.rctmgl.utils.LatLng;
|
|
78
|
-
import com.mapbox.rctmgl.utils.LatLngBounds;
|
|
79
|
-
|
|
80
|
-
import androidx.annotation.NonNull;
|
|
81
|
-
|
|
82
|
-
import kotlin.jvm.functions.Function1;
|
|
83
|
-
|
|
84
|
-
public class RCTMGLCamera extends AbstractMapFeature {
|
|
85
|
-
private RCTMGLCameraManager mManager;
|
|
86
|
-
private RCTMGLMapView mMapView;
|
|
87
|
-
|
|
88
|
-
private boolean hasSentFirstRegion = false;
|
|
89
|
-
|
|
90
|
-
private CameraStop mDefaultStop;
|
|
91
|
-
|
|
92
|
-
private CameraStop mCameraStop;
|
|
93
|
-
private CameraUpdateQueue mCameraUpdateQueue;
|
|
94
|
-
|
|
95
|
-
/*
|
|
96
|
-
// private LocationComponent mLocationComponent;
|
|
97
|
-
*/
|
|
98
|
-
private LocationComponentManager mLocationComponentManager;
|
|
99
|
-
|
|
100
|
-
private int mUserTrackingMode;
|
|
101
|
-
private int mUserTrackingState = UserTrackingState.POSSIBLE;
|
|
102
|
-
private int mUserLocationVerticalAlignment = UserLocationVerticalAlignment.CENTER;
|
|
103
|
-
|
|
104
|
-
public static final int USER_LOCATION_CAMERA_MOVE_DURATION = 1000;
|
|
105
|
-
|
|
106
|
-
private LocationManager mLocationManager;
|
|
107
|
-
private UserLocation mUserLocation;
|
|
108
|
-
private ScreenCoordinate mCenterCoordinate;
|
|
109
|
-
|
|
110
|
-
private boolean mAnimated;
|
|
111
|
-
private double mHeading;
|
|
112
|
-
private double mPitch;
|
|
113
|
-
private double mZoomLevel = -1;
|
|
114
|
-
|
|
115
|
-
private double mMinZoomLevel = -1;
|
|
116
|
-
private double mMaxZoomLevel = -1;
|
|
117
|
-
|
|
118
|
-
private LatLngBounds mMaxBounds;
|
|
119
|
-
|
|
120
|
-
private boolean mFollowUserLocation;
|
|
121
|
-
private String mFollowUserMode;
|
|
122
|
-
|
|
123
|
-
private Context mContext;
|
|
124
|
-
|
|
125
|
-
private LocationManager.OnUserLocationChange mLocationChangeListener = new LocationManager.OnUserLocationChange() {
|
|
126
|
-
@Override
|
|
127
|
-
public void onLocationChange(Location nextLocation) {
|
|
128
|
-
if (getMapboxMap() == null || mLocationComponentManager == null || !mLocationComponentManager.hasLocationComponent() || (!mFollowUserLocation)) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
mUserLocation.setCurrentLocation(nextLocation);
|
|
133
|
-
sendUserLocationUpdateEvent(GeoJSONUtils.toPoint(nextLocation));
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
private OnIndicatorBearingChangedListener mLocationBearingChangedListener = new OnIndicatorBearingChangedListener() {
|
|
138
|
-
@Override
|
|
139
|
-
public void onIndicatorBearingChanged(double v) {
|
|
140
|
-
if (mFollowUserLocation) {
|
|
141
|
-
mMapView.getMapboxMap().setCamera(new CameraOptions.Builder().bearing(v).build());
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
private OnIndicatorPositionChangedListener mLocationPositionChangeListener = new OnIndicatorPositionChangedListener() {
|
|
147
|
-
@Override
|
|
148
|
-
public void onIndicatorPositionChanged(@NonNull Point point) {
|
|
149
|
-
if (mFollowUserLocation) {
|
|
150
|
-
mMapView.getMapboxMap().setCamera(new CameraOptions.Builder().center(point).build());
|
|
151
|
-
GesturesUtils.getGestures(mMapView).setFocalPoint(mMapView.getMapboxMap().pixelForCoordinate(point));
|
|
152
|
-
|
|
153
|
-
sendUserLocationUpdateEvent(point);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
private Animator.AnimatorListener mCameraCallback = new Animator.AnimatorListener() {
|
|
160
|
-
@Override
|
|
161
|
-
public void onAnimationStart(Animator animator) {
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
@Override
|
|
166
|
-
public void onAnimationEnd(Animator animator) {
|
|
167
|
-
if (!hasSentFirstRegion) {
|
|
168
|
-
mMapView.sendRegionChangeEvent(false);
|
|
169
|
-
hasSentFirstRegion = true;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
@Override
|
|
174
|
-
public void onAnimationCancel(Animator animator) {
|
|
175
|
-
if (!hasSentFirstRegion) {
|
|
176
|
-
mMapView.sendRegionChangeEvent(false);
|
|
177
|
-
hasSentFirstRegion = true;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
@Override
|
|
182
|
-
public void onAnimationRepeat(Animator animator) {
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
public RCTMGLCamera(Context context, RCTMGLCameraManager manager) {
|
|
188
|
-
super(context);
|
|
189
|
-
mContext = context;
|
|
190
|
-
mManager = manager;
|
|
191
|
-
mCameraUpdateQueue = new CameraUpdateQueue();
|
|
192
|
-
|
|
193
|
-
mUserLocation = new UserLocation();
|
|
194
|
-
mLocationManager = LocationManager.getInstance(context);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
@Override
|
|
198
|
-
public void addToMap(RCTMGLMapView mapView) {
|
|
199
|
-
mMapView = mapView;
|
|
200
|
-
|
|
201
|
-
setInitialCamera();
|
|
202
|
-
updateMaxMinZoomLevel();
|
|
203
|
-
updateMaxBounds();
|
|
204
|
-
|
|
205
|
-
if (mCameraStop != null) {
|
|
206
|
-
updateCamera();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (mFollowUserLocation) {
|
|
210
|
-
// updateFollowLocation(mFollowUserLocation);
|
|
211
|
-
enableLocation();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
@Override
|
|
216
|
-
public void removeFromMap(RCTMGLMapView mapView) {
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
public void setStop(CameraStop stop) {
|
|
221
|
-
mCameraStop = stop;
|
|
222
|
-
mCameraStop.setCallback(mCameraCallback);
|
|
223
|
-
|
|
224
|
-
if (mMapView != null) {
|
|
225
|
-
updateCamera();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
public void setDefaultStop(CameraStop stop) {
|
|
230
|
-
mDefaultStop = stop;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
public void setFollowPitch(double pitch) {
|
|
234
|
-
mPitch = pitch;
|
|
235
|
-
// updateCameraPositionIfNeeded(true);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
public void setMaxBounds(LatLngBounds bounds) {
|
|
239
|
-
mMaxBounds = bounds;
|
|
240
|
-
updateMaxBounds();
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
private void updateMaxBounds() {
|
|
244
|
-
/*
|
|
245
|
-
MapboxMap map = getMapboxMap();
|
|
246
|
-
if (map != null && mMaxBounds != null) {
|
|
247
|
-
map.setLatLngBoundsForCameraTarget(mMaxBounds);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
*/
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
private void updateMaxMinZoomLevel() {
|
|
254
|
-
/*
|
|
255
|
-
MapboxMap map = getMapboxMap();
|
|
256
|
-
if (map != null) {
|
|
257
|
-
if (mMinZoomLevel >= 0.0) {
|
|
258
|
-
map.setMinZoomPreference(mMinZoomLevel);
|
|
259
|
-
}
|
|
260
|
-
if (mMaxZoomLevel >= 0.0) {
|
|
261
|
-
map.setMaxZoomPreference(mMaxZoomLevel);
|
|
262
|
-
}
|
|
263
|
-
}*/
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
private void setInitialCamera() {
|
|
267
|
-
MapboxMap map = mMapView.getMapboxMap();
|
|
268
|
-
|
|
269
|
-
if (mDefaultStop != null) {
|
|
270
|
-
mDefaultStop.setDuration(0);
|
|
271
|
-
mDefaultStop.setMode(com.mapbox.rctmgl.components.camera.constants.CameraMode.NONE);
|
|
272
|
-
CameraUpdateItem item = mDefaultStop.toCameraUpdate(mMapView);
|
|
273
|
-
item.run();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
private void updateCamera() {
|
|
278
|
-
mCameraUpdateQueue.offer(mCameraStop);
|
|
279
|
-
mCameraUpdateQueue.execute(mMapView);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
private void updateUserTrackingMode(int userTrackingMode) {
|
|
283
|
-
/* v10todo
|
|
284
|
-
mUserLocation.setTrackingMode(userTrackingMode);
|
|
285
|
-
IEvent event = new MapUserTrackingModeEvent(this, userTrackingMode);
|
|
286
|
-
mManager.handleEvent(event);
|
|
287
|
-
*/
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
private void updateUserLocation(boolean isAnimated) {
|
|
291
|
-
if ((!mFollowUserLocation) || mUserLocation.getTrackingMode() == UserTrackingMode.NONE) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (mUserTrackingState == UserTrackingState.POSSIBLE) {
|
|
296
|
-
updateUserLocationSignificantly(isAnimated);
|
|
297
|
-
} else if (mUserTrackingState == UserTrackingState.CHANGED) {
|
|
298
|
-
updateUserLocationIncrementally(isAnimated);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
private CameraOptions getUserLocationUpdateCameraOptions(double zoomLevel) {
|
|
303
|
-
LatLng center = mUserLocation.getCoordinate();
|
|
304
|
-
|
|
305
|
-
ScreenCoordinate anchor = CameraAnimationsUtils.getCamera(mMapView).getAnchor();
|
|
306
|
-
CameraState actState = mMapView.getMapboxMap().getCameraState();
|
|
307
|
-
if (mUserLocationVerticalAlignment != UserLocationVerticalAlignment.CENTER) {
|
|
308
|
-
CameraOptions options = ExtensionUtils.toCameraOptions(actState, anchor);
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
CoordinateBounds bounds = mMapView.getMapboxMap().coordinateBoundsForCamera(options);
|
|
312
|
-
|
|
313
|
-
//VisibleRegion region = mMapView.getVisibleRegion(center, zoomLevel);
|
|
314
|
-
|
|
315
|
-
switch (mUserLocationVerticalAlignment) {
|
|
316
|
-
case UserLocationVerticalAlignment.TOP:
|
|
317
|
-
center = new LatLng(bounds.getNortheast().latitude(), center.getLongitude());
|
|
318
|
-
break;
|
|
319
|
-
case UserLocationVerticalAlignment.BOTTOM:
|
|
320
|
-
center = new LatLng(bounds.getSouthwest().latitude(), center.getLongitude());
|
|
321
|
-
break;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return new CameraOptions.Builder()
|
|
326
|
-
.center(center.getPoint())
|
|
327
|
-
.bearing(getDirectionForUserLocationUpdate())
|
|
328
|
-
.pitch(mPitch)
|
|
329
|
-
.anchor(anchor)
|
|
330
|
-
.padding(actState.getPadding())
|
|
331
|
-
.zoom(zoomLevel)
|
|
332
|
-
.build();
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
private double getDirectionForUserLocationUpdate() {
|
|
336
|
-
// NOTE: The direction of this is used for map rotation only, not location layer rotation
|
|
337
|
-
|
|
338
|
-
CameraState currentCamera = mMapView.getMapboxMap().getCameraState();
|
|
339
|
-
double direction = currentCamera.getBearing();
|
|
340
|
-
|
|
341
|
-
int userTrackingMode = mUserLocation.getTrackingMode();
|
|
342
|
-
if (userTrackingMode == UserTrackingMode.FollowWithHeading || userTrackingMode == UserTrackingMode.FollowWithCourse) {
|
|
343
|
-
direction = mUserLocation.getBearing();
|
|
344
|
-
} else if (mHeading != 0.0) {
|
|
345
|
-
direction = mHeading;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
return direction;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
private void sendUserLocationUpdateEvent(Point point) {
|
|
353
|
-
if (point == null) {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
IEvent event = new MapChangeEvent(this, EventTypes.USER_LOCATION_UPDATED, makeLocationChangePayload(GeoJSONUtils.toLocation(point)));
|
|
357
|
-
mManager.handleEvent(event);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
private boolean hasSetCenterCoordinate() {
|
|
361
|
-
CameraState state = getMapboxMap().getCameraState();
|
|
362
|
-
Point center = state.getCenter();
|
|
363
|
-
return center.latitude() != 0.0 && center.longitude() != 0.0;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
static final double minimumZoomLevelForUserTracking = 10.5;
|
|
367
|
-
static final double defaultZoomLevelForUserTracking = 14.0;
|
|
368
|
-
|
|
369
|
-
private void updateUserLocationSignificantly(boolean isAnimated) {
|
|
370
|
-
mUserTrackingState = UserTrackingState.BEGAN;
|
|
371
|
-
|
|
372
|
-
double zoom = mZoomLevel;
|
|
373
|
-
if (zoom < 0) {
|
|
374
|
-
double camerZoom = mMapView.getMapboxMap().getCameraState().getZoom();
|
|
375
|
-
if (camerZoom < minimumZoomLevelForUserTracking) {
|
|
376
|
-
zoom = defaultZoomLevelForUserTracking;
|
|
377
|
-
} else {
|
|
378
|
-
zoom = camerZoom;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
CameraOptions.Builder builder = new CameraOptions.Builder();
|
|
383
|
-
CameraState currentCamera = mMapView.getMapboxMap().getCameraState();
|
|
384
|
-
|
|
385
|
-
CameraOptions cameraOptions = getUserLocationUpdateCameraOptions(zoom);
|
|
386
|
-
|
|
387
|
-
MapAnimationOptions.Builder animationOptions = new MapAnimationOptions.Builder().animatorListener(new Animator.AnimatorListener() {
|
|
388
|
-
@Override
|
|
389
|
-
public void onAnimationStart(Animator animation) {
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
@Override
|
|
394
|
-
public void onAnimationEnd(Animator animation) {
|
|
395
|
-
mUserTrackingState = UserTrackingState.CHANGED;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
@Override
|
|
399
|
-
public void onAnimationCancel(Animator animation) {
|
|
400
|
-
mUserTrackingState = UserTrackingState.CHANGED;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
@Override
|
|
404
|
-
public void onAnimationRepeat(Animator animation) {
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
if (isAnimated && hasSetCenterCoordinate()) {
|
|
409
|
-
CameraAnimationsUtils.flyTo(getMapboxMap(), cameraOptions, animationOptions.build());
|
|
410
|
-
} else {
|
|
411
|
-
CameraAnimationsUtils.flyTo(getMapboxMap(), cameraOptions, animationOptions.duration(0).build());
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
private void updateUserLocationIncrementally(boolean isAnimated) {
|
|
417
|
-
mUserTrackingState = UserTrackingState.BEGAN;
|
|
418
|
-
|
|
419
|
-
CameraState cameraState = getMapboxMap().getCameraState();
|
|
420
|
-
|
|
421
|
-
CameraOptions cameraOptions = getUserLocationUpdateCameraOptions(cameraState.getZoom());
|
|
422
|
-
|
|
423
|
-
MapAnimationOptions.Builder animationOptions = new MapAnimationOptions.Builder().animatorListener(new Animator.AnimatorListener() {
|
|
424
|
-
@Override
|
|
425
|
-
public void onAnimationStart(Animator animation) {
|
|
426
|
-
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
@Override
|
|
430
|
-
public void onAnimationEnd(Animator animation) {
|
|
431
|
-
mUserTrackingState = UserTrackingState.CHANGED;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
@Override
|
|
435
|
-
public void onAnimationCancel(Animator animation) {
|
|
436
|
-
mUserTrackingState = UserTrackingState.CHANGED;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
@Override
|
|
440
|
-
public void onAnimationRepeat(Animator animation) {
|
|
441
|
-
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
if (isAnimated) {
|
|
445
|
-
animationOptions.duration(USER_LOCATION_CAMERA_MOVE_DURATION);
|
|
446
|
-
} else {
|
|
447
|
-
animationOptions.duration(0);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
CameraAnimationsUtils.flyTo(getMapboxMap(), cameraOptions, animationOptions.build());
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
private void enableLocation() {
|
|
454
|
-
if (!PermissionsManager.areLocationPermissionsGranted(mContext)) {
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
if (!mLocationManager.isActive()) {
|
|
459
|
-
mLocationManager.enable();
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
mMapView.getMapboxMap().getStyle(new Style.OnStyleLoaded() {
|
|
463
|
-
@Override
|
|
464
|
-
public void onStyleLoaded(@NonNull Style style) {
|
|
465
|
-
enableLocationComponent(style);
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
/*
|
|
470
|
-
void updateFollowLocation(boolean follow) {
|
|
471
|
-
LocationComponentPlugin locationComponent = LocationComponentUtils.getLocationComponent(mMapView);
|
|
472
|
-
if (follow) {
|
|
473
|
-
locationComponent.setEnabled(true);
|
|
474
|
-
locationComponent.addOnIndicatorBearingChangedListener(mLocationBearingChangedListener);
|
|
475
|
-
locationComponent.addOnIndicatorPositionChangedListener(mLocationPositionChangeListener);
|
|
476
|
-
} else {
|
|
477
|
-
locationComponent.removeOnIndicatorBearingChangedListener(mLocationBearingChangedListener);
|
|
478
|
-
locationComponent.removeOnIndicatorPositionChangedListener(mLocationPositionChangeListener);
|
|
479
|
-
}
|
|
480
|
-
} */
|
|
481
|
-
|
|
482
|
-
private void enableLocationComponent(@NonNull Style style) {
|
|
483
|
-
updateUserLocation(false);
|
|
484
|
-
updateLocationLayer(style);
|
|
485
|
-
|
|
486
|
-
Location lastKnownLocation = mLocationManager.getLastKnownLocation();
|
|
487
|
-
mLocationManager.addLocationListener(mLocationChangeListener);
|
|
488
|
-
|
|
489
|
-
if (lastKnownLocation != null) {
|
|
490
|
-
mLocationChangeListener.onLocationChange(lastKnownLocation);
|
|
491
|
-
|
|
492
|
-
postDelayed(new Runnable() {
|
|
493
|
-
@Override
|
|
494
|
-
public void run() {
|
|
495
|
-
mMapView.sendRegionDidChangeEvent();
|
|
496
|
-
}
|
|
497
|
-
}, 200);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
private void updateLocationLayer(@NonNull Style style) {
|
|
502
|
-
if (mLocationComponentManager == null) {
|
|
503
|
-
mLocationComponentManager = mMapView.getLocationComponentManager();
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
mLocationComponentManager.update(style);
|
|
507
|
-
|
|
508
|
-
if (mFollowUserLocation) {
|
|
509
|
-
mLocationComponentManager.setCameraMode(UserTrackingMode.getCameraMode(mUserTrackingMode));
|
|
510
|
-
}
|
|
511
|
-
mLocationComponentManager.setFollowUserLocation(mFollowUserLocation);
|
|
512
|
-
|
|
513
|
-
if (mFollowUserLocation) {
|
|
514
|
-
mLocationComponentManager.setCameraMode(UserTrackingMode.getCameraMode(mUserTrackingMode));
|
|
515
|
-
|
|
516
|
-
/*
|
|
517
|
-
mLocationComponentManager.addOnCameraTrackingChangedListener(new OnCameraTrackingChangedListener() {
|
|
518
|
-
@Override public void onCameraTrackingChanged(int currentMode) {
|
|
519
|
-
int userTrackingMode = UserTrackingMode.NONE;
|
|
520
|
-
switch (currentMode) {
|
|
521
|
-
case CameraMode.NONE:
|
|
522
|
-
userTrackingMode = UserTrackingMode.NONE;
|
|
523
|
-
break;
|
|
524
|
-
case CameraMode.TRACKING:
|
|
525
|
-
userTrackingMode = UserTrackingMode.FOLLOW;
|
|
526
|
-
break;
|
|
527
|
-
case CameraMode.TRACKING_COMPASS:
|
|
528
|
-
userTrackingMode = UserTrackingMode.FollowWithHeading;
|
|
529
|
-
break;
|
|
530
|
-
case CameraMode.TRACKING_GPS:
|
|
531
|
-
userTrackingMode = UserTrackingMode.FollowWithCourse;
|
|
532
|
-
break;
|
|
533
|
-
default:
|
|
534
|
-
userTrackingMode = UserTrackingMode.NONE;
|
|
535
|
-
}
|
|
536
|
-
updateUserTrackingMode(userTrackingMode);
|
|
537
|
-
}
|
|
538
|
-
@Override public void onCameraTrackingDismissed() {
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
*/
|
|
542
|
-
} else {
|
|
543
|
-
mLocationComponentManager.setCameraMode(CameraMode.NONE);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
public void setMinZoomLevel(double zoomLevel) {
|
|
548
|
-
mMinZoomLevel = zoomLevel;
|
|
549
|
-
updateMaxMinZoomLevel();
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
public void setMaxZoomLevel(double zoomLevel) {
|
|
553
|
-
mMaxZoomLevel = zoomLevel;
|
|
554
|
-
updateMaxMinZoomLevel();
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
public void setZoomLevel(double zoomLevel) {
|
|
558
|
-
mZoomLevel = zoomLevel;
|
|
559
|
-
updateCameraPositionIfNeeded(false);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
private CameraOptions buildCamera(CameraState previousPosition, boolean shouldUpdateTarget) {
|
|
563
|
-
if (shouldUpdateTarget) {
|
|
564
|
-
return ExtensionUtils.toCameraOptions(previousPosition, mCenterCoordinate);
|
|
565
|
-
} else {
|
|
566
|
-
return ExtensionUtils.toCameraOptions(previousPosition, null);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
private void updateCameraPositionIfNeeded(boolean shouldUpdateTarget) {
|
|
571
|
-
if (mMapView != null) {
|
|
572
|
-
CameraState prevPosition = getMapboxMap().getCameraState();
|
|
573
|
-
CameraOptions cameraUpdate = /*CameraUpdateFactory.newCameraPosition(*/buildCamera(prevPosition, shouldUpdateTarget);
|
|
574
|
-
|
|
575
|
-
if (mAnimated) {
|
|
576
|
-
getMapboxMap().cameraAnimationsPlugin(new Function1<CameraAnimationsPlugin, Object>() {
|
|
577
|
-
public Object invoke(CameraAnimationsPlugin plugin) {
|
|
578
|
-
plugin.flyTo(cameraUpdate, null);
|
|
579
|
-
return null;
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
} else {
|
|
583
|
-
getMapboxMap().setCamera(cameraUpdate);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
public void setUserTrackingMode(int userTrackingMode) {
|
|
589
|
-
int oldTrackingMode = mUserTrackingMode;
|
|
590
|
-
mUserTrackingMode = userTrackingMode;
|
|
591
|
-
updateUserTrackingMode(userTrackingMode);
|
|
592
|
-
|
|
593
|
-
switch (mUserTrackingMode) {
|
|
594
|
-
case UserTrackingMode.NONE:
|
|
595
|
-
mUserTrackingState = UserTrackingState.POSSIBLE;
|
|
596
|
-
break;
|
|
597
|
-
case UserTrackingMode.FOLLOW:
|
|
598
|
-
case UserTrackingMode.FollowWithCourse:
|
|
599
|
-
case UserTrackingMode.FollowWithHeading:
|
|
600
|
-
if (oldTrackingMode == UserTrackingMode.NONE) {
|
|
601
|
-
mUserTrackingState = UserTrackingState.POSSIBLE;
|
|
602
|
-
}
|
|
603
|
-
break;
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
if (getMapboxMap() != null) {
|
|
608
|
-
updateLocationLayer(getMapboxMap().getStyle());
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
public void setFollowUserLocation(boolean value) {
|
|
614
|
-
mFollowUserLocation = value;
|
|
615
|
-
updatedFollowUserMode();
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
public void setFollowUserMode(String mode) {
|
|
619
|
-
mFollowUserMode = mode;
|
|
620
|
-
updatedFollowUserMode();
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
private void updatedFollowUserMode() {
|
|
624
|
-
if (mFollowUserLocation) {
|
|
625
|
-
setUserTrackingMode(UserTrackingMode.fromString(mFollowUserMode));
|
|
626
|
-
} else {
|
|
627
|
-
setUserTrackingMode(UserTrackingMode.NONE);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
MapboxMap getMapboxMap() {
|
|
632
|
-
if (mMapView == null) {
|
|
633
|
-
return null;
|
|
634
|
-
}
|
|
635
|
-
return mMapView.getMapboxMap();
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
/**
|
|
639
|
-
* Create a payload of the location data per the web api geolocation spec
|
|
640
|
-
* https://dev.w3.org/geo/api/spec-source.html#position
|
|
641
|
-
*
|
|
642
|
-
* @return
|
|
643
|
-
*/
|
|
644
|
-
private WritableMap makeLocationChangePayload(Location location) {
|
|
645
|
-
WritableMap positionProperties = new WritableNativeMap();
|
|
646
|
-
WritableMap coords = new WritableNativeMap();
|
|
647
|
-
|
|
648
|
-
coords.putDouble("longitude", location.getLongitude());
|
|
649
|
-
coords.putDouble("latitude", location.getLatitude());
|
|
650
|
-
coords.putDouble("altitude", location.getAltitude());
|
|
651
|
-
coords.putDouble("accuracy", location.getAccuracy());
|
|
652
|
-
// A better solution will be to pull the heading from the compass engine,
|
|
653
|
-
// unfortunately the api is not publicly available in the mapbox sdk
|
|
654
|
-
coords.putDouble("heading", location.getBearing());
|
|
655
|
-
coords.putDouble("course", location.getBearing());
|
|
656
|
-
coords.putDouble("speed", location.getSpeed());
|
|
657
|
-
|
|
658
|
-
positionProperties.putMap("coords", coords);
|
|
659
|
-
positionProperties.putDouble("timestamp", location.getTime());
|
|
660
|
-
return positionProperties;
|
|
661
|
-
}
|
|
662
|
-
}
|