mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Implement add nearby markers and add current marker methods
This commit is contained in:
parent
a96bbb18a5
commit
d4cee8b253
5 changed files with 115 additions and 16 deletions
|
|
@ -2,7 +2,7 @@ package fr.free.nrw.commons.nearby;
|
||||||
|
|
||||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||||
|
|
||||||
class NearbyMarker extends Marker {
|
public class NearbyMarker extends Marker {
|
||||||
private final Place place;
|
private final Place place;
|
||||||
private NearbyBaseMarker nearbyBaseMarker;
|
private NearbyBaseMarker nearbyBaseMarker;
|
||||||
|
|
||||||
|
|
@ -11,13 +11,13 @@ class NearbyMarker extends Marker {
|
||||||
*
|
*
|
||||||
* @param baseMarkerOptions The builder used to construct the Marker.
|
* @param baseMarkerOptions The builder used to construct the Marker.
|
||||||
*/
|
*/
|
||||||
NearbyMarker(NearbyBaseMarker baseMarkerOptions, Place place) {
|
public NearbyMarker(NearbyBaseMarker baseMarkerOptions, Place place) {
|
||||||
super(baseMarkerOptions);
|
super(baseMarkerOptions);
|
||||||
this.place = place;
|
this.place = place;
|
||||||
this.nearbyBaseMarker = baseMarkerOptions;
|
this.nearbyBaseMarker = baseMarkerOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
NearbyBaseMarker getNearbyBaseMarker() {
|
public NearbyBaseMarker getNearbyBaseMarker() {
|
||||||
return nearbyBaseMarker;
|
return nearbyBaseMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ public interface NearbyMapContract {
|
||||||
void showInformationBottomSheet();
|
void showInformationBottomSheet();
|
||||||
void initViews();
|
void initViews();
|
||||||
void updateMapMarkers(LatLng latLng, List<Place> placeList);
|
void updateMapMarkers(LatLng latLng, List<Place> placeList);
|
||||||
void updateMapToTrackPosition();
|
void updateMapToTrackPosition(LatLng curLatLng);
|
||||||
void setListeners();
|
void setListeners();
|
||||||
MapView setupMapView(Bundle savedInstanceState);
|
MapView setupMapView(Bundle savedInstanceState);
|
||||||
void addCurrentLocationMarker();
|
void addCurrentLocationMarker(LatLng curLatLng);
|
||||||
void setSearchThisAreaButtonVisibility(boolean visible);
|
void setSearchThisAreaButtonVisibility(boolean visible);
|
||||||
boolean isCurrentLocationMarkerVisible();
|
boolean isCurrentLocationMarkerVisible();
|
||||||
void addNearbyMarkersToMapBoxMap(List<NearbyBaseMarker> baseMarkerOptions);
|
void addNearbyMarkersToMapBoxMap(List<NearbyBaseMarker> baseMarkerOptions);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package fr.free.nrw.commons.nearby.mvp.fragments;
|
package fr.free.nrw.commons.nearby.mvp.fragments;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
@ -16,6 +17,11 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.mapbox.mapboxsdk.Mapbox;
|
import com.mapbox.mapboxsdk.Mapbox;
|
||||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||||
|
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.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;
|
||||||
import com.mapbox.mapboxsdk.constants.Style;
|
import com.mapbox.mapboxsdk.constants.Style;
|
||||||
|
|
@ -24,6 +30,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||||
import com.mapbox.mapboxsdk.plugins.localization.LocalizationPlugin;
|
import com.mapbox.mapboxsdk.plugins.localization.LocalizationPlugin;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
@ -40,6 +47,7 @@ import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
import fr.free.nrw.commons.location.LatLng;
|
||||||
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
|
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
|
||||||
import fr.free.nrw.commons.nearby.NearbyController;
|
import fr.free.nrw.commons.nearby.NearbyController;
|
||||||
|
import fr.free.nrw.commons.nearby.NearbyMarker;
|
||||||
import fr.free.nrw.commons.nearby.Place;
|
import fr.free.nrw.commons.nearby.Place;
|
||||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
||||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
||||||
|
|
@ -136,7 +144,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
//viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -174,6 +182,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mapboxMap = mapboxMap;
|
this.mapboxMap = mapboxMap;
|
||||||
|
viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
||||||
//addMapMovementListeners();
|
//addMapMovementListeners();
|
||||||
//updateMapSignificantlyForCurrentLocation();
|
//updateMapSignificantlyForCurrentLocation();
|
||||||
});
|
});
|
||||||
|
|
@ -205,18 +214,20 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
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);
|
||||||
mapboxMap.animateCamera(CameraUpdateFactory
|
/*mapboxMap.animateCamera(CameraUpdateFactory
|
||||||
.newCameraPosition(cameraPosition), 1000);
|
.newCameraPosition(cameraPosition), 1000);*/
|
||||||
// TODO: set position depening to botom sheet position heere
|
// 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
|
// We are trying to find nearby places around our custom searched area, thus custom parameter is nonnull
|
||||||
addNearbyMarkersToMapBoxMap(customBaseMarkerOptions);
|
addNearbyMarkersToMapBoxMap(customBaseMarkerOptions);
|
||||||
// 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);
|
||||||
|
updateMapToTrackPosition(curLatLng);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMapToTrackPosition() {
|
public void updateMapToTrackPosition(LatLng curLatLng) {
|
||||||
//addCurrentLocationMarker(mapboxMap);
|
Log.d("deneme1","updateMapToTrackPosition");
|
||||||
|
addCurrentLocationMarker(curLatLng);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,12 +235,65 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
public void setListeners() {
|
public void setListeners() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Adds a marker for the user's current position. Adds a
|
||||||
|
* circle which uses the accuracy * 2, to draw a circle
|
||||||
|
* which represents the user's position with an accuracy
|
||||||
|
* of 95%.
|
||||||
|
*
|
||||||
|
* Should be called only on creation of mapboxMap, there
|
||||||
|
* is other method to update markers location with users
|
||||||
|
* move.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addCurrentLocationMarker() {
|
public void addCurrentLocationMarker(LatLng curLatLng) {
|
||||||
|
Log.d("deneme1","addCurrentLocationMarker");
|
||||||
|
Timber.d("addCurrentLocationMarker is called");
|
||||||
|
|
||||||
|
Icon icon = IconFactory.getInstance(getContext()).fromResource(R.drawable.current_location_marker);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
List<com.mapbox.mapboxsdk.geometry.LatLng> circle = createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(),
|
||||||
|
curLatLng.getAccuracy() * 2, 100);
|
||||||
|
|
||||||
|
PolygonOptions currentLocationPolygonOptions = new PolygonOptions()
|
||||||
|
.addAll(circle)
|
||||||
|
.strokeColor(Color.parseColor("#55000000"))
|
||||||
|
.fillColor(Color.parseColor("#11000000"));
|
||||||
|
mapboxMap.addPolygon(currentLocationPolygonOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: go to util
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
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 setSearchThisAreaButtonVisibility(boolean visible) {
|
public void setSearchThisAreaButtonVisibility(boolean visible) {
|
||||||
|
|
||||||
|
|
@ -240,9 +304,42 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void addNearbyMarkersToMapBoxMap(List<NearbyBaseMarker> baseMarkerOptions) {
|
* Adds markers for nearby places to mapbox map
|
||||||
|
*/
|
||||||
|
public void addNearbyMarkersToMapBoxMap(@Nullable List<NearbyBaseMarker> baseMarkerList) {
|
||||||
|
Timber.d("addNearbyMarkersToMapBoxMap is called");
|
||||||
|
|
||||||
|
mapboxMap.addMarkers(baseMarkerList);
|
||||||
|
mapboxMap.setOnInfoWindowCloseListener(marker -> {
|
||||||
|
/*if (marker == selected) {
|
||||||
|
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||||
|
}*/
|
||||||
|
});
|
||||||
|
mapView.getMapAsync(mapboxMap -> {
|
||||||
|
mapboxMap.addMarkers(baseMarkerList);
|
||||||
|
//fabRecenter.setVisibility(View.VISIBLE);
|
||||||
|
mapboxMap.setOnInfoWindowCloseListener(marker -> {
|
||||||
|
/*if (marker == selected) {
|
||||||
|
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||||
|
}*/
|
||||||
|
});
|
||||||
|
|
||||||
|
mapboxMap.setOnMarkerClickListener(marker -> {
|
||||||
|
|
||||||
|
if (marker instanceof NearbyMarker) {
|
||||||
|
//this.selected = marker;
|
||||||
|
NearbyMarker nearbyMarker = (NearbyMarker) marker;
|
||||||
|
Place place = nearbyMarker.getNearbyBaseMarker().getPlace();
|
||||||
|
passInfoToSheet(place);
|
||||||
|
bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||||
|
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ public class NearbyParentFragmentPresenter
|
||||||
// TODO add a search location here
|
// TODO add a search location here
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
nearbyMapFragmentView.updateMapToTrackPosition();
|
nearbyMapFragmentView.updateMapToTrackPosition(curLatLng);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,8 +165,9 @@ public class NearbyParentFragmentPresenter
|
||||||
* @param nearbyPlacesInfo This variable has place list information and distances.
|
* @param nearbyPlacesInfo This variable has place list information and distances.
|
||||||
*/
|
*/
|
||||||
public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
|
public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
|
||||||
|
Log.d("deneme","updateMapMarkers npfp");
|
||||||
nearbyMapFragmentView.updateMapMarkers(nearbyPlacesInfo.curLatLng, nearbyPlacesInfo.placeList);
|
nearbyMapFragmentView.updateMapMarkers(nearbyPlacesInfo.curLatLng, nearbyPlacesInfo.placeList);
|
||||||
nearbyMapFragmentView.updateMapToTrackPosition();
|
nearbyMapFragmentView.updateMapToTrackPosition(nearbyPlacesInfo.curLatLng);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
android:layout_below="@id/toolbar"
|
android:layout_below="@id/toolbar"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:background="#aa969696"
|
android:background="#aa969696"
|
||||||
|
android:visibility="gone"
|
||||||
android:elevation="6dp">
|
android:elevation="6dp">
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue