Search in sources :

Example 36 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class MapControlsLayer method onNavigationClick.

private void onNavigationClick() {
    if (mapRouteInfoMenu != null) {
        mapRouteInfoMenu.cancelSelectionFromMap();
    }
    MapActivity.clearPrevActivityIntent();
    RoutingHelper routingHelper = mapActivity.getRoutingHelper();
    if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
        if (!hasTargets) {
            getTargets().restoreTargetPoints(false);
            if (getTargets().getPointToNavigate() == null) {
                mapActivity.getMapActions().setFirstMapMarkerAsTarget();
            }
        }
        TargetPoint start = getTargets().getPointToStart();
        if (start != null) {
            mapActivity.getMapActions().enterRoutePlanningMode(new LatLon(start.getLatitude(), start.getLongitude()), start.getOriginalPointDescription());
        } else {
            mapActivity.getMapActions().enterRoutePlanningMode(null, null);
        }
    } else {
        showRouteInfoControlDialog();
    }
    hasTargets = false;
}
Also used : LatLon(net.osmand.data.LatLon) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint)

Example 37 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class PointNavigationLayer method onDraw.

@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
    if (tb.getZoom() < 3) {
        return;
    }
    TargetPointsHelper targetPoints = map.getMyApplication().getTargetPointsHelper();
    TargetPoint pointToStart = targetPoints.getPointToStart();
    if (pointToStart != null) {
        if (isLocationVisible(tb, pointToStart)) {
            int marginX = mStartPoint.getWidth() / 6;
            int marginY = mStartPoint.getHeight();
            float locationX = getPointX(tb, pointToStart);
            float locationY = getPointY(tb, pointToStart);
            canvas.rotate(-tb.getRotate(), locationX, locationY);
            canvas.drawBitmap(mStartPoint, locationX - marginX, locationY - marginY, mBitmapPaint);
            canvas.rotate(tb.getRotate(), locationX, locationY);
        }
    }
    int index = 0;
    for (TargetPoint ip : targetPoints.getIntermediatePoints()) {
        index++;
        if (isLocationVisible(tb, ip)) {
            int marginX = mIntermediatePoint.getWidth() / 6;
            int marginY = mIntermediatePoint.getHeight();
            float locationX = getPointX(tb, ip);
            float locationY = getPointY(tb, ip);
            canvas.rotate(-tb.getRotate(), locationX, locationY);
            canvas.drawBitmap(mIntermediatePoint, locationX - marginX, locationY - marginY, mBitmapPaint);
            marginX = mIntermediatePoint.getWidth() / 3;
            canvas.drawText(index + "", locationX + marginX, locationY - 3 * marginY / 5, mTextPaint);
            canvas.rotate(tb.getRotate(), locationX, locationY);
        }
    }
    TargetPoint pointToNavigate = targetPoints.getPointToNavigate();
    if (isLocationVisible(tb, pointToNavigate)) {
        int marginX = mTargetPoint.getWidth() / 6;
        int marginY = mTargetPoint.getHeight();
        float locationX = getPointX(tb, pointToNavigate);
        float locationY = getPointY(tb, pointToNavigate);
        canvas.rotate(-tb.getRotate(), locationX, locationY);
        canvas.drawBitmap(mTargetPoint, locationX - marginX, locationY - marginY, mBitmapPaint);
        canvas.rotate(tb.getRotate(), locationX, locationY);
    }
}
Also used : TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint)

Example 38 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class PointNavigationLayer method applyNewObjectPosition.

@Override
public void applyNewObjectPosition(@NonNull Object o, @NonNull LatLon position, @Nullable ContextMenuLayer.ApplyMovedObjectCallback callback) {
    boolean result = false;
    TargetPoint newTargetPoint = null;
    if (o instanceof TargetPoint) {
        TargetPointsHelper targetPointsHelper = map.getMyApplication().getTargetPointsHelper();
        TargetPoint oldPoint = (TargetPoint) o;
        if (oldPoint.start) {
            targetPointsHelper.setStartPoint(position, true, null);
            newTargetPoint = targetPointsHelper.getPointToStart();
        } else if (oldPoint == targetPointsHelper.getPointToNavigate()) {
            targetPointsHelper.navigateToPoint(position, true, -1, null);
            newTargetPoint = targetPointsHelper.getPointToNavigate();
        } else if (oldPoint.intermediate) {
            List<TargetPoint> points = targetPointsHelper.getIntermediatePointsWithTarget();
            int i = points.indexOf(oldPoint);
            if (i != -1) {
                newTargetPoint = new TargetPoint(position, new PointDescription(PointDescription.POINT_TYPE_LOCATION, ""));
                points.set(i, newTargetPoint);
                targetPointsHelper.reorderAllTargetPoints(points, true);
            }
        }
        result = true;
    }
    if (callback != null) {
        callback.onApplyMovedObject(result, newTargetPoint == null ? o : newTargetPoint);
    }
}
Also used : PointDescription(net.osmand.data.PointDescription) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint)

Example 39 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class RouteInfoWidgetsFactory method createBearingControl.

public TextInfoWidget createBearingControl(final MapActivity map) {
    final int bearingResId = R.drawable.widget_bearing_day;
    final int bearingNightResId = R.drawable.widget_bearing_night;
    final int relativeBearingResId = R.drawable.widget_relative_bearing_day;
    final int relativeBearingNightResId = R.drawable.widget_relative_bearing_night;
    final OsmandApplication ctx = map.getMyApplication();
    final OsmandPreference<Boolean> showRelativeBearing = ctx.getSettings().SHOW_RELATIVE_BEARING_OTHERWISE_REGULAR_BEARING;
    final TextInfoWidget bearingControl = new TextInfoWidget(map) {

        private int cachedDegrees;

        private float MIN_SPEED_FOR_HEADING = 1f;

        public LatLon getPointToNavigate() {
            TargetPoint p = map.getPointToNavigate();
            return p == null ? null : p.point;
        }

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            boolean relative = showRelativeBearing.get();
            boolean modeChanged = setIcons(relative ? relativeBearingResId : bearingResId, relative ? relativeBearingNightResId : bearingNightResId);
            setContentTitle(relative ? R.string.map_widget_bearing : R.string.map_widget_magnetic_bearing);
            int b = getBearing(relative);
            if (degreesChanged(cachedDegrees, b) || modeChanged) {
                cachedDegrees = b;
                if (b != -1000) {
                    setText(String.valueOf(b) + "°" + (relative ? "" : " M"), null);
                } else {
                    setText(null, null);
                }
                return true;
            }
            return false;
        }

        public int getBearing(boolean relative) {
            int d = -1000;
            Location myLocation = getOsmandApplication().getLocationProvider().getLastKnownLocation();
            LatLon l = getPointToNavigate();
            if (l == null) {
                List<MapMarker> markers = getOsmandApplication().getMapMarkersHelper().getMapMarkers();
                if (markers.size() > 0) {
                    l = markers.get(0).point;
                }
            }
            if (myLocation != null && l != null) {
                Location dest = new Location("");
                dest.setLatitude(l.getLatitude());
                dest.setLongitude(l.getLongitude());
                dest.setBearing(myLocation.bearingTo(dest));
                GeomagneticField destGf = new GeomagneticField((float) dest.getLatitude(), (float) dest.getLongitude(), (float) dest.getAltitude(), System.currentTimeMillis());
                float bearingToDest = dest.getBearing() - destGf.getDeclination();
                if (relative) {
                    float b = -1000;
                    Float heading = getOsmandApplication().getLocationProvider().getHeading();
                    if ((myLocation.getSpeed() < MIN_SPEED_FOR_HEADING || !myLocation.hasBearing()) && heading != null) {
                        b = heading;
                    } else if (myLocation.hasBearing()) {
                        GeomagneticField myLocGf = new GeomagneticField((float) myLocation.getLatitude(), (float) myLocation.getLongitude(), (float) myLocation.getAltitude(), System.currentTimeMillis());
                        b = myLocation.getBearing() - myLocGf.getDeclination();
                    }
                    if (b > -1000) {
                        bearingToDest -= b;
                        if (bearingToDest > 180f) {
                            bearingToDest -= 360f;
                        } else if (bearingToDest < -180f) {
                            bearingToDest += 360f;
                        }
                        d = (int) bearingToDest;
                    }
                } else {
                    d = (int) bearingToDest;
                }
            }
            return d;
        }
    };
    bearingControl.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showRelativeBearing.set(!showRelativeBearing.get());
            map.refreshMap();
        }
    });
    bearingControl.setText(null, null);
    bearingControl.setIcons(!showRelativeBearing.get() ? bearingResId : relativeBearingResId, !showRelativeBearing.get() ? bearingNightResId : relativeBearingNightResId);
    return bearingControl;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) GeomagneticField(android.hardware.GeomagneticField) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings) LatLon(net.osmand.data.LatLon) Location(net.osmand.Location)

Aggregations

TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)39 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)18 LatLon (net.osmand.data.LatLon)17 View (android.view.View)13 TextView (android.widget.TextView)13 Location (net.osmand.Location)10 PointDescription (net.osmand.data.PointDescription)10 AdapterView (android.widget.AdapterView)9 ArrayList (java.util.ArrayList)9 ImageView (android.widget.ImageView)8 SuppressLint (android.annotation.SuppressLint)6 LocationPoint (net.osmand.data.LocationPoint)6 FavouritePoint (net.osmand.data.FavouritePoint)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 Paint (android.graphics.Paint)4 ImageButton (android.widget.ImageButton)4 ListView (android.widget.ListView)4 List (java.util.List)4 RoutingHelper (net.osmand.plus.routing.RoutingHelper)4 DialogInterface (android.content.DialogInterface)3