Search in sources :

Example 6 with QuadPoint

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

the class RoutePlannerFrontEnd method projectDistance.

protected double projectDistance(List<RouteSegmentResult> res, int k, int px, int py) {
    RouteSegmentResult sr = res.get(k);
    RouteDataObject r = sr.getObject();
    QuadPoint pp = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(sr.getStartPointIndex()), r.getPoint31YTile(sr.getStartPointIndex()), r.getPoint31XTile(sr.getEndPointIndex()), r.getPoint31YTile(sr.getEndPointIndex()));
    double currentsDist = squareDist((int) pp.x, (int) pp.y, px, py);
    return currentsDist;
}
Also used : QuadPoint(net.osmand.data.QuadPoint) RouteDataObject(net.osmand.binary.RouteDataObject)

Example 7 with QuadPoint

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

the class RoutePlannerFrontEnd method updateResult.

private void updateResult(RouteSegmentResult routeSegmentResult, LatLon point, boolean st) {
    int px = MapUtils.get31TileNumberX(point.getLongitude());
    int py = MapUtils.get31TileNumberY(point.getLatitude());
    int pind = st ? routeSegmentResult.getStartPointIndex() : routeSegmentResult.getEndPointIndex();
    RouteDataObject r = routeSegmentResult.getObject();
    QuadPoint before = null;
    QuadPoint after = null;
    if (pind > 0) {
        before = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(pind - 1), r.getPoint31YTile(pind - 1), r.getPoint31XTile(pind), r.getPoint31YTile(pind));
    }
    if (pind < r.getPointsLength() - 1) {
        after = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(pind + 1), r.getPoint31YTile(pind + 1), r.getPoint31XTile(pind), r.getPoint31YTile(pind));
    }
    int insert = 0;
    double dd = MapUtils.getDistance(point, MapUtils.get31LatitudeY(r.getPoint31YTile(pind)), MapUtils.get31LongitudeX(r.getPoint31XTile(pind)));
    double ddBefore = Double.POSITIVE_INFINITY;
    double ddAfter = Double.POSITIVE_INFINITY;
    QuadPoint i = null;
    if (before != null) {
        ddBefore = MapUtils.getDistance(point, MapUtils.get31LatitudeY((int) before.y), MapUtils.get31LongitudeX((int) before.x));
        if (ddBefore < dd) {
            insert = -1;
            i = before;
        }
    }
    if (after != null) {
        ddAfter = MapUtils.getDistance(point, MapUtils.get31LatitudeY((int) after.y), MapUtils.get31LongitudeX((int) after.x));
        if (ddAfter < dd && ddAfter < ddBefore) {
            insert = 1;
            i = after;
        }
    }
    if (insert != 0) {
        if (st && routeSegmentResult.getStartPointIndex() < routeSegmentResult.getEndPointIndex()) {
            routeSegmentResult.setEndPointIndex(routeSegmentResult.getEndPointIndex() + 1);
        }
        if (!st && routeSegmentResult.getStartPointIndex() > routeSegmentResult.getEndPointIndex()) {
            routeSegmentResult.setStartPointIndex(routeSegmentResult.getStartPointIndex() + 1);
        }
        if (insert > 0) {
            r.insert(pind + 1, (int) i.x, (int) i.y);
            if (st) {
                routeSegmentResult.setStartPointIndex(routeSegmentResult.getStartPointIndex() + 1);
            }
            if (!st) {
                routeSegmentResult.setEndPointIndex(routeSegmentResult.getEndPointIndex() + 1);
            }
        } else {
            r.insert(pind, (int) i.x, (int) i.y);
        }
    }
}
Also used : QuadPoint(net.osmand.data.QuadPoint) RouteDataObject(net.osmand.binary.RouteDataObject) RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint) QuadPoint(net.osmand.data.QuadPoint)

Example 8 with QuadPoint

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

the class RoutePlannerFrontEnd method findRouteSegment.

public RouteSegmentPoint findRouteSegment(double lat, double lon, RoutingContext ctx, List<RouteSegmentPoint> list) throws IOException {
    int px = MapUtils.get31TileNumberX(lon);
    int py = MapUtils.get31TileNumberY(lat);
    ArrayList<RouteDataObject> dataObjects = new ArrayList<RouteDataObject>();
    ctx.loadTileData(px, py, 17, dataObjects);
    if (dataObjects.isEmpty()) {
        ctx.loadTileData(px, py, 15, dataObjects);
    }
    if (list == null) {
        list = new ArrayList<BinaryRoutePlanner.RouteSegmentPoint>();
    }
    for (RouteDataObject r : dataObjects) {
        if (r.getPointsLength() > 1) {
            RouteSegmentPoint road = null;
            for (int j = 1; j < r.getPointsLength(); j++) {
                QuadPoint pr = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(j - 1), r.getPoint31YTile(j - 1), r.getPoint31XTile(j), r.getPoint31YTile(j));
                double currentsDistSquare = squareDist((int) pr.x, (int) pr.y, px, py);
                if (road == null || currentsDistSquare < road.distSquare) {
                    RouteDataObject ro = new RouteDataObject(r);
                    road = new RouteSegmentPoint(ro, j, currentsDistSquare);
                    road.preciseX = (int) pr.x;
                    road.preciseY = (int) pr.y;
                }
            }
            if (road != null) {
                list.add(road);
            }
        }
    }
    Collections.sort(list, new Comparator<RouteSegmentPoint>() {

        @Override
        public int compare(RouteSegmentPoint o1, RouteSegmentPoint o2) {
            return Double.compare(o1.distSquare, o2.distSquare);
        }
    });
    if (list.size() > 0) {
        RouteSegmentPoint ps = list.get(0);
        ps.others = list;
        return ps;
    }
    return null;
}
Also used : RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint) QuadPoint(net.osmand.data.QuadPoint) ArrayList(java.util.ArrayList) RouteDataObject(net.osmand.binary.RouteDataObject) RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint) QuadPoint(net.osmand.data.QuadPoint)

Example 9 with QuadPoint

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

the class MapUtils method getProjectionPoint31.

public static QuadPoint getProjectionPoint31(int px, int py, int st31x, int st31y, int end31x, int end31y) {
    double projection = calculateProjection31TileMetric(st31x, st31y, end31x, end31y, px, py);
    double mDist = measuredDist31(end31x, end31y, st31x, st31y);
    int pry = end31y;
    int prx = end31x;
    if (projection < 0) {
        prx = st31x;
        pry = st31y;
    } else if (projection >= mDist * mDist) {
        prx = end31x;
        pry = end31y;
    } else {
        prx = (int) (st31x + (end31x - st31x) * (projection / (mDist * mDist)));
        pry = (int) (st31y + (end31y - st31y) * (projection / (mDist * mDist)));
    }
    return new QuadPoint(prx, pry);
}
Also used : QuadPoint(net.osmand.data.QuadPoint) GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint) QuadPoint(net.osmand.data.QuadPoint)

Example 10 with QuadPoint

use of net.osmand.data.QuadPoint 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 = getBox();
    // box.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
    box.setZoom(zoom);
    int markerMapCenterX = (int) box.getPixXFromLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
    int 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) {
        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

QuadPoint (net.osmand.data.QuadPoint)14 Paint (android.graphics.Paint)5 LatLon (net.osmand.data.LatLon)5 RouteDataObject (net.osmand.binary.RouteDataObject)3 RotatedTileBox (net.osmand.data.RotatedTileBox)3 SuppressLint (android.annotation.SuppressLint)2 Bitmap (android.graphics.Bitmap)2 PointF (android.graphics.PointF)2 RouteSegmentPoint (net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint)2 Canvas (android.graphics.Canvas)1 Handler (android.os.Handler)1 Message (android.os.Message)1 ArrayList (java.util.ArrayList)1 Location (net.osmand.Location)1 MapMarkersHelper (net.osmand.plus.MapMarkersHelper)1 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)1 OsmandSettings (net.osmand.plus.OsmandSettings)1 RulerMode (net.osmand.plus.OsmandSettings.RulerMode)1 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)1 GeoParsedPoint (net.osmand.util.GeoPointParserUtil.GeoParsedPoint)1