mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-01 07:13:56 +01:00
PlacesRepository: Add methods for fetching places in map bounds
This commit is contained in:
parent
ecaa296918
commit
7b154c3dc1
3 changed files with 69 additions and 7 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import io.reactivex.Completable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
|
@ -27,9 +29,71 @@ public class PlacesLocalDataSource {
|
|||
return placeDao.getPlace(entityID);
|
||||
}
|
||||
|
||||
public List<Place> fetchPlaces(final double latBegin, final double lngBegin,
|
||||
final double latEnd, final double lngEnd) {
|
||||
return placeDao.fetchPlaces(latBegin, lngBegin, latEnd, lngEnd);
|
||||
public List<Place> fetchPlaces(final LatLng mapTopRight, final LatLng mapBottomLeft) {
|
||||
class Constraint {
|
||||
|
||||
final double latBegin;
|
||||
final double lngBegin;
|
||||
final double latEnd;
|
||||
final double lngEnd;
|
||||
|
||||
public Constraint(final double latBegin, final double lngBegin, final double latEnd,
|
||||
final double lngEnd) {
|
||||
this.latBegin = latBegin;
|
||||
this.lngBegin = lngBegin;
|
||||
this.latEnd = latEnd;
|
||||
this.lngEnd = lngEnd;
|
||||
}
|
||||
}
|
||||
|
||||
final List<Constraint> constraints = new ArrayList<>();
|
||||
|
||||
if (mapTopRight.getLatitude() < mapBottomLeft.getLatitude()) {
|
||||
if (mapTopRight.getLongitude() < mapBottomLeft.getLongitude()) {
|
||||
constraints.add(
|
||||
new Constraint(mapBottomLeft.getLatitude(), mapBottomLeft.getLongitude(), 90.0,
|
||||
180.0));
|
||||
constraints.add(new Constraint(mapBottomLeft.getLatitude(), -180.0, 90.0,
|
||||
mapTopRight.getLongitude()));
|
||||
constraints.add(
|
||||
new Constraint(-90.0, mapBottomLeft.getLongitude(), mapTopRight.getLatitude(),
|
||||
180.0));
|
||||
constraints.add(new Constraint(-90.0, -180.0, mapTopRight.getLatitude(),
|
||||
mapTopRight.getLongitude()));
|
||||
} else {
|
||||
constraints.add(
|
||||
new Constraint(mapBottomLeft.getLatitude(), mapBottomLeft.getLongitude(), 90.0,
|
||||
mapTopRight.getLongitude()));
|
||||
constraints.add(
|
||||
new Constraint(-90.0, mapBottomLeft.getLongitude(), mapTopRight.getLatitude(),
|
||||
mapTopRight.getLongitude()));
|
||||
}
|
||||
} else {
|
||||
if (mapTopRight.getLongitude() < mapBottomLeft.getLongitude()) {
|
||||
constraints.add(
|
||||
new Constraint(mapBottomLeft.getLatitude(), mapBottomLeft.getLongitude(),
|
||||
mapTopRight.getLatitude(), 180.0));
|
||||
constraints.add(
|
||||
new Constraint(mapBottomLeft.getLatitude(), -180.0, mapTopRight.getLatitude(),
|
||||
mapTopRight.getLongitude()));
|
||||
} else {
|
||||
constraints.add(
|
||||
new Constraint(mapBottomLeft.getLatitude(), mapBottomLeft.getLongitude(),
|
||||
mapTopRight.getLatitude(), mapTopRight.getLongitude()));
|
||||
}
|
||||
}
|
||||
|
||||
final List<Place> cachedPlaces = new ArrayList<>();
|
||||
for (final Constraint constraint : constraints) {
|
||||
cachedPlaces.addAll(placeDao.fetchPlaces(
|
||||
constraint.latBegin,
|
||||
constraint.lngBegin,
|
||||
constraint.latEnd,
|
||||
constraint.lngEnd
|
||||
));
|
||||
}
|
||||
|
||||
return cachedPlaces;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -40,9 +40,8 @@ public class PlacesRepository {
|
|||
return localDataSource.fetchPlace(entityID);
|
||||
}
|
||||
|
||||
public List<Place> fetchPlaces(final double latBegin, final double lngBegin,
|
||||
final double latEnd, final double lngEnd) {
|
||||
return localDataSource.fetchPlaces(latBegin, lngBegin, latEnd, lngEnd);
|
||||
public List<Place> fetchPlaces(final LatLng mapBottomLeft, final LatLng mapTopRight) {
|
||||
return localDataSource.fetchPlaces(mapBottomLeft, mapTopRight);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import android.location.Location
|
|||
import android.view.View
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import fr.free.nrw.commons.BaseMarker
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.location.LatLng
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue