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:
Kanahia 2024-03-29 16:14:49 +05:30 committed by GitHub
parent 6d4ba12775
commit 1f064e29fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 109 additions and 134 deletions

View file

@ -412,63 +412,44 @@ public class OkHttpJsonApiClient {
"<!--Created by Wikimedia Commons Android app -->\n" +
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" +
" <Document>";
List<PlaceBindings> placeBindings = runQuery(leftLatLng,
rightLatLng);
if (placeBindings != null) {
for (PlaceBindings item : placeBindings) {
if (item.getItem() != null && item.getLabel() != null && item.getClas() != null) {
String input = item.getLocation().getValue();
Pattern pattern = Pattern.compile(
"Point\\(([-+]?[0-9]*\\.?[0-9]+) ([-+]?[0-9]*\\.?[0-9]+)\\)");
Matcher matcher = pattern.matcher(input);
int increment = 1;
double longitude = leftLatLng.getLongitude();
if (matcher.find()) {
String longStr = matcher.group(1);
String latStr = matcher.group(2);
String itemUrl = item.getItem().getValue();
String itemName = item.getLabel().getValue().replace("&", "&amp;");
String itemLatitude = latStr;
String itemLongitude = longStr;
String itemClass = item.getClas().getValue();
while (longitude <= rightLatLng.getLongitude()) {
double NEXT_LONGITUDE =
(increment + longitude) >= 0.0 && (increment + longitude) <= 1.0 ? 0.0
: increment + longitude;
String formattedItemName =
!itemClass.isEmpty() ? itemName + " (" + itemClass + ")"
: itemName;
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) {
for (PlaceBindings item : placeBindings) {
if (item.getItem() != null && item.getLabel() != null && item.getClas() != null) {
String input = item.getLocation().getValue();
Pattern pattern = Pattern.compile(
"Point\\(([-+]?[0-9]*\\.?[0-9]+) ([-+]?[0-9]*\\.?[0-9]+)\\)");
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
String longStr = matcher.group(1);
String latStr = matcher.group(2);
String itemUrl = item.getItem().getValue();
String itemName = item.getLabel().getValue().replace("&", "&amp;");
String itemLatitude = latStr;
String itemLongitude = longStr;
String itemClass = item.getClas().getValue();
String formattedItemName =
!itemClass.isEmpty() ? itemName + " (" + itemClass + ")"
: itemName;
String kmlEntry = "\n <Placemark>\n" +
" <name>" + formattedItemName + "</name>\n" +
" <description>" + itemUrl + "</description>\n" +
" <Point>\n" +
" <coordinates>" + itemLongitude + ","
+ itemLatitude
+ "</coordinates>\n" +
" </Point>\n" +
" </Placemark>";
kmlString = kmlString + kmlEntry;
} else {
Timber.e("No match found");
}
}
String kmlEntry = "\n <Placemark>\n" +
" <name>" + formattedItemName + "</name>\n" +
" <description>" + itemUrl + "</description>\n" +
" <Point>\n" +
" <coordinates>" + itemLongitude + ","
+ itemLatitude
+ "</coordinates>\n" +
" </Point>\n" +
" </Placemark>";
kmlString = kmlString + kmlEntry;
} else {
Timber.e("No match found");
}
}
latitude += increment;
}
longitude += increment;
}
kmlString = kmlString + "\n </Document>\n" +
"</kml>\n";
@ -495,60 +476,42 @@ public class OkHttpJsonApiClient {
" 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\"/>";
int increment = 1;
double longitude = leftLatLng.getLongitude();
List<PlaceBindings> placeBindings = runQuery(leftLatLng,rightLatLng);
if (placeBindings != null) {
for (PlaceBindings item : placeBindings) {
if (item.getItem() != null && item.getLabel() != null && item.getClas() != null) {
String input = item.getLocation().getValue();
Pattern pattern = Pattern.compile(
"Point\\(([-+]?[0-9]*\\.?[0-9]+) ([-+]?[0-9]*\\.?[0-9]+)\\)");
Matcher matcher = pattern.matcher(input);
while (longitude <= rightLatLng.getLongitude()) {
double NEXT_LONGITUDE =
(increment + longitude) >= 0.0 && (increment + longitude) <= 1.0 ? 0.0
: increment + longitude;
if (matcher.find()) {
String longStr = matcher.group(1);
String latStr = matcher.group(2);
String itemUrl = item.getItem().getValue();
String itemName = item.getLabel().getValue().replace("&", "&amp;");
String itemLatitude = latStr;
String itemLongitude = longStr;
String itemClass = item.getClas().getValue();
double latitude = leftLatLng.getLatitude();
String formattedItemName =
!itemClass.isEmpty() ? itemName + " (" + itemClass + ")"
: itemName;
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) {
for (PlaceBindings item : placeBindings) {
if (item.getItem() != null && item.getLabel() != null && item.getClas() != null) {
String input = item.getLocation().getValue();
Pattern pattern = Pattern.compile(
"Point\\(([-+]?[0-9]*\\.?[0-9]+) ([-+]?[0-9]*\\.?[0-9]+)\\)");
Matcher matcher = pattern.matcher(input);
String gpxEntry =
"\n <wpt lat=\"" + itemLatitude + "\" lon=\"" + itemLongitude
+ "\">\n" +
" <name>" + itemName + "</name>\n" +
" <url>" + itemUrl + "</url>\n" +
" </wpt>";
gpxString = gpxString + gpxEntry;
if (matcher.find()) {
String longStr = matcher.group(1);
String latStr = matcher.group(2);
String itemUrl = item.getItem().getValue();
String itemName = item.getLabel().getValue().replace("&", "&amp;");
String itemLatitude = latStr;
String itemLongitude = longStr;
String itemClass = item.getClas().getValue();
String formattedItemName =
!itemClass.isEmpty() ? itemName + " (" + itemClass + ")"
: itemName;
String gpxEntry =
"\n <wpt lat=\"" + itemLatitude + "\" lon=\"" + itemLongitude
+ "\">\n" +
" <name>" + itemName + "</name>\n" +
" <url>" + itemUrl + "</url>\n" +
" </wpt>";
gpxString = gpxString + gpxEntry;
} else {
Timber.e("No match found");
}
}
} else {
Timber.e("No match found");
}
}
latitude += increment;
}
longitude += increment;
}
gpxString = gpxString + "\n</gpx>";
return gpxString;

View file

@ -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));
}
}

View file

@ -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())