Search in sources :

Example 1 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker 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 2 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class MapMarkersLayer method collectObjectsFromPoint.

@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
    if (tileBox.getZoom() < 3) {
        return;
    }
    amenities.clear();
    OsmandApplication app = map.getMyApplication();
    int r = getDefaultRadiusPoi(tileBox);
    boolean selectMarkerOnSingleTap = app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get();
    for (MapMarker marker : app.getMapMarkersHelper().getMapMarkers()) {
        if ((!unknownLocation && selectMarkerOnSingleTap) || !isSynced(marker)) {
            LatLon latLon = marker.point;
            if (latLon != null) {
                int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
                int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
                if (calculateBelongs((int) point.x, (int) point.y, x, y, r)) {
                    if (!unknownLocation && selectMarkerOnSingleTap) {
                        o.add(marker);
                    } else {
                        if (isMarkerOnFavorite(marker) || isMarkerOnWaypoint(marker)) {
                            continue;
                        }
                        Amenity mapObj = getMapObjectByMarker(marker);
                        if (mapObj != null) {
                            amenities.add(mapObj);
                            o.add(mapObj);
                        } else {
                            o.add(marker);
                        }
                    }
                }
            }
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) Amenity(net.osmand.data.Amenity) OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint)

Example 3 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class MapMarkersLayer method runExclusiveAction.

@Override
public boolean runExclusiveAction(Object o, boolean unknownLocation) {
    if (unknownLocation || o == null || !(o instanceof MapMarker) || !map.getMyApplication().getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) {
        return false;
    }
    final MapMarkersHelper helper = map.getMyApplication().getMapMarkersHelper();
    final MapMarker old = helper.getMapMarkers().get(0);
    helper.moveMarkerToTop((MapMarker) o);
    String title = map.getString(R.string.marker_activated, helper.getMapMarkers().get(0).getName(map));
    Snackbar.make(map.findViewById(R.id.bottomFragmentContainer), title, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_cancel, new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            helper.moveMarkerToTop(old);
        }
    }).show();
    return true;
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) View(android.view.View)

Example 4 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class MapMarkersWidgetsFactory method updateInfo.

public void updateInfo(LatLon customLocation, int zoom) {
    if (customLocation != null) {
        loc = customLocation;
    } else {
        Location l = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
        if (l != null) {
            loc = new LatLon(l.getLatitude(), l.getLongitude());
        } else {
            loc = map.getMapLocation();
        }
    }
    List<MapMarker> markers = helper.getMapMarkers();
    if (zoom < 3 || markers.size() == 0 || !map.getMyApplication().getSettings().MARKERS_DISTANCE_INDICATION_ENABLED.get() || !map.getMyApplication().getSettings().MAP_MARKERS_MODE.get().isToolbar() || map.getMyApplication().getRoutingHelper().isFollowingMode() || map.getMyApplication().getRoutingHelper().isRoutePlanningMode() || MapRouteInfoMenu.isVisible() || addressTopBar.getVisibility() == View.VISIBLE || map.isTopToolbarActive() || !map.getContextMenu().shouldShowTopControls() || map.getMapLayers().getMapMarkersLayer().isInPlanRouteMode()) {
        updateVisibility(false);
        return;
    }
    Float heading = map.getMapViewTrackingUtilities().getHeading();
    MapMarker marker = markers.get(0);
    updateUI(loc, heading, marker, arrowImg, distText, okButton, addressText, true, customLocation != null);
    if (markers.size() > 1 && map.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 2) {
        marker = markers.get(1);
        if (loc != null && customLocation == null) {
            for (int i = 1; i < markers.size(); i++) {
                MapMarker m = markers.get(i);
                m.dist = (int) (MapUtils.getDistance(m.getLatitude(), m.getLongitude(), loc.getLatitude(), loc.getLongitude()));
                if (m.dist < MIN_DIST_2ND_ROW_SHOW && marker.dist > m.dist) {
                    marker = m;
                }
            }
        }
        updateUI(loc, heading, marker, arrowImg2nd, distText2nd, okButton2nd, addressText2nd, false, customLocation != null);
        updateVisibility(topBar2nd, true);
    } else {
        updateVisibility(topBar2nd, false);
    }
    updateVisibility(true);
}
Also used : LatLon(net.osmand.data.LatLon) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) Location(net.osmand.Location)

Example 5 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class MapMarkersWidgetsFactory method showMarkerOnMap.

private void showMarkerOnMap(int index) {
    if (helper.getMapMarkers().size() > index) {
        MapMarker marker = helper.getMapMarkers().get(index);
        AnimateDraggingMapThread thread = map.getMapView().getAnimatedDraggingThread();
        LatLon pointToNavigate = marker.point;
        if (pointToNavigate != null) {
            int fZoom = map.getMapView().getZoom() < 15 ? 15 : map.getMapView().getZoom();
            thread.startMoving(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true);
        }
    // MapMarkerDialogHelper.showMarkerOnMap(map, marker);
    }
}
Also used : LatLon(net.osmand.data.LatLon) AnimateDraggingMapThread(net.osmand.plus.views.AnimateDraggingMapThread) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker)

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