Search in sources :

Example 36 with MapMarker

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);
    }
}
Also used : LatLon(net.osmand.data.LatLon) Bitmap(android.graphics.Bitmap) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) QuadPoint(net.osmand.data.QuadPoint) PointF(android.graphics.PointF) OsmandSettings(net.osmand.plus.OsmandSettings) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint)

Example 37 with MapMarker

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);
    }
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) PointDescription(net.osmand.data.PointDescription) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint)

Example 38 with MapMarker

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

MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)38 LatLon (net.osmand.data.LatLon)20 View (android.view.View)13 MapMarkersHelper (net.osmand.plus.MapMarkersHelper)11 RecyclerView (android.support.v7.widget.RecyclerView)10 OsmandApplication (net.osmand.plus.OsmandApplication)10 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)9 ImageView (android.widget.ImageView)8 Location (net.osmand.Location)8 PointDescription (net.osmand.data.PointDescription)8 Paint (android.graphics.Paint)7 Nullable (android.support.annotation.Nullable)6 MapActivity (net.osmand.plus.activities.MapActivity)6 ArrayList (java.util.ArrayList)5 Amenity (net.osmand.data.Amenity)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)4 FavouritePoint (net.osmand.data.FavouritePoint)4 QuadPoint (net.osmand.data.QuadPoint)4 Bitmap (android.graphics.Bitmap)3