diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index ae3bc19ef1..2e799b65de 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -202,6 +202,16 @@ public class MapMarkersHelper { return list; } + public List getSelectedMarkersLatLon() { + List list = new ArrayList<>(); + for (MapMarker m : this.mapMarkers) { + if (m.selected) { + list.add(m.point); + } + } + return list; + } + public List getMarkersHistoryLatLon() { List list = new ArrayList<>(); for (MapMarker m : this.mapMarkersHistory) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index a9735c0358..13976eeacc 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -38,11 +38,13 @@ import com.github.ksoichiro.android.observablescrollview.ScrollState; import net.osmand.PlatformUtil; import net.osmand.ValueHolder; import net.osmand.data.LatLon; +import net.osmand.data.RotatedTileBox; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnRowItemClick; import net.osmand.plus.IconsCache; +import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener; import net.osmand.plus.OsmandApplication; @@ -772,6 +774,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis } else { if (visibleType == DashboardType.MAP_MARKERS || visibleType == DashboardType.MAP_MARKERS_SELECTION) { getMyApplication().getMapMarkersHelper().removeListener(this); + mapActivity.getMapLayers().getMapMarkersLayer().clearRoute(); } if (swipeDismissListener != null) { swipeDismissListener.discardUndo(); @@ -859,6 +862,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis setDynamicListItems(listView, listAdapter); updateListAdapter(listAdapter, listener); + if (visibleType == DashboardType.MAP_MARKERS_SELECTION) { + showMarkersRouteOnMap(); + } } else { @@ -904,7 +910,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis View v = listView.getChildAt(0); int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop()); updateListAdapter(); - ((ListView)listView).setSelectionFromTop(index, top); + ((ListView) listView).setSelectionFromTop(index, top); } else { listAdapter.notifyDataSetChanged(); } @@ -1388,6 +1394,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis } else if (visibleType == DashboardType.MAP_MARKERS || visibleType == DashboardType.MAP_MARKERS_SELECTION) { List markers = (List) (Object) items; getMyApplication().getMapMarkersHelper().saveMapMarkers(markers, null); + if (visibleType == DashboardType.MAP_MARKERS_SELECTION) { + showMarkersRouteOnMap(); + } } if (swipeDismissListener != null) { @@ -1426,6 +1435,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis waypointDialogHelper.reloadListAdapter(stableAdapter); } else if (DashboardType.MAP_MARKERS == visibleType || visibleType == DashboardType.MAP_MARKERS_SELECTION) { mapMarkerDialogHelper.reloadListAdapter(stableAdapter); + if (visibleType == DashboardType.MAP_MARKERS_SELECTION) { + showMarkersRouteOnMap(); + } } setDynamicListItems(listView, stableAdapter); } @@ -1446,4 +1458,44 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis public void deleteMapMarker(int position) { deleteSwipeItem(position); } + + @Override + public void showMarkersRouteOnMap() { + MapMarkersHelper helper = getMyApplication().getMapMarkersHelper(); + List points = helper.getSelectedMarkersLatLon(); + mapActivity.getMapLayers().getMapMarkersLayer().setRoute(points); + showRouteOnMap(points); + } + + public void showRouteOnMap(List points) { + if (points.size() > 0 && mapActivity != null) { + OsmandMapTileView mapView = mapActivity.getMapView(); + double left = 0, right = 0; + double top = 0, bottom = 0; + for (LatLon l : points) { + if (left == 0) { + left = l.getLongitude(); + right = l.getLongitude(); + top = l.getLatitude(); + bottom = l.getLatitude(); + } else { + left = Math.min(left, l.getLongitude()); + right = Math.max(right, l.getLongitude()); + top = Math.max(top, l.getLatitude()); + bottom = Math.min(bottom, l.getLatitude()); + } + } + + RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy(); + int tileBoxWidthPx = 0; + int tileBoxHeightPx = 0; + + if (landscape) { + tileBoxWidthPx = tb.getPixWidth() - dashboardView.getWidth(); + } else if (listBackgroundView != null) { + tileBoxHeightPx = 3 * (mFlexibleSpaceImageHeight - mFlexibleBlurSpaceHeight) / 4; + } + mapView.fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, mFlexibleBlurSpaceHeight * 3/2); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java index fe83f7533c..6cf6aa690d 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java @@ -76,8 +76,8 @@ public class MapMarkerDialogHelper { public interface MapMarkersDialogHelperCallbacks { void reloadAdapter(); - void deleteMapMarker(int position); + void showMarkersRouteOnMap(); } public MapMarkerDialogHelper(MapActivity mapActivity) { @@ -126,6 +126,9 @@ public class MapMarkerDialogHelper { checkBox.setChecked(!checkBox.isChecked()); marker.selected = checkBox.isChecked(); markersHelper.updateMapMarker(marker, false); + if (helperCallbacks != null) { + helperCallbacks.showMarkersRouteOnMap(); + } } else { if (!marker.history) { showMarkerOnMap(mapActivity, marker); diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 198c3b57e2..f06dcf35c1 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -4,6 +4,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; +import android.graphics.Path; import android.graphics.PointF; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; @@ -12,7 +13,6 @@ import android.os.Message; import android.view.GestureDetector; import android.view.MotionEvent; -import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadPoint; @@ -26,6 +26,7 @@ import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProviderSelection; import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; +import java.util.ArrayList; import java.util.List; public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection { @@ -57,6 +58,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private Bitmap arrowToDestination; private float[] calculations = new float[2]; + private Paint paint; + private Path path; + private List route = new ArrayList<>(); + private LatLon fingerLocation; private boolean hasMoved; private boolean moving; @@ -94,6 +99,16 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi bitmapPaintDestTeal = createPaintDest(R.color.marker_teal); bitmapPaintDestPurple = createPaintDest(R.color.marker_purple); + path = new Path(); + paint = new Paint(); + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeWidth(7 * view.getDensity()); + paint.setAntiAlias(true); + paint.setStrokeCap(Paint.Cap.ROUND); + paint.setStrokeJoin(Paint.Join.ROUND); + paint.setColor(map.getResources().getColor(R.color.marker_red)); + paint.setAlpha(200); + widgetsFactory = new MapMarkersWidgetsFactory(map); } @@ -149,6 +164,15 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } } + public void setRoute(List points) { + route.clear(); + route.addAll(points); + } + + public void clearRoute() { + route.clear(); + } + @Override public void initLayer(OsmandMapTileView view) { this.view = view; @@ -196,6 +220,22 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi return; } + if (route.size() > 0) { + path.reset(); + boolean first = true; + for (LatLon point : route) { + int locationX = tb.getPixXFromLonNoRot(point.getLongitude()); + int locationY = tb.getPixYFromLatNoRot(point.getLatitude()); + if (first) { + path.moveTo(locationX, locationY); + first = false; + } else { + path.lineTo(locationX, locationY); + } + } + canvas.drawPath(path, paint); + } + MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); List activeMapMarkers = markersHelper.getActiveMapMarkers(); for (int i = 0; i < activeMapMarkers.size(); i++) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index 43408d94a2..9428c2a6e4 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -169,7 +169,8 @@ public class MapMarkersWidgetsFactory { } public boolean isTopBarVisible() { - return topBar.getVisibility() == View.VISIBLE; + return topBar.getVisibility() == View.VISIBLE + && map.findViewById(R.id.MapHudButtonsOverlay).getVisibility() == View.VISIBLE; } public void updateInfo(LatLon customLocation, int zoom) {