2015-12-12 12:41:50 -08:00
|
|
|
|
|
|
|
|
package com.mapbox.reactnativemapboxgl;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.util.Log;
|
2015-12-17 11:47:22 -08:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
2015-12-12 12:41:50 -08:00
|
|
|
|
|
|
|
|
import com.facebook.react.bridge.Arguments;
|
|
|
|
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
|
|
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
|
|
|
import com.facebook.react.bridge.ReactMethod;
|
|
|
|
|
import com.facebook.react.bridge.ReadableArray;
|
|
|
|
|
import com.facebook.react.bridge.ReadableMap;
|
2016-06-30 16:59:10 +03:00
|
|
|
import com.facebook.react.bridge.WritableArray;
|
|
|
|
|
import com.facebook.react.bridge.WritableNativeArray;
|
|
|
|
|
import com.mapbox.mapboxsdk.MapboxAccountManager;
|
2015-12-17 11:47:22 -08:00
|
|
|
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
2016-06-30 16:59:10 +03:00
|
|
|
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
|
|
|
|
|
import com.mapbox.mapboxsdk.constants.Style;
|
2015-12-12 12:41:50 -08:00
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
|
|
|
|
public class ReactNativeMapboxGLModule extends ReactContextBaseJavaModule {
|
|
|
|
|
|
|
|
|
|
private static final String TAG = ReactNativeMapboxGLModule.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
private Context context;
|
|
|
|
|
private ReactNativeMapboxGLPackage aPackage;
|
2016-06-30 16:59:10 +03:00
|
|
|
private static boolean initialized = false;
|
2015-12-12 12:41:50 -08:00
|
|
|
|
2016-06-30 16:59:10 +03:00
|
|
|
public ReactNativeMapboxGLModule(ReactApplicationContext reactContext, ReactNativeMapboxGLPackage thePackage) {
|
2015-12-12 12:41:50 -08:00
|
|
|
super(reactContext);
|
|
|
|
|
this.context = reactContext;
|
2016-06-30 16:59:10 +03:00
|
|
|
this.aPackage = thePackage;
|
2015-12-12 12:41:50 -08:00
|
|
|
Log.d(TAG, "Context " + context);
|
|
|
|
|
Log.d(TAG, "reactContext " + reactContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
2015-12-14 09:30:47 -08:00
|
|
|
return "MapboxGLManager";
|
2015-12-12 12:41:50 -08:00
|
|
|
}
|
|
|
|
|
|
2016-06-30 16:59:10 +03:00
|
|
|
static private WritableArray serializeTracking(int locationTracking, int bearingTracking) {
|
|
|
|
|
WritableArray result = Arguments.createArray();
|
|
|
|
|
result.pushInt(locationTracking);
|
|
|
|
|
result.pushInt(bearingTracking);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-17 11:47:22 -08:00
|
|
|
@Override
|
|
|
|
|
public @Nullable Map<String, Object> getConstants() {
|
|
|
|
|
HashMap<String, Object> constants = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
|
|
HashMap<String, Object> userTrackingMode = new HashMap<String, Object>();
|
|
|
|
|
HashMap<String, Object> mapStyles = new HashMap<String, Object>();
|
|
|
|
|
|
2016-06-30 16:59:10 +03:00
|
|
|
// // User tracking constants
|
|
|
|
|
// userTrackingMode.put("none", serializeTracking(MyLocationTracking.TRACKING_NONE, MyBearingTracking.NONE));
|
|
|
|
|
// userTrackingMode.put("follow", serializeTracking(MyLocationTracking.TRACKING_FOLLOW, MyBearingTracking.NONE));
|
|
|
|
|
// userTrackingMode.put("followWithCourse", serializeTracking(MyLocationTracking.TRACKING_FOLLOW, MyBearingTracking.GPS));
|
|
|
|
|
// userTrackingMode.put("followWithHeading", serializeTracking(MyLocationTracking.TRACKING_FOLLOW, MyBearingTracking.COMPASS));
|
2015-12-17 11:47:22 -08:00
|
|
|
|
|
|
|
|
// Style constants
|
|
|
|
|
mapStyles.put("light", Style.LIGHT);
|
|
|
|
|
mapStyles.put("dark", Style.DARK);
|
|
|
|
|
mapStyles.put("streets", Style.MAPBOX_STREETS);
|
|
|
|
|
mapStyles.put("emerald", Style.EMERALD);
|
|
|
|
|
mapStyles.put("satellite", Style.SATELLITE);
|
|
|
|
|
mapStyles.put("hybrid", Style.SATELLITE_STREETS);
|
|
|
|
|
|
|
|
|
|
constants.put("userTrackingMode", userTrackingMode);
|
|
|
|
|
constants.put("mapStyles", mapStyles);
|
|
|
|
|
|
|
|
|
|
return constants;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 16:59:10 +03:00
|
|
|
@ReactMethod
|
|
|
|
|
public void setAccessToken(String accessToken) {
|
|
|
|
|
if (accessToken == null || accessToken.length() == 0 || accessToken == "your-mapbox.com-access-token") {
|
|
|
|
|
Log.e(TAG, "Invalid access token. Register to mapbox.com and request an access token, then pass it to setAccessToken()");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (initialized) {
|
|
|
|
|
if (MapboxAccountManager.getInstance().getAccessToken() != accessToken) {
|
|
|
|
|
Log.e(TAG, "Access token cannot be initialized twice with different values");
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
initialized = true;
|
|
|
|
|
MapboxAccountManager.start(context, accessToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ReactMethod
|
|
|
|
|
public void spliceAnnotations(int mapRef, boolean removeAll, ReadableArray itemsToRemove, ReadableArray itemsToAdd) {
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2015-12-12 12:41:50 -08:00
|
|
|
@ReactMethod
|
2015-12-24 12:21:24 -06:00
|
|
|
public void setDirectionAnimated(int mapRef, int direction) {
|
2015-12-12 12:41:50 -08:00
|
|
|
aPackage.getManager().setDirection(aPackage.getManager().getMapView(), direction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ReactMethod
|
2015-12-24 12:21:24 -06:00
|
|
|
public void setCenterCoordinateAnimated(int mapRef, double latitude, double longitude) {
|
2015-12-12 12:41:50 -08:00
|
|
|
WritableMap location = Arguments.createMap();
|
|
|
|
|
location.putDouble("latitude", latitude);
|
|
|
|
|
location.putDouble("longitude", longitude);
|
|
|
|
|
aPackage.getManager().setCenterCoordinate(aPackage.getManager().getMapView(), location);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ReactMethod
|
2015-12-24 12:21:24 -06:00
|
|
|
public void setCenterCoordinateZoomLevelAnimated(int mapRef, double latitude, double longitude, double zoom) {
|
2015-12-12 12:41:50 -08:00
|
|
|
WritableMap location = Arguments.createMap();
|
|
|
|
|
location.putDouble("latitude", latitude);
|
|
|
|
|
location.putDouble("longitude", longitude);
|
|
|
|
|
location.putDouble("zoom", zoom);
|
2016-01-15 22:13:09 +08:00
|
|
|
aPackage.getManager().setCenterCoordinateZoomLevel(aPackage.getManager().getMapView(), location);
|
2015-12-12 12:41:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ReactMethod
|
2015-12-24 12:21:24 -06:00
|
|
|
public void addAnnotations(int mapRef, ReadableArray value) {
|
2016-01-11 15:51:12 -08:00
|
|
|
aPackage.getManager().setAnnotations(aPackage.getManager().getMapView(), value, false);
|
2015-12-12 12:41:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ReactMethod
|
2015-12-24 12:21:24 -06:00
|
|
|
public void setUserTrackingMode(int mapRef, int mode) {
|
2015-12-12 12:41:50 -08:00
|
|
|
aPackage.getManager().setMyLocationTrackingMode(aPackage.getManager().getMapView(), mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ReactMethod
|
2015-12-24 12:22:48 -06:00
|
|
|
public void removeAllAnnotations(int mapRef) {
|
2015-12-12 12:41:50 -08:00
|
|
|
aPackage.getManager().removeAllAnnotations(aPackage.getManager().getMapView(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ReactMethod
|
2015-12-24 12:21:24 -06:00
|
|
|
public void setTilt(int mapRef, double pitch) {
|
2015-12-12 12:41:50 -08:00
|
|
|
aPackage.getManager().setTilt(aPackage.getManager().getMapView(), pitch);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-13 17:37:32 -08:00
|
|
|
@ReactMethod
|
2015-12-24 12:21:24 -06:00
|
|
|
public void setVisibleCoordinateBoundsAnimated(int mapRef, double latSW, double lngSW,double latNE, double lngNE, float paddingTop, float paddingRight, float paddingBottom, float paddingLeft) {
|
2015-12-13 17:37:32 -08:00
|
|
|
WritableMap info = Arguments.createMap();
|
|
|
|
|
info.putDouble("latSW", latSW);
|
|
|
|
|
info.putDouble("lngSW", lngSW);
|
|
|
|
|
info.putDouble("latNE", latNE);
|
|
|
|
|
info.putDouble("lngNE", lngNE);
|
|
|
|
|
info.putDouble("paddingTop", paddingTop);
|
|
|
|
|
info.putDouble("paddingRight", paddingRight);
|
|
|
|
|
info.putDouble("paddingBottom", paddingBottom);
|
|
|
|
|
info.putDouble("paddingLeft", paddingLeft);
|
|
|
|
|
aPackage.getManager().setVisibleCoordinateBounds(aPackage.getManager().getMapView(), info);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 17:15:11 -08:00
|
|
|
@ReactMethod
|
|
|
|
|
public void getDirection(int mapRef, Callback successCallback) {
|
|
|
|
|
WritableMap direction = aPackage.getManager().getDirection(aPackage.getManager().getMapView());
|
|
|
|
|
successCallback.invoke(direction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ReactMethod
|
|
|
|
|
public void getCenterCoordinateZoomLevel(int mapRef, Callback successCallback) {
|
2016-06-30 16:59:10 +03:00
|
|
|
WritableMap location =aPackage.getManager().getCenterCoordinateZoomLevel(aPackage.getManager().getMapView());
|
2016-01-11 17:15:11 -08:00
|
|
|
successCallback.invoke(location);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 12:14:16 +01:00
|
|
|
@ReactMethod
|
|
|
|
|
public void getBounds(int mapRef, Callback successCallback) {
|
|
|
|
|
WritableMap bounds = aPackage.getManager().getBounds(aPackage.getManager().getMapView());
|
|
|
|
|
successCallback.invoke(bounds);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 16:59:10 +03:00
|
|
|
*/
|
2015-12-12 12:41:50 -08:00
|
|
|
}
|