Search in sources :

Example 16 with BoundingBox

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);
            }
        }
    }
}
Also used : Rect(android.graphics.Rect) AlertDialogBuilder(de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) UiThread(android.support.annotation.UiThread)

Example 17 with BoundingBox

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;
}
Also used : Rect(android.graphics.Rect) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox)

Example 18 with BoundingBox

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");
    }
}
Also used : OsmNoteQuestType(de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestType) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) QuestType(de.westnordost.streetcomplete.data.QuestType) LatLon(de.westnordost.osmapi.map.data.LatLon) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox)

Example 19 with BoundingBox

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);
}
Also used : Rect(android.graphics.Rect) LngLat(com.mapzen.tangram.LngLat) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) Point(android.graphics.Point)

Example 20 with BoundingBox

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);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox)

Aggregations

BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)28 LatLon (de.westnordost.osmapi.map.data.LatLon)13 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)11 ArrayList (java.util.ArrayList)7 Rect (android.graphics.Rect)4 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)4 Point (android.graphics.Point)3 Note (de.westnordost.osmapi.notes.Note)3 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)3 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)3 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)3 Collection (java.util.Collection)3 List (java.util.List)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 OsmNode (de.westnordost.osmapi.map.data.OsmNode)2 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)2 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)2 Date (java.util.Date)2 Cursor (android.database.Cursor)1 PointF (android.graphics.PointF)1