mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Make current location marker follow
This commit is contained in:
parent
25a88f32f9
commit
1a816fdecd
4 changed files with 15 additions and 5 deletions
|
|
@ -33,5 +33,6 @@ public interface NearbyMapContract {
|
|||
void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
|
||||
void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener);
|
||||
void centerMapToPlace(Place place, boolean isPortraitMode);
|
||||
void removeCurrentLocationMarker();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,8 @@ package fr.free.nrw.commons.nearby.mvp.fragments;
|
|||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -18,6 +16,7 @@ import com.mapbox.mapboxsdk.annotations.Icon;
|
|||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Polygon;
|
||||
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
|
|
@ -74,6 +73,8 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
|
|||
private MapFragment.OnMapViewReadyCallback mapViewReadyCallback;
|
||||
private MapboxMap mapboxMap;
|
||||
private MapView map;
|
||||
private Marker currentLocationMarker;
|
||||
private Polygon currentLocationPolygon;
|
||||
|
||||
private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.005;
|
||||
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.004;
|
||||
|
|
@ -317,7 +318,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
|
|||
MarkerOptions currentLocationMarkerOptions = new MarkerOptions()
|
||||
.position(new com.mapbox.mapboxsdk.geometry.LatLng(curLatLng.getLatitude(), curLatLng.getLongitude()));
|
||||
currentLocationMarkerOptions.setIcon(icon); // Set custom icon
|
||||
Marker currentLocationMarker = mapboxMap.addMarker(currentLocationMarkerOptions);
|
||||
currentLocationMarker = mapboxMap.addMarker(currentLocationMarkerOptions);
|
||||
|
||||
List<com.mapbox.mapboxsdk.geometry.LatLng> circle = UiUtils.createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(),
|
||||
curLatLng.getAccuracy() * 2, 100);
|
||||
|
|
@ -326,7 +327,13 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
|
|||
.addAll(circle)
|
||||
.strokeColor(getResources().getColor(R.color.current_marker_stroke))
|
||||
.fillColor(getResources().getColor(R.color.current_marker_fill));
|
||||
mapboxMap.addPolygon(currentLocationPolygonOptions);
|
||||
currentLocationPolygon = mapboxMap.addPolygon(currentLocationPolygonOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCurrentLocationMarker() {
|
||||
mapboxMap.removeMarker(currentLocationMarker);
|
||||
mapboxMap.removePolygon(currentLocationPolygon);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -686,6 +686,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
|
||||
@Override
|
||||
public void recenterMap(fr.free.nrw.commons.location.LatLng curLatLng) {
|
||||
nearbyMapFragment.removeCurrentLocationMarker();
|
||||
nearbyMapFragment.addCurrentLocationMarker(curLatLng);
|
||||
CameraPosition position;
|
||||
|
||||
if (ViewUtil.isPortrait(getActivity())){
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ public class NearbyParentFragmentPresenter
|
|||
|
||||
} else { // Means location changed slightly, ie user is walking or driving.
|
||||
Timber.d("Means location changed slightly");
|
||||
nearbyMapFragmentView.updateMapToTrackPosition(curLatLng);
|
||||
nearbyParentFragmentView.recenterMap(curLatLng);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue