Search in sources :

Example 26 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class TargetPointsHelper method hasTooLongDistanceToNavigate.

public boolean hasTooLongDistanceToNavigate() {
    if (settings.ROUTER_SERVICE.getModeValue(routingHelper.getAppMode()) != RouteService.OSMAND) {
        return false;
    }
    Location current = routingHelper.getLastProjection();
    double dist = 400000;
    if (ApplicationMode.BICYCLE.isDerivedRoutingFrom(routingHelper.getAppMode()) && settings.getCustomRoutingBooleanProperty("height_obstacles", false).getModeValue(routingHelper.getAppMode())) {
        dist = 50000;
    }
    List<TargetPoint> list = getIntermediatePointsWithTarget();
    if (!list.isEmpty()) {
        if (current != null && MapUtils.getDistance(list.get(0).point, current.getLatitude(), current.getLongitude()) > dist) {
            return true;
        }
        for (int i = 1; i < list.size(); i++) {
            if (MapUtils.getDistance(list.get(i - 1).point, list.get(i).point) > dist) {
                return true;
            }
        }
    }
    return false;
}
Also used : SuppressLint(android.annotation.SuppressLint) LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location)

Example 27 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class MapMarkersLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
    Location myLoc;
    if (useFingerLocation && fingerLocation != null) {
        myLoc = new Location("");
        myLoc.setLatitude(fingerLocation.getLatitude());
        myLoc.setLongitude(fingerLocation.getLongitude());
    } else {
        myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
    }
    MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
    List<MapMarker> activeMapMarkers = markersHelper.getMapMarkers();
    int displayedWidgets = map.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get();
    if (route != null && route.points.size() > 0) {
        planRouteAttrs.updatePaints(view, nightMode, tileBox);
        route.renders.clear();
        route.renders.add(new Renderable.StandardTrack(new ArrayList<>(route.points), 17.2));
        route.drawRenderers(view.getZoom(), defaultAppMode ? planRouteAttrs.paint : planRouteAttrs.paint2, canvas, tileBox);
    }
    if (map.getMyApplication().getSettings().SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) {
        textAttrs.paint.setTextSize(textSize);
        textAttrs.paint2.setTextSize(textSize);
        lineAttrs.updatePaints(view, nightMode, tileBox);
        textAttrs.updatePaints(view, nightMode, tileBox);
        textAttrs.paint.setStyle(Paint.Style.FILL);
        boolean drawMarkerName = map.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 1;
        int locX;
        int locY;
        if (map.getMapViewTrackingUtilities().isMapLinkedToLocation() && !MapViewTrackingUtilities.isSmallSpeedForAnimation(myLoc) && !map.getMapViewTrackingUtilities().isMovingToMyLocation()) {
            locX = (int) tileBox.getPixXFromLatLon(tileBox.getLatitude(), tileBox.getLongitude());
            locY = (int) tileBox.getPixYFromLatLon(tileBox.getLatitude(), tileBox.getLongitude());
        } else {
            locX = (int) tileBox.getPixXFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
            locY = (int) tileBox.getPixYFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
        }
        int[] colors = MapMarker.getColors(map);
        for (int i = 0; i < activeMapMarkers.size() && i < displayedWidgets; i++) {
            MapMarker marker = activeMapMarkers.get(i);
            int markerX = (int) tileBox.getPixXFromLatLon(marker.getLatitude(), marker.getLongitude());
            int markerY = (int) tileBox.getPixYFromLatLon(marker.getLatitude(), marker.getLongitude());
            linePath.reset();
            tx.clear();
            ty.clear();
            tx.add(locX);
            ty.add(locY);
            tx.add(markerX);
            ty.add(markerY);
            calculatePath(tileBox, tx, ty, linePath);
            PathMeasure pm = new PathMeasure(linePath, false);
            float[] pos = new float[2];
            pm.getPosTan(pm.getLength() / 2, pos, null);
            float dist = (float) MapUtils.getDistance(myLoc.getLatitude(), myLoc.getLongitude(), marker.getLatitude(), marker.getLongitude());
            String distSt = OsmAndFormatter.getFormattedDistance(dist, view.getApplication());
            String text = distSt + (drawMarkerName ? " • " + marker.getName(map) : "");
            Rect bounds = new Rect();
            textAttrs.paint.getTextBounds(text, 0, text.length(), bounds);
            float hOffset = pm.getLength() / 2 - bounds.width() / 2;
            lineAttrs.paint.setColor(colors[marker.colorIndex]);
            canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
            canvas.drawPath(linePath, lineAttrs.paint);
            if (locX >= markerX) {
                canvas.rotate(180, pos[0], pos[1]);
                canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + verticalOffset, textAttrs.paint2);
                canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + verticalOffset, textAttrs.paint);
                canvas.rotate(-180, pos[0], pos[1]);
            } else {
                canvas.drawTextOnPath(text, linePath, hOffset, -verticalOffset, textAttrs.paint2);
                canvas.drawTextOnPath(text, linePath, hOffset, -verticalOffset, textAttrs.paint);
            }
            canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
        }
    }
}
Also used : Rect(android.graphics.Rect) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) PathMeasure(android.graphics.PathMeasure) Location(net.osmand.Location)

Example 28 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class PointLocationLayer method onDraw.

@Override
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) {
    if (box.getZoom() < 3) {
        return;
    }
    // draw
    boolean nm = nightMode != null && nightMode.isNightMode();
    Location lastKnownLocation = locationProvider.getLastStaleKnownLocation();
    updateIcons(view.getSettings().getApplicationMode(), nm, view.getApplication().getLocationProvider().getLastKnownLocation() == null);
    if (lastKnownLocation == null || view == null) {
        return;
    }
    int locationX;
    int locationY;
    if (mapViewTrackingUtilities.isMapLinkedToLocation() && !MapViewTrackingUtilities.isSmallSpeedForAnimation(lastKnownLocation) && !mapViewTrackingUtilities.isMovingToMyLocation()) {
        locationX = box.getPixXFromLonNoRot(box.getLongitude());
        locationY = box.getPixYFromLatNoRot(box.getLatitude());
    } else {
        locationX = box.getPixXFromLonNoRot(lastKnownLocation.getLongitude());
        locationY = box.getPixYFromLatNoRot(lastKnownLocation.getLatitude());
    }
    final double dist = box.getDistance(0, box.getPixHeight() / 2, box.getPixWidth(), box.getPixHeight() / 2);
    int radius = (int) (((double) box.getPixWidth()) / dist * lastKnownLocation.getAccuracy());
    if (radius > RADIUS * box.getDensity()) {
        int allowedRad = Math.min(box.getPixWidth() / 2, box.getPixHeight() / 2);
        canvas.drawCircle(locationX, locationY, Math.min(radius, allowedRad), area);
        canvas.drawCircle(locationX, locationY, Math.min(radius, allowedRad), aroundArea);
    }
    // draw bearing/direction/location
    if (isLocationVisible(box, lastKnownLocation)) {
        Float heading = locationProvider.getHeading();
        if (!locationOutdated && heading != null && mapViewTrackingUtilities.isShowViewAngle()) {
            canvas.save();
            canvas.rotate(heading - 180, locationX, locationY);
            canvas.drawBitmap(headingIcon, locationX - headingIcon.getWidth() / 2, locationY - headingIcon.getHeight() / 2, locationPaint);
            canvas.restore();
        }
        boolean isBearing = lastKnownLocation.hasBearing();
        if (!locationOutdated && isBearing) {
            float bearing = lastKnownLocation.getBearing();
            canvas.rotate(bearing - 90, locationX, locationY);
            canvas.drawBitmap(bearingIcon, locationX - bearingIcon.getWidth() / 2, locationY - bearingIcon.getHeight() / 2, locationPaint);
        } else {
            canvas.drawBitmap(locationIcon, locationX - locationIcon.getWidth() / 2, locationY - locationIcon.getHeight() / 2, locationPaint);
        }
    }
}
Also used : Paint(android.graphics.Paint) Location(net.osmand.Location)

Example 29 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RouteLayer method drawLocations.

public void drawLocations(RotatedTileBox tb, Canvas canvas, double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
    RouteCalculationResult route = helper.getRoute();
    routeGeometry.updateRoute(tb, route);
    routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, helper.getLastProjection(), route == null ? 0 : route.getCurrentRoute());
    List<RouteDirectionInfo> rd = helper.getRouteDirections();
    Iterator<RouteDirectionInfo> it = rd.iterator();
    if (tb.getZoom() >= 14) {
        List<Location> actionPoints = calculateActionPoints(topLatitude, leftLongitude, bottomLatitude, rightLongitude, helper.getLastProjection(), helper.getRoute().getRouteLocations(), helper.getRoute().getCurrentRoute(), it, tb.getZoom());
        drawAction(tb, canvas, actionPoints);
    }
}
Also used : RouteCalculationResult(net.osmand.plus.routing.RouteCalculationResult) RouteDirectionInfo(net.osmand.plus.routing.RouteDirectionInfo) Location(net.osmand.Location)

Example 30 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RouteLayer method calculateProjection.

private Location calculateProjection(double part, Location lp, Location l) {
    Location p = new Location(l);
    p.setLatitude(lp.getLatitude() + part * (l.getLatitude() - lp.getLatitude()));
    p.setLongitude(lp.getLongitude() + part * (l.getLongitude() - lp.getLongitude()));
    return p;
}
Also used : Location(net.osmand.Location)

Aggregations

Location (net.osmand.Location)105 LatLon (net.osmand.data.LatLon)37 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)29 ArrayList (java.util.ArrayList)21 LocationPoint (net.osmand.data.LocationPoint)21 View (android.view.View)13 OsmandApplication (net.osmand.plus.OsmandApplication)12 Paint (android.graphics.Paint)11 TextView (android.widget.TextView)11 ImageView (android.widget.ImageView)10 RouteDataObject (net.osmand.binary.RouteDataObject)9 WptPt (net.osmand.plus.GPXUtilities.WptPt)9 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)7 PointDescription (net.osmand.data.PointDescription)6 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 IOException (java.io.IOException)5 QuadPoint (net.osmand.data.QuadPoint)5 MapActivity (net.osmand.plus.activities.MapActivity)5