use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.
the class MainActivity method downloadDisplayedArea.
@UiThread
private void downloadDisplayedArea() {
BoundingBox displayArea;
if ((displayArea = mapFragment.getDisplayedArea(new Rect())) == null) {
Toast.makeText(this, R.string.cannot_find_bbox_or_reduce_tilt, Toast.LENGTH_LONG).show();
} else {
final BoundingBox enclosingBBox = SlippyMapMath.asBoundingBoxOfEnclosingTiles(displayArea, ApplicationConstants.QUEST_TILE_ZOOM);
double areaInSqKm = SphericalEarthMath.enclosedArea(enclosingBBox) / 1000000;
if (areaInSqKm > ApplicationConstants.MAX_DOWNLOADABLE_AREA_IN_SQKM) {
Toast.makeText(this, R.string.download_area_too_big, Toast.LENGTH_LONG).show();
} else {
if (questController.isPriorityDownloadRunning()) {
new AlertDialogBuilder(this).setMessage(R.string.confirmation_cancel_prev_download_title).setPositiveButton(android.R.string.ok, (dialog, which) -> downloadAreaConfirmed(enclosingBBox)).setNegativeButton(android.R.string.cancel, null).show();
} else {
downloadAreaConfirmed(enclosingBBox);
}
}
}
}
use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.
the class AActiveRadiusStrategy method mayDownloadHere.
private boolean mayDownloadHere(LatLon pos, int radius, int numberOfQuestTypes) {
BoundingBox bbox = SphericalEarthMath.enclosingBoundingBox(pos, radius);
double areaInKm2 = SphericalEarthMath.enclosedArea(bbox) / 1000 / 1000;
// got enough quests in vicinity
int visibleQuests = osmQuestDB.getCount(bbox, QuestStatus.NEW);
if (visibleQuests / areaInKm2 > getMinQuestsInActiveRadiusPerKm2()) {
Log.i(TAG, "Not downloading quests because there are enough quests in " + radius + "m radius");
return false;
}
// (this check is more computational effort, so its done after the vicinity check)
// nothing more to download
Rect tiles = SlippyMapMath.enclosingTiles(bbox, ApplicationConstants.QUEST_TILE_ZOOM);
long questExpirationTime = ApplicationConstants.REFRESH_QUESTS_AFTER;
long ignoreOlderThan = Math.max(0, System.currentTimeMillis() - questExpirationTime);
int alreadyDownloadedQuestTypes = downloadedTilesDao.get(tiles, ignoreOlderThan).size();
if (alreadyDownloadedQuestTypes >= numberOfQuestTypes) {
Log.i(TAG, "Not downloading quests because everything has been downloaded already in " + radius + "m radius");
return false;
}
return true;
}
use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.
the class QuestDownload method download.
public void download() {
if (cancelState.get())
return;
List<QuestType> questTypes = getQuestTypesToDownload();
if (questTypes.isEmpty()) {
finished = true;
progressListener.onNotStarted();
return;
}
totalQuestTypes = questTypes.size();
BoundingBox bbox = SlippyMapMath.asBoundingBox(tiles, ApplicationConstants.QUEST_TILE_ZOOM);
try {
Log.i(TAG, "(" + bbox.getAsLeftBottomRightTopString() + ") Starting");
progressListener.onStarted();
Set<LatLon> notesPositions;
if (questTypes.contains(getOsmNoteQuestType())) {
notesPositions = downloadNotes(bbox);
} else {
notesPositions = getNotePositionsFromDb(bbox);
}
downloadQuestTypes(bbox, questTypes, notesPositions);
progressListener.onSuccess();
} finally {
finished = true;
progressListener.onFinished();
Log.i(TAG, "(" + bbox.getAsLeftBottomRightTopString() + ") Finished");
}
}
use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.
the class QuestsMapFragment method updateView.
protected void updateView() {
super.updateView();
if (controller.getZoom() < TILES_ZOOM)
return;
// check if anything changed (needs to be extended when I reenable tilt and rotation)
LngLat positionNow = controller.getPosition();
if (lastPos != null && lastPos.equals(positionNow))
return;
lastPos = positionNow;
BoundingBox displayedArea = getDisplayedArea(new Rect());
if (displayedArea == null)
return;
Rect tilesRect = SlippyMapMath.enclosingTiles(displayedArea, TILES_ZOOM);
if (lastDisplayedRect != null && lastDisplayedRect.equals(tilesRect))
return;
lastDisplayedRect = tilesRect;
// area to big -> skip ( see https://github.com/tangrams/tangram-es/issues/1492 )
if (tilesRect.width() * tilesRect.height() > 4) {
return;
}
List<Point> tiles = SlippyMapMath.asTileList(tilesRect);
tiles.removeAll(retrievedTiles);
Rect minRect = SlippyMapMath.minRect(tiles);
if (minRect == null)
return;
BoundingBox bbox = SlippyMapMath.asBoundingBox(minRect, TILES_ZOOM);
listener.onFirstInView(bbox);
// debugging
/*List<LatLon> corners = new ArrayList<LatLon>(5);
corners.add(bbox.getMin());
corners.add(new OsmLatLon(bbox.getMinLatitude(), bbox.getMaxLongitude()));
corners.add(bbox.getMax());
corners.add(new OsmLatLon(bbox.getMaxLatitude(), bbox.getMinLongitude()));
corners.add(bbox.getMin());
ElementGeometry e = new ElementGeometry(null, Collections.singletonList(corners));
addQuestGeometry(e);*/
retrievedTiles.addAll(tiles);
}
use of de.westnordost.osmapi.map.data.BoundingBox in project StreetComplete by westnordost.
the class SphericalEarthMath method enclosingBoundingBox.
/**
* Calculate a bounding box that contains the given positions.
*/
public static BoundingBox enclosingBoundingBox(List<LatLon> positions) {
Double minLat = null, minLon = null, maxLat = null, maxLon = null;
for (LatLon pos : positions) {
double lat = pos.getLatitude();
double lon = pos.getLongitude();
if (minLat == null || lat < minLat)
minLat = lat;
if (minLon == null || lon < minLon)
minLon = lon;
if (maxLat == null || lat > maxLat)
maxLat = lat;
if (maxLon == null || lon > maxLon)
maxLon = lon;
}
return new BoundingBox(minLat, minLon, maxLat, maxLon);
}
Aggregations