mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
Fixes Nearby export: Pins not all around me (#5658)
* Fixed Grey empty screen at Upload wizard caption step after denying files permission * Empty commit * Fixed loop issue * Created docs for earlier commits * Fixed javadoc * Fixed spaces * Added added basic features to OSM Maps * Added search location feature * Added filter to Open Street Maps * Fixed chipGroup in Open Street Maps * Removed mapBox code * Removed mapBox's code * Reformat code * Reformatted code * Removed rotation feature to map * Removed rotation files and Fixed Marker click problem * Ignored failing tests * Added voice input feature * Fixed test cases * Changed caption and description text * Replaced mapbox to osmdroid in upload activity * Fixed Unit Tests * Made selected marker to be fixed on map * Changed color of map marker * Fixes #4345 * Delete app/src/main/res/values-yue-hant directory * Added comment explaining the context * Fixes #5651 * Deleted directory * Changed query to 10 kilometers * Fixed issue --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
6d4ba12775
commit
1f064e29fa
3 changed files with 109 additions and 134 deletions
|
|
@ -1,8 +1,10 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import static fr.free.nrw.commons.utils.LengthUtils.computeDistanceBetween;
|
||||
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
|
||||
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import fr.free.nrw.commons.BaseMarker;
|
||||
import fr.free.nrw.commons.MapController;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
|
|
@ -16,9 +18,6 @@ import java.util.Map;
|
|||
import javax.inject.Inject;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static fr.free.nrw.commons.utils.LengthUtils.computeDistanceBetween;
|
||||
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
|
||||
|
||||
public class NearbyController extends MapController {
|
||||
|
||||
private static final int MAX_RESULTS = 1000;
|
||||
|
|
@ -39,7 +38,7 @@ public class NearbyController extends MapController {
|
|||
/**
|
||||
* Prepares Place list to make their distance information update later.
|
||||
*
|
||||
* @param currentLatLng current location for user
|
||||
* @param currentLatLng current location for user
|
||||
* @param searchLatLng the location user wants to search around
|
||||
* @param returnClosestResult if this search is done to find closest result or all results
|
||||
* @param customQuery if this search is done via an advanced query
|
||||
|
|
@ -118,18 +117,44 @@ public class NearbyController extends MapController {
|
|||
return nearbyPlacesInfo;
|
||||
}
|
||||
|
||||
public String getPlacesAsKML(LatLng leftLatLng, LatLng rightLatLng) throws Exception {
|
||||
return nearbyPlaces.getPlacesAsKML(leftLatLng, rightLatLng);
|
||||
public String getPlacesAsKML(LatLng currentLocation) throws Exception {
|
||||
return nearbyPlaces.getPlacesAsKML(
|
||||
calculateSouthWest(currentLocation.getLatitude(), currentLocation.getLongitude(), 10),
|
||||
calculateNorthEast(currentLocation.getLatitude(), currentLocation.getLongitude(), 10)
|
||||
);
|
||||
}
|
||||
|
||||
public String getPlacesAsGPX(LatLng leftLatLng, LatLng rightLatLng) throws Exception {
|
||||
return nearbyPlaces.getPlacesAsGPX(leftLatLng, rightLatLng);
|
||||
public String getPlacesAsGPX(LatLng currentLocation) throws Exception {
|
||||
return nearbyPlaces.getPlacesAsGPX(
|
||||
calculateSouthWest(currentLocation.getLatitude(), currentLocation.getLongitude(), 10),
|
||||
calculateNorthEast(currentLocation.getLatitude(), currentLocation.getLongitude(), 10)
|
||||
);
|
||||
}
|
||||
|
||||
public static LatLng calculateNorthEast(double latitude, double longitude, double distance) {
|
||||
double lat1 = Math.toRadians(latitude);
|
||||
double deltaLat = distance * 0.008;
|
||||
double deltaLon = distance / Math.cos(lat1)*0.008;
|
||||
double lat2 = latitude + deltaLat;
|
||||
double lon2 = longitude + deltaLon;
|
||||
|
||||
return new LatLng(lat2, lon2, 0);
|
||||
}
|
||||
|
||||
public static LatLng calculateSouthWest(double latitude, double longitude, double distance) {
|
||||
double lat1 = Math.toRadians(latitude);
|
||||
double deltaLat = distance * 0.008;
|
||||
double deltaLon = distance / Math.cos(lat1)*0.008;
|
||||
double lat2 = latitude - deltaLat;
|
||||
double lon2 = longitude - deltaLon;
|
||||
|
||||
return new LatLng(lat2, lon2, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares Place list to make their distance information update later.
|
||||
*
|
||||
* @param currentLatLng The current latitude and longitude.
|
||||
* @param currentLatLng The current latitude and longitude.
|
||||
* @param screenTopRight The top right corner of the screen (latitude,
|
||||
* longitude).
|
||||
* @param screenBottomLeft The bottom left corner of the screen (latitude,
|
||||
|
|
@ -221,7 +246,7 @@ public class NearbyController extends MapController {
|
|||
/**
|
||||
* Prepares Place list to make their distance information update later.
|
||||
*
|
||||
* @param currentLatLng current location for user
|
||||
* @param currentLatLng current location for user
|
||||
* @param searchLatLng the location user wants to search around
|
||||
* @param returnClosestResult if this search is done to find closest result or all results
|
||||
* @return NearbyPlacesInfo a variable holds Place list without distance information and
|
||||
|
|
@ -239,12 +264,12 @@ public class NearbyController extends MapController {
|
|||
* Loads attractions from location for map view, we need to return BaseMarkerOption data type.
|
||||
*
|
||||
* @param currentLatLng users current location
|
||||
* @param placeList list of nearby places in Place data type
|
||||
* @param placeList list of nearby places in Place data type
|
||||
* @return BaseMarkerOptions list that holds nearby places
|
||||
*/
|
||||
public static List<BaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
LatLng currentLatLng,
|
||||
List<Place> placeList) {
|
||||
LatLng currentLatLng,
|
||||
List<Place> placeList) {
|
||||
List<BaseMarker> baseMarkersList = new ArrayList<>();
|
||||
|
||||
if (placeList == null) {
|
||||
|
|
@ -259,7 +284,7 @@ public class NearbyController extends MapController {
|
|||
baseMarker.setPosition(
|
||||
new fr.free.nrw.commons.location.LatLng(
|
||||
place.location.getLatitude(),
|
||||
place.location.getLongitude(),0));
|
||||
place.location.getLongitude(), 0));
|
||||
baseMarker.setPlace(place);
|
||||
baseMarkersList.add(baseMarker);
|
||||
}
|
||||
|
|
@ -267,8 +292,6 @@ public class NearbyController extends MapController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Updates makerLabelList item isBookmarked value
|
||||
*
|
||||
|
|
@ -280,7 +303,8 @@ public class NearbyController extends MapController {
|
|||
for (ListIterator<MarkerPlaceGroup> iter = markerLabelList.listIterator();
|
||||
iter.hasNext(); ) {
|
||||
MarkerPlaceGroup markerPlaceGroup = iter.next();
|
||||
if (markerPlaceGroup.getPlace().getWikiDataEntityId().equals(place.getWikiDataEntityId())) {
|
||||
if (markerPlaceGroup.getPlace().getWikiDataEntityId()
|
||||
.equals(place.getWikiDataEntityId())) {
|
||||
iter.set(new MarkerPlaceGroup(isBookmarked, place));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -289,15 +289,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
@Override
|
||||
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||
try {
|
||||
IGeoPoint screenTopRight = binding.map.getProjection().fromPixels(binding.map.getWidth(), 0);
|
||||
IGeoPoint screenBottomLeft = binding.map.getProjection().fromPixels(0, binding.map.getHeight());
|
||||
fr.free.nrw.commons.location.LatLng screenTopRightLatLng = new fr.free.nrw.commons.location.LatLng(
|
||||
screenBottomLeft.getLatitude(), screenBottomLeft.getLongitude(), 0);
|
||||
fr.free.nrw.commons.location.LatLng screenBottomLeftLatLng = new fr.free.nrw.commons.location.LatLng(
|
||||
screenTopRight.getLatitude(), screenTopRight.getLongitude(), 0);
|
||||
progressDialog.setTitle(getString(R.string.saving_gpx_file));
|
||||
progressDialog.show();
|
||||
savePlacesAsGPX(screenTopRightLatLng, screenBottomLeftLatLng);
|
||||
savePlacesAsGPX();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
@ -309,15 +303,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
@Override
|
||||
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||
try {
|
||||
IGeoPoint screenTopRight = binding.map.getProjection().fromPixels(binding.map.getWidth(), 0);
|
||||
IGeoPoint screenBottomLeft = binding.map.getProjection().fromPixels(0, binding.map.getHeight());
|
||||
fr.free.nrw.commons.location.LatLng screenTopRightLatLng = new fr.free.nrw.commons.location.LatLng(
|
||||
screenBottomLeft.getLatitude(), screenBottomLeft.getLongitude(), 0);
|
||||
fr.free.nrw.commons.location.LatLng screenBottomLeftLatLng = new fr.free.nrw.commons.location.LatLng(
|
||||
screenTopRight.getLatitude(), screenTopRight.getLongitude(), 0);
|
||||
progressDialog.setTitle(getString(R.string.saving_kml_file));
|
||||
progressDialog.show();
|
||||
savePlacesAsKML(screenTopRightLatLng, screenBottomLeftLatLng);
|
||||
savePlacesAsKML();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
@ -1163,10 +1151,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
}
|
||||
}
|
||||
|
||||
private void savePlacesAsKML(LatLng latLng, LatLng nextlatLng) {
|
||||
private void savePlacesAsKML() {
|
||||
final Observable<String> savePlacesObservable = Observable
|
||||
.fromCallable(() -> nearbyController
|
||||
.getPlacesAsKML(latLng, nextlatLng));
|
||||
.getPlacesAsKML(getMapFocus()));
|
||||
compositeDisposable.add(savePlacesObservable
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
|
@ -1197,10 +1185,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
}));
|
||||
}
|
||||
|
||||
private void savePlacesAsGPX(LatLng latLng, LatLng nextlatLng) {
|
||||
private void savePlacesAsGPX() {
|
||||
final Observable<String> savePlacesObservable = Observable
|
||||
.fromCallable(() -> nearbyController
|
||||
.getPlacesAsGPX(latLng, nextlatLng));
|
||||
.getPlacesAsGPX(getMapFocus()));
|
||||
compositeDisposable.add(savePlacesObservable
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue