Make current location marker follow

This commit is contained in:
neslihanturan 2019-10-02 15:14:13 +03:00
parent 25a88f32f9
commit 1a816fdecd
4 changed files with 15 additions and 5 deletions

View file

@ -33,5 +33,6 @@ public interface NearbyMapContract {
void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback); void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener); void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener);
void centerMapToPlace(Place place, boolean isPortraitMode); void centerMapToPlace(Place place, boolean isPortraitMode);
void removeCurrentLocationMarker();
} }
} }

View file

@ -2,10 +2,8 @@ package fr.free.nrw.commons.nearby.mvp.fragments;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
@ -74,6 +73,8 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
private MapFragment.OnMapViewReadyCallback mapViewReadyCallback; private MapFragment.OnMapViewReadyCallback mapViewReadyCallback;
private MapboxMap mapboxMap; private MapboxMap mapboxMap;
private MapView map; 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_PORTRAIT = 0.005;
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.004; private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.004;
@ -317,7 +318,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
MarkerOptions currentLocationMarkerOptions = new MarkerOptions() MarkerOptions currentLocationMarkerOptions = new MarkerOptions()
.position(new com.mapbox.mapboxsdk.geometry.LatLng(curLatLng.getLatitude(), curLatLng.getLongitude())); .position(new com.mapbox.mapboxsdk.geometry.LatLng(curLatLng.getLatitude(), curLatLng.getLongitude()));
currentLocationMarkerOptions.setIcon(icon); // Set custom icon 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(), List<com.mapbox.mapboxsdk.geometry.LatLng> circle = UiUtils.createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(),
curLatLng.getAccuracy() * 2, 100); curLatLng.getAccuracy() * 2, 100);
@ -326,7 +327,13 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
.addAll(circle) .addAll(circle)
.strokeColor(getResources().getColor(R.color.current_marker_stroke)) .strokeColor(getResources().getColor(R.color.current_marker_stroke))
.fillColor(getResources().getColor(R.color.current_marker_fill)); .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);
} }
/** /**

View file

@ -686,6 +686,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@Override @Override
public void recenterMap(fr.free.nrw.commons.location.LatLng curLatLng) { public void recenterMap(fr.free.nrw.commons.location.LatLng curLatLng) {
nearbyMapFragment.removeCurrentLocationMarker();
nearbyMapFragment.addCurrentLocationMarker(curLatLng);
CameraPosition position; CameraPosition position;
if (ViewUtil.isPortrait(getActivity())){ if (ViewUtil.isPortrait(getActivity())){

View file

@ -258,7 +258,7 @@ public class NearbyParentFragmentPresenter
} else { // Means location changed slightly, ie user is walking or driving. } else { // Means location changed slightly, ie user is walking or driving.
Timber.d("Means location changed slightly"); Timber.d("Means location changed slightly");
nearbyMapFragmentView.updateMapToTrackPosition(curLatLng); nearbyParentFragmentView.recenterMap(curLatLng);
} }
} }