Skip to content

Commit

Permalink
migrate android sdk to vietmap sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhdang198 committed Jan 30, 2024
1 parent 3134696 commit 7544597
Show file tree
Hide file tree
Showing 62 changed files with 342 additions and 319 deletions.
26 changes: 18 additions & 8 deletions android/rctmgl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,37 @@ dependencies {
implementation("com.facebook.react:react-android")

// MapLibre SDK
implementation "org.maplibre.gl:android-sdk:9.6.0"
implementation "org.maplibre.gl:android-sdk-turf:5.9.0"
// implementation "org.maplibre.gl:android-sdk:9.6.0"
// implementation "org.maplibre.gl:android-sdk-turf:5.9.0"

implementation 'com.github.vietmap-company:maps-sdk-android:2.2.2'

implementation 'com.github.vietmap-company:vietmap-services-turf-android:1.0.2'
// Dependencies
implementation "com.android.support:support-vector-drawable:${safeExtGet('supportLibVersion', '28.0.0')}"
implementation "com.android.support:support-annotations:${safeExtGet('supportLibVersion', '28.0.0')}"
implementation "com.android.support:appcompat-v7:${safeExtGet('supportLibVersion', '28.0.0')}"
implementation "com.squareup.okhttp3:okhttp:${safeExtGet('okhttpVersion', '4.9.0')}"
implementation "com.squareup.okhttp3:okhttp-urlconnection:${safeExtGet('okhttpVersion', '4.9.0')}"


implementation("com.github.vietmap-company:maps-sdk-plugin-annotation-android:1.0.0")
implementation('com.github.vietmap-company:vietmap-services-plugin-markerview:1.0.3')
implementation('com.github.vietmap-company:maps-sdk-plugin-localization-android:1.0.0')
implementation('com.github.vietmap-company:maps-sdk-plugin-localization-android:2.0.0')
implementation 'com.github.vietmap-company:vietmap-services-geojson-android:1.0.0'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
// MapLibre plugins
implementation ("org.maplibre.gl:android-plugin-localization-v9:1.0.0")
implementation ("org.maplibre.gl:android-plugin-annotation-v9:1.0.0")
implementation ("org.maplibre.gl:android-plugin-markerview-v9:1.0.0")
// implementation ("org.maplibre.gl:android-plugin-localization-v9:1.0.0")
// implementation ("org.maplibre.gl:android-plugin-annotation-v9:1.0.0")
// implementation ("org.maplibre.gl:android-plugin-markerview-v9:1.0.0")
}

allprojects {
repositories {
maven {
url = "https://dl.bintray.com/maplibre/maplibre-gl-native"
// url = "https://dl.bintray.com/maplibre/maplibre-gl-native"

url = "https://jitpack.io"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import androidx.annotation.NonNull;

import com.mapbox.mapboxsdk.geometry.LatLng;
import vn.vietmap.vietmapsdk.geometry.LatLng;

/**
* Subclass of MarkerView so we MarkerViewManager can implement remove/restoreViews
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import androidx.annotation.NonNull;

import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import vn.vietmap.vietmapsdk.maps.MapView;
import vn.vietmap.vietmapsdk.maps.VietMapGL;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -18,7 +18,7 @@ public class MarkerViewManager extends com.mapbox.mapboxsdk.plugins.markerview.M
private MapView mapView;
private java.lang.reflect.Method markerUpdate;

public MarkerViewManager(MapView mapView, MapboxMap mapboxMap) {
public MarkerViewManager(MapView mapView, VietMapGL mapboxMap) {
super(mapView, mapboxMap);
this.mapView = mapView;
// this.mapboxMap = mapboxMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import androidx.annotation.NonNull;

import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import vn.vietmap.vietmapsdk.maps.VietMapGL;
import vn.vietmap.vietmapsdk.maps.OnMapReadyCallback;
import com.mapbox.rctmgl.components.AbstractMapFeature;
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView;
import com.mapbox.rctmgl.utils.GeoJSONUtils;
Expand Down Expand Up @@ -65,7 +65,7 @@ public void addToMap(RCTMGLMapView mapView) {
mMapView.getMapAsync(
new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
public void onMapReady(@NonNull VietMapGL mapboxMap) {
mMarkerViewManager = mMapView.getMarkerViewManager(mapboxMap);

if (mChildView != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import androidx.annotation.NonNull;

import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.plugins.annotation.Symbol;
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager;
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import vn.vietmap.vietmapsdk.geometry.LatLng;
import vn.vietmap.vietmapsdk.maps.Style;
import vn.vietmap.vietmapsdk.plugins.annotation.Symbol;
import vn.vietmap.vietmapsdk.plugins.annotation.SymbolManager;
import vn.vietmap.vietmapsdk.plugins.annotation.SymbolOptions;
import vn.vietmap.vietmapsdk.maps.VietMapGL;
import com.mapbox.rctmgl.components.AbstractMapFeature;
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView;
import com.mapbox.rctmgl.events.PointAnnotationClickEvent;
Expand All @@ -25,7 +25,7 @@ public class RCTMGLPointAnnotation extends AbstractMapFeature implements View.On
private Context mContext;
private RCTMGLPointAnnotationManager mManager;
private Symbol mAnnotation;
private MapboxMap mMap;
private VietMapGL mMap;
private RCTMGLMapView mMapView;

private boolean mHasChildren;
Expand Down Expand Up @@ -93,7 +93,7 @@ public void onStyleLoaded(@NonNull Style style) {
@Override
public void addToMap(RCTMGLMapView mapView) {
mMapView = mapView;
mMap = mapView.getMapboxMap();
mMap = mapView.getVietMapGL();
makeMarker();

if (mChildView != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import com.facebook.react.bridge.ReadableMap;
import com.mapbox.geojson.FeatureCollection;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import vn.vietmap.vietmapsdk.camera.CameraPosition;
import vn.vietmap.vietmapsdk.camera.CameraUpdate;
import vn.vietmap.vietmapsdk.camera.CameraUpdateFactory;
import vn.vietmap.vietmapsdk.geometry.LatLng;
import vn.vietmap.vietmapsdk.geometry.LatLngBounds;
import vn.vietmap.vietmapsdk.maps.VietMapGL;
import com.mapbox.rctmgl.components.camera.constants.CameraMode;
import com.mapbox.rctmgl.utils.GeoJSONUtils;

Expand All @@ -36,7 +36,7 @@ public class CameraStop {

private int mMode = CameraMode.EASE;
private int mDuration = 2000;
private MapboxMap.CancelableCallback mCallback;
private VietMapGL.CancelableCallback mCallback;

public CameraStop() {
}
Expand All @@ -61,7 +61,7 @@ public void setDuration(int duration) {
mDuration = duration;
}

public void setCallback(MapboxMap.CancelableCallback callback) {
public void setCallback(VietMapGL.CancelableCallback callback) {
mCallback = callback;
}

Expand All @@ -81,7 +81,7 @@ public void setMode(@CameraMode.Mode int mode) {
}

public CameraUpdateItem toCameraUpdate(RCTMGLMapView mapView) {
MapboxMap map = mapView.getMapboxMap();
VietMapGL map = mapView.getVietMapGL();
CameraPosition currentCamera = map.getCameraPosition();
CameraPosition.Builder builder = new CameraPosition.Builder(currentCamera);

Expand Down Expand Up @@ -144,7 +144,7 @@ public CameraUpdateItem toCameraUpdate(RCTMGLMapView mapView) {
return new CameraUpdateItem(map, CameraUpdateFactory.newCameraPosition(builder.build()), mDuration, mCallback, mMode);
}

public static CameraStop fromReadableMap(Context context, @NonNull ReadableMap readableMap, MapboxMap.CancelableCallback callback) {
public static CameraStop fromReadableMap(Context context, @NonNull ReadableMap readableMap, VietMapGL.CancelableCallback callback) {
CameraStop stop = new CameraStop();

if (readableMap.hasKey("pitch")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import androidx.annotation.NonNull;

import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import vn.vietmap.vietmapsdk.camera.CameraUpdate;
import vn.vietmap.vietmapsdk.constants.VietMapConstants;
import vn.vietmap.vietmapsdk.maps.VietMapGL;
import com.mapbox.rctmgl.components.camera.constants.CameraMode;

import java.lang.ref.WeakReference;
Expand All @@ -23,16 +23,16 @@

public class CameraUpdateItem implements RunnableFuture<Void> {
private int mDuration;
private MapboxMap.CancelableCallback mCallback;
private VietMapGL.CancelableCallback mCallback;
private CameraUpdate mCameraUpdate;
private int mCameraMode;

private boolean isCameraActionFinished;
private boolean isCameraActionCancelled;

private WeakReference<MapboxMap> mMap;
private WeakReference<VietMapGL> mMap;

public CameraUpdateItem(MapboxMap map, CameraUpdate update, int duration, MapboxMap.CancelableCallback callback, @CameraMode.Mode int cameraMode) {
public CameraUpdateItem(VietMapGL map, CameraUpdate update, int duration, VietMapGL.CancelableCallback callback, @CameraMode.Mode int cameraMode) {
mCameraUpdate = update;
mDuration = duration;
mCallback = callback;
Expand All @@ -46,7 +46,7 @@ public int getDuration() {

@Override
public void run() {
final MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() {
final VietMapGL.CancelableCallback callback = new VietMapGL.CancelableCallback() {
@Override
public void onCancel() {
handleCallbackResponse(true);
Expand All @@ -58,7 +58,7 @@ public void onFinish() {
}
};

MapboxMap map = mMap.get();
VietMapGL map = mMap.get();
if (map == null) {
isCameraActionCancelled = true;
return;
Expand All @@ -72,7 +72,7 @@ public void onFinish() {

// On iOS a duration of -1 means default or dynamic duration (based on flight-path length)
// On Android we can fallback to Mapbox's default duration as there is no such API
int duration = mDuration < 0 ? MapboxConstants.ANIMATION_DURATION : mDuration;
int duration = mDuration < 0 ? VietMapConstants.ANIMATION_DURATION : mDuration;

if (mCameraMode == CameraMode.FLIGHT) {
map.animateCamera(mCameraUpdate, duration, callback);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mapbox.rctmgl.components.camera;

import com.mapbox.mapboxsdk.maps.MapboxMap;
import vn.vietmap.vietmapsdk.maps.VietMapGL;
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
import android.content.Context;
import android.location.Location;

import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.VisibleRegion;
import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
// import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
import vn.vietmap.vietmapsdk.camera.CameraPosition;
import vn.vietmap.vietmapsdk.camera.CameraUpdate;
import vn.vietmap.vietmapsdk.camera.CameraUpdateFactory;
import vn.vietmap.vietmapsdk.geometry.LatLng;
import vn.vietmap.vietmapsdk.geometry.LatLngBounds;
import vn.vietmap.vietmapsdk.geometry.VisibleRegion;
import vn.vietmap.vietmapsdk.location.OnCameraTrackingChangedListener;
import vn.vietmap.vietmapsdk.location.modes.CameraMode;
import vn.vietmap.vietmapsdk.location.modes.RenderMode;
import vn.vietmap.vietmapsdk.maps.VietMapGL;
import vn.vietmap.vietmapsdk.maps.Style;
import vn.vietmap.vietmapsdk.location.LocationComponent;
import vn.vietmap.vietmapsdk.location.LocationComponentOptions;
import vn.vietmap.vietmapsdk.location.LocationComponentActivationOptions;
// import vn.vietmap.vietmapsdk.plugins.locationlayer.LocationLayerPlugin;
import com.mapbox.rctmgl.components.AbstractMapFeature;
import com.mapbox.rctmgl.components.location.LocationComponentManager;
import com.mapbox.rctmgl.components.mapview.RCTMGLMapView;
Expand All @@ -40,7 +40,7 @@

import com.mapbox.geojson.Point;

import com.mapbox.mapboxsdk.location.permissions.PermissionsManager;
import vn.vietmap.vietmapsdk.location.permissions.PermissionsManager;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -87,7 +87,7 @@ public class RCTMGLCamera extends AbstractMapFeature {
private LocationManager.OnUserLocationChange mLocationChangeListener = new LocationManager.OnUserLocationChange() {
@Override
public void onLocationChange(Location nextLocation) {
if (getMapboxMap() == null || mLocationComponentManager == null || !mLocationComponentManager.hasLocationComponent() || (!mFollowUserLocation)) {
if (getVietMapGL() == null || mLocationComponentManager == null || !mLocationComponentManager.hasLocationComponent() || (!mFollowUserLocation)) {
return;
}

Expand All @@ -96,7 +96,7 @@ public void onLocationChange(Location nextLocation) {
}
};

private MapboxMap.CancelableCallback mCameraCallback = new MapboxMap.CancelableCallback() {
private VietMapGL.CancelableCallback mCameraCallback = new VietMapGL.CancelableCallback() {
@Override
public void onCancel() {
if (!hasSentFirstRegion) {
Expand Down Expand Up @@ -170,14 +170,14 @@ public void setMaxBounds(LatLngBounds bounds) {
}

private void updateMaxBounds() {
MapboxMap map = getMapboxMap();
VietMapGL map = getVietMapGL();
if (map != null && mMaxBounds != null) {
map.setLatLngBoundsForCameraTarget(mMaxBounds);
}
}

private void updateMaxMinZoomLevel() {
MapboxMap map = getMapboxMap();
VietMapGL map = getVietMapGL();
if (map != null) {
if (mMinZoomLevel >= 0.0) {
map.setMinZoomPreference(mMinZoomLevel);
Expand Down Expand Up @@ -281,15 +281,15 @@ private void updateUserLocationSignificantly(boolean isAnimated) {

double zoom = mZoomLevel;
if (zoom < 0) {
double camerZoom = mMapView.getMapboxMap().getCameraPosition().zoom;
double camerZoom = mMapView.getVietMapGL().getCameraPosition().zoom;
if (camerZoom < minimumZoomLevelForUserTracking) {
zoom = defaultZoomLevelForUserTracking;
} else {
zoom = camerZoom;
}
}
CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(getUserLocationUpdateCameraPosition(zoom));
MapboxMap.CancelableCallback cameraCallback = new MapboxMap.CancelableCallback() {
VietMapGL.CancelableCallback cameraCallback = new VietMapGL.CancelableCallback() {
@Override
public void onCancel() {
mUserTrackingState = UserTrackingState.CHANGED;
Expand All @@ -314,7 +314,7 @@ private void updateUserLocationIncrementally(boolean isAnimated) {
CameraPosition cameraPosition = mMapView.getCameraPosition();
CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(getUserLocationUpdateCameraPosition(cameraPosition.zoom));

MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() {
VietMapGL.CancelableCallback callback = new VietMapGL.CancelableCallback() {
@Override
public void onCancel() {
mUserTrackingState = UserTrackingState.CHANGED;
Expand Down Expand Up @@ -342,7 +342,7 @@ private void enableLocation() {
mLocationManager.enable();
}

mMapView.getMapboxMap().getStyle(new Style.OnStyleLoaded() {
mMapView.getVietMapGL().getStyle(new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
enableLocationComponent(style);
Expand Down Expand Up @@ -473,8 +473,8 @@ public void setUserTrackingMode(int userTrackingMode) {

}

if (getMapboxMap() != null) {
updateLocationLayer(getMapboxMap().getStyle());
if (getVietMapGL() != null) {
updateLocationLayer(getVietMapGL().getStyle());
}
}

Expand All @@ -497,11 +497,11 @@ private void updatedFollowUserMode() {
}
}

MapboxMap getMapboxMap() {
VietMapGL getVietMapGL() {
if (mMapView == null) {
return null;
}
return mMapView.getMapboxMap();
return mMapView.getVietMapGL();
}

/**
Expand Down
Loading

0 comments on commit 7544597

Please sign in to comment.