mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Cleanup
This commit is contained in:
parent
cff4086bb3
commit
45d6f56630
3 changed files with 59 additions and 48 deletions
|
|
@ -19,9 +19,7 @@ import fr.free.nrw.commons.nearby.mvp.presenter.NearbyParentFragmentPresenter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface defines specific View and UserActions for map
|
* This interface defines specific View and UserActions for map
|
||||||
* part of the nearby. On the other hand both extends methods
|
* part of the nearby.
|
||||||
* from parent View and UserActions where general methods are
|
|
||||||
* defined (in Nearby Contract)
|
|
||||||
*/
|
*/
|
||||||
public interface NearbyMapContract {
|
public interface NearbyMapContract {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,7 @@ import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
|
||||||
* @see #getMapAsync(OnMapReadyCallback)
|
* @see #getMapAsync(OnMapReadyCallback)
|
||||||
*/
|
*/
|
||||||
public class NearbyMapFragment extends CommonsDaggerSupportFragment
|
public class NearbyMapFragment extends CommonsDaggerSupportFragment
|
||||||
implements OnMapReadyCallback,
|
implements OnMapReadyCallback, NearbyMapContract.View{
|
||||||
NearbyMapContract.View{
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BookmarkLocationsDao bookmarkLocationDao;
|
BookmarkLocationsDao bookmarkLocationDao;
|
||||||
|
|
@ -75,6 +74,7 @@ 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 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;
|
||||||
private static final double ZOOM_LEVEL = 14f;
|
private static final double ZOOM_LEVEL = 14f;
|
||||||
|
|
@ -260,30 +260,36 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears map, adds nearby markers to map
|
||||||
|
* @param latLng current location
|
||||||
|
* @param placeList all places will be displayed on the map
|
||||||
|
* @param selectedMarker clicked marker by user
|
||||||
|
* @param nearbyParentFragmentPresenter presenter
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void updateMapMarkers(LatLng latLng, List<Place> placeList
|
public void updateMapMarkers(LatLng latLng, List<Place> placeList
|
||||||
, Marker selectedMarker
|
, Marker selectedMarker
|
||||||
, NearbyParentFragmentPresenter nearbyParentFragmentPresenter) {
|
, NearbyParentFragmentPresenter nearbyParentFragmentPresenter) {
|
||||||
Log.d("denemeTest","updateMapMarkers, curLatng:"+latLng);
|
Timber.d("Updates map markers");
|
||||||
List<NearbyBaseMarker> customBaseMarkerOptions = NearbyController
|
List<NearbyBaseMarker> customBaseMarkerOptions = NearbyController
|
||||||
.loadAttractionsFromLocationToBaseMarkerOptions(latLng, // Curlatlang will be used to calculate distances
|
.loadAttractionsFromLocationToBaseMarkerOptions(latLng, // Curlatlang will be used to calculate distances
|
||||||
placeList,
|
placeList,
|
||||||
getActivity(),
|
getActivity(),
|
||||||
bookmarkLocationDao.getAllBookmarksLocations());
|
bookmarkLocationDao.getAllBookmarksLocations());
|
||||||
mapboxMap.clear();
|
mapboxMap.clear();
|
||||||
// TODO: set search latlang here
|
|
||||||
|
|
||||||
/*mapboxMap.animateCamera(CameraUpdateFactory
|
|
||||||
.newCameraPosition(cameraPosition), 1000);*/
|
|
||||||
// TODO: set position depening to botom sheet position heere
|
|
||||||
// We are trying to find nearby places around our custom searched area, thus custom parameter is nonnull
|
|
||||||
addNearbyMarkersToMapBoxMap(customBaseMarkerOptions, selectedMarker, nearbyParentFragmentPresenter);
|
addNearbyMarkersToMapBoxMap(customBaseMarkerOptions, selectedMarker, nearbyParentFragmentPresenter);
|
||||||
// Re-enable mapbox gestures on custom location markers load
|
// Re-enable mapbox gestures on custom location markers load
|
||||||
mapboxMap.getUiSettings().setAllGesturesEnabled(true);
|
mapboxMap.getUiSettings().setAllGesturesEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes map camera follow users location with animation
|
||||||
|
* @param curLatLng current location of user
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void updateMapToTrackPosition(LatLng curLatLng) {
|
public void updateMapToTrackPosition(LatLng curLatLng) {
|
||||||
|
Timber.d("Updates map camera to track user position");
|
||||||
CameraPosition cameraPosition = new CameraPosition.Builder().target
|
CameraPosition cameraPosition = new CameraPosition.Builder().target
|
||||||
(LocationUtils.commonsLatLngToMapBoxLatLng(curLatLng)).build();
|
(LocationUtils.commonsLatLngToMapBoxLatLng(curLatLng)).build();
|
||||||
mapboxMap.setCameraPosition(cameraPosition);
|
mapboxMap.setCameraPosition(cameraPosition);
|
||||||
|
|
@ -300,11 +306,11 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
|
||||||
* Should be called only on creation of mapboxMap, there
|
* Should be called only on creation of mapboxMap, there
|
||||||
* is other method to update markers location with users
|
* is other method to update markers location with users
|
||||||
* move.
|
* move.
|
||||||
|
* @param curLatLng current location
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addCurrentLocationMarker(LatLng curLatLng) {
|
public void addCurrentLocationMarker(LatLng curLatLng) {
|
||||||
Log.d("denemeTest","addCurrentLocationMarker");
|
Timber.d("Adds current location marker");
|
||||||
Timber.d("addCurrentLocationMarker is called");
|
|
||||||
|
|
||||||
Icon icon = IconFactory.getInstance(getContext()).fromResource(R.drawable.current_location_marker);
|
Icon icon = IconFactory.getInstance(getContext()).fromResource(R.drawable.current_location_marker);
|
||||||
|
|
||||||
|
|
@ -312,9 +318,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
|
||||||
.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);
|
List<com.mapbox.mapboxsdk.geometry.LatLng> circle = UiUtils.createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(),
|
||||||
|
|
||||||
List<com.mapbox.mapboxsdk.geometry.LatLng> circle = createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(),
|
|
||||||
curLatLng.getAccuracy() * 2, 100);
|
curLatLng.getAccuracy() * 2, 100);
|
||||||
|
|
||||||
PolygonOptions currentLocationPolygonOptions = new PolygonOptions()
|
PolygonOptions currentLocationPolygonOptions = new PolygonOptions()
|
||||||
|
|
@ -324,50 +328,24 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
|
||||||
mapboxMap.addPolygon(currentLocationPolygonOptions);
|
mapboxMap.addPolygon(currentLocationPolygonOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: go to util
|
|
||||||
/**
|
/**
|
||||||
* Creates a series of points that create a circle on the map.
|
* Adds markers to map
|
||||||
* Takes the center latitude, center longitude of the circle,
|
* @param baseMarkerList is markers will be added
|
||||||
* the radius in meter and the number of nodes of the circle.
|
* @param selectedMarker is selected marker by user
|
||||||
*
|
* @param nearbyParentFragmentPresenter presenter
|
||||||
* @return List List of LatLng points of the circle.
|
|
||||||
*/
|
*/
|
||||||
private List<com.mapbox.mapboxsdk.geometry.LatLng> createCircleArray(
|
|
||||||
double centerLat, double centerLong, float radius, int nodes) {
|
|
||||||
List<com.mapbox.mapboxsdk.geometry.LatLng> circle = new ArrayList<>();
|
|
||||||
float radiusKilometer = radius / 1000;
|
|
||||||
double radiusLong = radiusKilometer
|
|
||||||
/ (111.320 * Math.cos(centerLat * Math.PI / 180));
|
|
||||||
double radiusLat = radiusKilometer / 110.574;
|
|
||||||
|
|
||||||
for (int i = 0; i < nodes; i++) {
|
|
||||||
double theta = ((double) i / (double) nodes) * (2 * Math.PI);
|
|
||||||
double nodeLongitude = centerLong + radiusLong * Math.cos(theta);
|
|
||||||
double nodeLatitude = centerLat + radiusLat * Math.sin(theta);
|
|
||||||
circle.add(new com.mapbox.mapboxsdk.geometry.LatLng(nodeLatitude, nodeLongitude));
|
|
||||||
}
|
|
||||||
return circle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNearbyMarkersToMapBoxMap(@Nullable List<NearbyBaseMarker> baseMarkerList
|
public void addNearbyMarkersToMapBoxMap(@Nullable List<NearbyBaseMarker> baseMarkerList
|
||||||
, Marker selectedMarker
|
, Marker selectedMarker
|
||||||
, NearbyParentFragmentPresenter nearbyParentFragmentPresenter) {
|
, NearbyParentFragmentPresenter nearbyParentFragmentPresenter) {
|
||||||
Log.d("denemeTest","add markers to map");
|
Log.d("denemeTest","add markers to map");
|
||||||
mapboxMap.addMarkers(baseMarkerList);
|
mapboxMap.addMarkers(baseMarkerList);
|
||||||
mapboxMap.setOnInfoWindowCloseListener(marker -> {
|
|
||||||
/*if (marker == selected) {
|
|
||||||
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
||||||
}*/
|
|
||||||
});
|
|
||||||
map.getMapAsync(mapboxMap -> {
|
map.getMapAsync(mapboxMap -> {
|
||||||
mapboxMap.addMarkers(baseMarkerList);
|
mapboxMap.addMarkers(baseMarkerList);
|
||||||
//fabRecenter.setVisibility(View.VISIBLE);
|
|
||||||
setMapMarkerActions(selectedMarker, nearbyParentFragmentPresenter);
|
setMapMarkerActions(selectedMarker, nearbyParentFragmentPresenter);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LatLng getCameraTarget() {
|
public LatLng getCameraTarget() {
|
||||||
return LocationUtils
|
return LocationUtils
|
||||||
|
|
@ -405,6 +383,12 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets marker icon according to marker status. Sets title and distance.
|
||||||
|
* @param isBookmarked true if place is bookmarked
|
||||||
|
* @param place
|
||||||
|
* @param curLatLng current location
|
||||||
|
*/
|
||||||
public void updateMarker(boolean isBookmarked, Place place, @Nullable LatLng curLatLng) {
|
public void updateMarker(boolean isBookmarked, Place place, @Nullable LatLng curLatLng) {
|
||||||
|
|
||||||
VectorDrawableCompat vectorDrawable;
|
VectorDrawableCompat vectorDrawable;
|
||||||
|
|
@ -446,7 +430,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void centerMapToPlace(Place place, boolean isPortraitMode) {
|
public void centerMapToPlace(Place place, boolean isPortraitMode) {
|
||||||
Log.d("denemeSon","isPortyrait:"+isPortraitMode);
|
Timber.d("Map is centered to place");
|
||||||
double cameraShift;
|
double cameraShift;
|
||||||
if (isPortraitMode) {
|
if (isPortraitMode) {
|
||||||
cameraShift = CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT;
|
cameraShift = CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,11 @@ import android.graphics.Canvas;
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
|
|
||||||
|
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class UiUtils {
|
public class UiUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,4 +48,28 @@ public class UiUtils {
|
||||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||||
return px / ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
return px / ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a series of points that create a circle on the map.
|
||||||
|
* Takes the center latitude, center longitude of the circle,
|
||||||
|
* the radius in meter and the number of nodes of the circle.
|
||||||
|
*
|
||||||
|
* @return List List of LatLng points of the circle.
|
||||||
|
*/
|
||||||
|
public static List<LatLng> createCircleArray(
|
||||||
|
double centerLat, double centerLong, float radius, int nodes) {
|
||||||
|
List<com.mapbox.mapboxsdk.geometry.LatLng> circle = new ArrayList<>();
|
||||||
|
float radiusKilometer = radius / 1000;
|
||||||
|
double radiusLong = radiusKilometer
|
||||||
|
/ (111.320 * Math.cos(centerLat * Math.PI / 180));
|
||||||
|
double radiusLat = radiusKilometer / 110.574;
|
||||||
|
|
||||||
|
for (int i = 0; i < nodes; i++) {
|
||||||
|
double theta = ((double) i / (double) nodes) * (2 * Math.PI);
|
||||||
|
double nodeLongitude = centerLong + radiusLong * Math.cos(theta);
|
||||||
|
double nodeLatitude = centerLat + radiusLat * Math.sin(theta);
|
||||||
|
circle.add(new com.mapbox.mapboxsdk.geometry.LatLng(nodeLatitude, nodeLongitude));
|
||||||
|
}
|
||||||
|
return circle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue