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;
}
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);
}
}
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);
}
}
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;
}
Aggregations