Search in sources :

Example 26 with RotatedTileBox

use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.

the class MapContextMenuFragment method showOnMap.

private void showOnMap(LatLon latLon, boolean updateCoords, boolean needMove, boolean alreadyAdjusted) {
    // AnimateDraggingMapThread thread = map.getAnimatedDraggingThread(); todo amimation
    int fZoom = getZoom();
    double flat = latLon.getLatitude();
    double flon = latLon.getLongitude();
    RotatedTileBox cp = getBox();
    // cp.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
    cp.setLatLonCenter(flat, flon);
    cp.setZoom(fZoom);
    flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
    flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
    if (updateCoords) {
        mapCenter = new LatLon(flat, flon);
        menu.setMapCenter(mapCenter);
        origMarkerX = cp.getCenterPixelX();
        origMarkerY = cp.getCenterPixelY();
    }
    if (!alreadyAdjusted) {
        LatLon adjustedLatLon = getAdjustedMarkerLocation(getPosY(), new LatLon(flat, flon), true, fZoom);
        flat = adjustedLatLon.getLatitude();
        flon = adjustedLatLon.getLongitude();
    }
    if (needMove) {
        // thread.startMoving(flat, flon, fZoom, true); todo animation
        PointI targetI = Utilities.convertLatLonTo31(new net.osmand.core.jni.LatLon(flat, flon));
        getMainActivity().setTarget(targetI);
        getMainActivity().setZoom(fZoom);
    }
}
Also used : LatLon(net.osmand.data.LatLon) RotatedTileBox(net.osmand.data.RotatedTileBox) PointI(net.osmand.core.jni.PointI) QuadPoint(net.osmand.data.QuadPoint)

Example 27 with RotatedTileBox

use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.

the class MeasurementToolLayer method addCenterPoint.

public WptPt addCenterPoint() {
    RotatedTileBox tb = view.getCurrentRotatedTileBox();
    LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY());
    WptPt pt = new WptPt();
    pt.lat = l.getLatitude();
    pt.lon = l.getLongitude();
    boolean allowed = editingCtx.getPointsCount() == 0 || !editingCtx.getPoints().get(editingCtx.getPointsCount() - 1).equals(pt);
    if (allowed) {
        editingCtx.addPoint(pt);
        return pt;
    }
    return null;
}
Also used : LatLon(net.osmand.data.LatLon) WptPt(net.osmand.plus.GPXUtilities.WptPt) RotatedTileBox(net.osmand.data.RotatedTileBox)

Example 28 with RotatedTileBox

use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.

the class MapContextMenuFragment method calculateCenterLatLon.

private LatLon calculateCenterLatLon(LatLon latLon, int zoom, boolean updateOrigXY) {
    double flat = latLon.getLatitude();
    double flon = latLon.getLongitude();
    RotatedTileBox cp = map.getCurrentRotatedTileBox().copy();
    cp.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
    cp.setLatLonCenter(flat, flon);
    cp.setZoom(zoom);
    flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
    flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
    if (updateOrigXY) {
        origMarkerX = cp.getCenterPixelX();
        origMarkerY = cp.getCenterPixelY();
    }
    return new LatLon(flat, flon);
}
Also used : LatLon(net.osmand.data.LatLon) RotatedTileBox(net.osmand.data.RotatedTileBox)

Example 29 with RotatedTileBox

use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.

the class MapContextMenuFragment method setCustomMapRatio.

private void setCustomMapRatio() {
    LatLon latLon = menu.getLatLon();
    RotatedTileBox tb = map.getCurrentRotatedTileBox().copy();
    float px = tb.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
    float py = tb.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
    float ratioX = px / tb.getPixWidth();
    float ratioY = py / tb.getPixHeight();
    map.setCustomMapRatio(ratioX, ratioY);
    map.setLatLon(latLon.getLatitude(), latLon.getLongitude());
}
Also used : LatLon(net.osmand.data.LatLon) RotatedTileBox(net.osmand.data.RotatedTileBox)

Example 30 with RotatedTileBox

use of net.osmand.data.RotatedTileBox in project Osmand by osmandapp.

the class MapContextMenuFragment method getAdjustedMarkerLocation.

private LatLon getAdjustedMarkerLocation(int y, LatLon reqMarkerLocation, boolean center, int zoom) {
    double markerLat = reqMarkerLocation.getLatitude();
    double markerLon = reqMarkerLocation.getLongitude();
    RotatedTileBox box = map.getCurrentRotatedTileBox().copy();
    box.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
    box.setZoom(zoom);
    boolean hasMapCenter = mapCenter != null;
    int markerMapCenterX = 0;
    int markerMapCenterY = 0;
    if (hasMapCenter) {
        markerMapCenterX = (int) box.getPixXFromLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
        markerMapCenterY = (int) box.getPixYFromLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
    }
    float cpyOrig = box.getCenterPixelPoint().y;
    box.setCenterLocation(0.5f, 0.5f);
    int markerX = (int) box.getPixXFromLatLon(markerLat, markerLon);
    int markerY = (int) box.getPixYFromLatLon(markerLat, markerLon);
    QuadPoint cp = box.getCenterPixelPoint();
    float cpx = cp.x;
    float cpy = cp.y;
    float cpyDelta = menu.isLandscapeLayout() ? 0 : cpyOrig - cpy;
    markerY += cpyDelta;
    y += cpyDelta;
    float origMarkerY = this.origMarkerY + cpyDelta;
    LatLon latlon;
    if (center || !hasMapCenter) {
        latlon = reqMarkerLocation;
    } else {
        latlon = box.getLatLonFromPixel(markerMapCenterX, markerMapCenterY);
    }
    if (menu.isLandscapeLayout()) {
        int x = menu.getLandscapeWidthPx();
        if (markerX - markerPaddingXPx < x || markerX > origMarkerX) {
            int dx = (x + markerPaddingXPx) - markerX;
            int dy = 0;
            if (center) {
                dy = (int) cpy - markerY;
            } else {
                cpy = cpyOrig;
            }
            if (dx >= 0 || center) {
                latlon = box.getLatLonFromPixel(cpx - dx, cpy - dy);
            }
        }
    } else {
        if (markerY + markerPaddingPx > y || markerY < origMarkerY) {
            int dx = 0;
            int dy = markerY - (y - markerPaddingPx);
            if (markerY - dy <= origMarkerY) {
                if (center) {
                    dx = markerX - (int) cpx;
                }
                latlon = box.getLatLonFromPixel(cpx + dx, cpy + dy);
            }
        }
    }
    return latlon;
}
Also used : LatLon(net.osmand.data.LatLon) RotatedTileBox(net.osmand.data.RotatedTileBox) QuadPoint(net.osmand.data.QuadPoint) QuadPoint(net.osmand.data.QuadPoint)

Aggregations

RotatedTileBox (net.osmand.data.RotatedTileBox)48 LatLon (net.osmand.data.LatLon)20 QuadPoint (net.osmand.data.QuadPoint)15 Paint (android.graphics.Paint)11 QuadRect (net.osmand.data.QuadRect)8 SuppressLint (android.annotation.SuppressLint)7 View (android.view.View)6 ImageView (android.widget.ImageView)5 ArrayList (java.util.ArrayList)4 Location (net.osmand.Location)4 ITileSource (net.osmand.map.ITileSource)4 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)4 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)4 PointF (android.graphics.PointF)3 TextView (android.widget.TextView)3 List (java.util.List)3 QuadPointDouble (net.osmand.data.QuadPointDouble)3 WptPt (net.osmand.plus.GPXUtilities.WptPt)3 DialogInterface (android.content.DialogInterface)2 Bitmap (android.graphics.Bitmap)2