Search in sources :

Example 6 with LngLat

use of com.mapzen.tangram.LngLat in project StreetComplete by westnordost.

the class TangramConst method toLatLon.

public static List<List<LatLon>> toLatLon(List<List<LngLat>> positionLists) {
    List<List<LatLon>> result = new ArrayList<>(positionLists.size());
    for (List<LngLat> positions : positionLists) {
        List<LatLon> resultPositions = new ArrayList<>(positions.size());
        for (LngLat pos : positions) {
            resultPositions.add(toLatLon(pos));
        }
        result.add(resultPositions);
    }
    return result;
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) LngLat(com.mapzen.tangram.LngLat) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with LngLat

use of com.mapzen.tangram.LngLat in project StreetComplete by westnordost.

the class MapFragment method updateAccuracy.

private void updateAccuracy() {
    if (accuracyMarker != null && lastLocation != null && accuracyMarker.isVisible()) {
        LngLat pos = new LngLat(lastLocation.getLongitude(), lastLocation.getLatitude());
        float size = meters2Pixels(pos, lastLocation.getAccuracy());
        accuracyMarker.setStylingFromString("{ style: 'points', color: 'white', size: [" + size + "px, " + size + "px], order: 2000, flat: true, collide: false }");
    }
}
Also used : LngLat(com.mapzen.tangram.LngLat)

Example 8 with LngLat

use of com.mapzen.tangram.LngLat in project StreetComplete by westnordost.

the class QuestsMapFragment method zoomAndMoveToContain.

private void zoomAndMoveToContain(ElementGeometry g) {
    // never zoom back further than 17.5
    previousZoom = Math.max(17.5f, controller.getZoom());
    float targetZoom = getMaxZoomThatContains(g);
    if (Float.isNaN(targetZoom) || targetZoom > MAX_QUEST_ZOOM) {
        targetZoom = MAX_QUEST_ZOOM;
    } else {
        // zoom out a bit
        targetZoom -= 0.4;
    }
    float currentZoom = controller.getZoom();
    controller.setZoom(targetZoom);
    LngLat pos = getCenterWithOffset(g);
    controller.setZoom(currentZoom);
    controller.setPositionEased(pos, 500);
    controller.setZoomEased(targetZoom, 500);
    updateView();
}
Also used : LngLat(com.mapzen.tangram.LngLat)

Example 9 with LngLat

use of com.mapzen.tangram.LngLat in project StreetComplete by westnordost.

the class QuestsMapFragment method getCenterWithOffset.

private LngLat getCenterWithOffset(ElementGeometry geometry) {
    int w = getView().getWidth();
    int h = getView().getHeight();
    LngLat normalCenter = controller.screenPositionToLngLat(new PointF(w / 2f, h / 2f));
    LngLat offsetCenter = controller.screenPositionToLngLat(new PointF(questOffset.left + (w - questOffset.left - questOffset.right) / 2, questOffset.top + (h - questOffset.top - questOffset.bottom) / 2));
    LngLat pos = TangramConst.toLngLat(geometry.center);
    pos.latitude -= offsetCenter.latitude - normalCenter.latitude;
    pos.longitude -= offsetCenter.longitude - normalCenter.longitude;
    return pos;
}
Also used : LngLat(com.mapzen.tangram.LngLat) PointF(android.graphics.PointF) Point(android.graphics.Point)

Example 10 with LngLat

use of com.mapzen.tangram.LngLat 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)

Aggregations

LngLat (com.mapzen.tangram.LngLat)11 SharedPreferences (android.content.SharedPreferences)2 Point (android.graphics.Point)2 PointF (android.graphics.PointF)2 LatLon (de.westnordost.osmapi.map.data.LatLon)2 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Rect (android.graphics.Rect)1 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)1