mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43: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
|
|
@ -412,23 +412,8 @@ public class OkHttpJsonApiClient {
|
||||||
"<!--Created by Wikimedia Commons Android app -->\n" +
|
"<!--Created by Wikimedia Commons Android app -->\n" +
|
||||||
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" +
|
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" +
|
||||||
" <Document>";
|
" <Document>";
|
||||||
|
List<PlaceBindings> placeBindings = runQuery(leftLatLng,
|
||||||
int increment = 1;
|
rightLatLng);
|
||||||
double longitude = leftLatLng.getLongitude();
|
|
||||||
|
|
||||||
while (longitude <= rightLatLng.getLongitude()) {
|
|
||||||
double NEXT_LONGITUDE =
|
|
||||||
(increment + longitude) >= 0.0 && (increment + longitude) <= 1.0 ? 0.0
|
|
||||||
: increment + longitude;
|
|
||||||
|
|
||||||
double latitude = leftLatLng.getLatitude();
|
|
||||||
|
|
||||||
while (latitude <= rightLatLng.getLatitude()) {
|
|
||||||
double NEXT_LATITUDE =
|
|
||||||
(increment + latitude) >= 0.0 && (increment + latitude) <= 1.0 ? 0.0
|
|
||||||
: increment + latitude;
|
|
||||||
List<PlaceBindings> placeBindings = runQuery(new LatLng(latitude, longitude, 0),
|
|
||||||
new LatLng(NEXT_LATITUDE, NEXT_LONGITUDE, 0));
|
|
||||||
if (placeBindings != null) {
|
if (placeBindings != null) {
|
||||||
for (PlaceBindings item : placeBindings) {
|
for (PlaceBindings item : placeBindings) {
|
||||||
if (item.getItem() != null && item.getLabel() != null && item.getClas() != null) {
|
if (item.getItem() != null && item.getLabel() != null && item.getClas() != null) {
|
||||||
|
|
@ -466,10 +451,6 @@ public class OkHttpJsonApiClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
latitude += increment;
|
|
||||||
}
|
|
||||||
longitude += increment;
|
|
||||||
}
|
|
||||||
kmlString = kmlString + "\n </Document>\n" +
|
kmlString = kmlString + "\n </Document>\n" +
|
||||||
"</kml>\n";
|
"</kml>\n";
|
||||||
return kmlString;
|
return kmlString;
|
||||||
|
|
@ -495,22 +476,7 @@ public class OkHttpJsonApiClient {
|
||||||
" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">"
|
" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">"
|
||||||
+ "\n<bounds minlat=\"$MIN_LATITUDE\" minlon=\"$MIN_LONGITUDE\" maxlat=\"$MAX_LATITUDE\" maxlon=\"$MAX_LONGITUDE\"/>";
|
+ "\n<bounds minlat=\"$MIN_LATITUDE\" minlon=\"$MIN_LONGITUDE\" maxlat=\"$MAX_LATITUDE\" maxlon=\"$MAX_LONGITUDE\"/>";
|
||||||
|
|
||||||
int increment = 1;
|
List<PlaceBindings> placeBindings = runQuery(leftLatLng,rightLatLng);
|
||||||
double longitude = leftLatLng.getLongitude();
|
|
||||||
|
|
||||||
while (longitude <= rightLatLng.getLongitude()) {
|
|
||||||
double NEXT_LONGITUDE =
|
|
||||||
(increment + longitude) >= 0.0 && (increment + longitude) <= 1.0 ? 0.0
|
|
||||||
: increment + longitude;
|
|
||||||
|
|
||||||
double latitude = leftLatLng.getLatitude();
|
|
||||||
|
|
||||||
while (latitude <= rightLatLng.getLatitude()) {
|
|
||||||
double NEXT_LATITUDE =
|
|
||||||
(increment + latitude) >= 0.0 && (increment + latitude) <= 1.0 ? 0.0
|
|
||||||
: increment + latitude;
|
|
||||||
List<PlaceBindings> placeBindings = runQuery(new LatLng(latitude, longitude, 0),
|
|
||||||
new LatLng(NEXT_LATITUDE, NEXT_LONGITUDE, 0));
|
|
||||||
if (placeBindings != null) {
|
if (placeBindings != null) {
|
||||||
for (PlaceBindings item : placeBindings) {
|
for (PlaceBindings item : placeBindings) {
|
||||||
if (item.getItem() != null && item.getLabel() != null && item.getClas() != null) {
|
if (item.getItem() != null && item.getLabel() != null && item.getClas() != null) {
|
||||||
|
|
@ -545,10 +511,7 @@ public class OkHttpJsonApiClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
latitude += increment;
|
|
||||||
}
|
|
||||||
longitude += increment;
|
|
||||||
}
|
}
|
||||||
gpxString = gpxString + "\n</gpx>";
|
gpxString = gpxString + "\n</gpx>";
|
||||||
return gpxString;
|
return gpxString;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package fr.free.nrw.commons.nearby;
|
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.MainThread;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import fr.free.nrw.commons.BaseMarker;
|
import fr.free.nrw.commons.BaseMarker;
|
||||||
import fr.free.nrw.commons.MapController;
|
import fr.free.nrw.commons.MapController;
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
import fr.free.nrw.commons.location.LatLng;
|
||||||
|
|
@ -16,9 +18,6 @@ import java.util.Map;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import timber.log.Timber;
|
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 {
|
public class NearbyController extends MapController {
|
||||||
|
|
||||||
private static final int MAX_RESULTS = 1000;
|
private static final int MAX_RESULTS = 1000;
|
||||||
|
|
@ -118,12 +117,38 @@ public class NearbyController extends MapController {
|
||||||
return nearbyPlacesInfo;
|
return nearbyPlacesInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlacesAsKML(LatLng leftLatLng, LatLng rightLatLng) throws Exception {
|
public String getPlacesAsKML(LatLng currentLocation) throws Exception {
|
||||||
return nearbyPlaces.getPlacesAsKML(leftLatLng, rightLatLng);
|
return nearbyPlaces.getPlacesAsKML(
|
||||||
|
calculateSouthWest(currentLocation.getLatitude(), currentLocation.getLongitude(), 10),
|
||||||
|
calculateNorthEast(currentLocation.getLatitude(), currentLocation.getLongitude(), 10)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlacesAsGPX(LatLng leftLatLng, LatLng rightLatLng) throws Exception {
|
public String getPlacesAsGPX(LatLng currentLocation) throws Exception {
|
||||||
return nearbyPlaces.getPlacesAsGPX(leftLatLng, rightLatLng);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -267,8 +292,6 @@ public class NearbyController extends MapController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates makerLabelList item isBookmarked value
|
* Updates makerLabelList item isBookmarked value
|
||||||
*
|
*
|
||||||
|
|
@ -280,7 +303,8 @@ public class NearbyController extends MapController {
|
||||||
for (ListIterator<MarkerPlaceGroup> iter = markerLabelList.listIterator();
|
for (ListIterator<MarkerPlaceGroup> iter = markerLabelList.listIterator();
|
||||||
iter.hasNext(); ) {
|
iter.hasNext(); ) {
|
||||||
MarkerPlaceGroup markerPlaceGroup = iter.next();
|
MarkerPlaceGroup markerPlaceGroup = iter.next();
|
||||||
if (markerPlaceGroup.getPlace().getWikiDataEntityId().equals(place.getWikiDataEntityId())) {
|
if (markerPlaceGroup.getPlace().getWikiDataEntityId()
|
||||||
|
.equals(place.getWikiDataEntityId())) {
|
||||||
iter.set(new MarkerPlaceGroup(isBookmarked, place));
|
iter.set(new MarkerPlaceGroup(isBookmarked, place));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -289,15 +289,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||||
try {
|
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.setTitle(getString(R.string.saving_gpx_file));
|
||||||
progressDialog.show();
|
progressDialog.show();
|
||||||
savePlacesAsGPX(screenTopRightLatLng, screenBottomLeftLatLng);
|
savePlacesAsGPX();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
@ -309,15 +303,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
public boolean onMenuItemClick(@NonNull MenuItem item) {
|
||||||
try {
|
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.setTitle(getString(R.string.saving_kml_file));
|
||||||
progressDialog.show();
|
progressDialog.show();
|
||||||
savePlacesAsKML(screenTopRightLatLng, screenBottomLeftLatLng);
|
savePlacesAsKML();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(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
|
final Observable<String> savePlacesObservable = Observable
|
||||||
.fromCallable(() -> nearbyController
|
.fromCallable(() -> nearbyController
|
||||||
.getPlacesAsKML(latLng, nextlatLng));
|
.getPlacesAsKML(getMapFocus()));
|
||||||
compositeDisposable.add(savePlacesObservable
|
compositeDisposable.add(savePlacesObservable
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.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
|
final Observable<String> savePlacesObservable = Observable
|
||||||
.fromCallable(() -> nearbyController
|
.fromCallable(() -> nearbyController
|
||||||
.getPlacesAsGPX(latLng, nextlatLng));
|
.getPlacesAsGPX(getMapFocus()));
|
||||||
compositeDisposable.add(savePlacesObservable
|
compositeDisposable.add(savePlacesObservable
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue