use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.
the class MapMarkersLayer method onDraw.
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tileBox.getZoom());
OsmandSettings settings = map.getMyApplication().getSettings();
if (tileBox.getZoom() < 3) {
return;
}
int displayedWidgets = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get();
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
for (MapMarker marker : markersHelper.getMapMarkers()) {
if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker) && !isInMotion(marker) && !isSynced(marker)) {
Bitmap bmp = getMapMarkerBitmap(marker.colorIndex);
int marginX = bmp.getWidth() / 6;
int marginY = bmp.getHeight();
int locationX = tileBox.getPixXFromLonNoRot(marker.getLongitude());
int locationY = tileBox.getPixYFromLatNoRot(marker.getLatitude());
canvas.rotate(-tileBox.getRotate(), locationX, locationY);
canvas.drawBitmap(bmp, locationX - marginX, locationY - marginY, bitmapPaint);
canvas.rotate(tileBox.getRotate(), locationX, locationY);
}
}
if (settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()) {
LatLon loc = tileBox.getCenterLatLon();
int i = 0;
for (MapMarker marker : markersHelper.getMapMarkers()) {
if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) {
canvas.save();
net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(), marker.getLatitude(), marker.getLongitude(), calculations);
float bearing = calculations[1] - 90;
float radiusBearing = DIST_TO_SHOW * tileBox.getDensity();
final QuadPoint cp = tileBox.getCenterPixelPoint();
canvas.rotate(bearing, cp.x, cp.y);
canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity());
canvas.drawBitmap(arrowShadow, cp.x, cp.y, bitmapPaint);
canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex));
canvas.drawBitmap(arrowLight, cp.x, cp.y, bitmapPaint);
canvas.restore();
}
i++;
if (i > displayedWidgets - 1) {
break;
}
}
}
if (contextMenuLayer.getMoveableObject() instanceof MapMarker) {
MapMarker objectInMotion = (MapMarker) contextMenuLayer.getMoveableObject();
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
Bitmap bitmap = getMapMarkerBitmap(objectInMotion.colorIndex);
int marginX = bitmap.getWidth() / 6;
int marginY = bitmap.getHeight();
float locationX = pf.x;
float locationY = pf.y;
canvas.rotate(-tileBox.getRotate(), locationX, locationY);
canvas.drawBitmap(bitmap, locationX - marginX, locationY - marginY, bitmapPaint);
}
}
use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.
the class MapMarkersLayer method applyNewObjectPosition.
@Override
public void applyNewObjectPosition(@NonNull Object o, @NonNull LatLon position, @Nullable ApplyMovedObjectCallback callback) {
boolean result = false;
MapMarker newObject = null;
if (o instanceof MapMarker) {
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
MapMarker marker = (MapMarker) o;
PointDescription originalDescription = marker.getOriginalPointDescription();
if (originalDescription.isLocation()) {
originalDescription.setName(PointDescription.getSearchAddressStr(map));
}
markersHelper.moveMapMarker(marker, position);
int index = markersHelper.getMapMarkers().indexOf(marker);
if (index != -1) {
newObject = markersHelper.getMapMarkers().get(index);
}
result = true;
}
if (callback != null) {
callback.onApplyMovedObject(result, newObject == null ? o : newObject);
}
}
use of net.osmand.plus.MapMarkersHelper.MapMarker 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