Build route with selected Map markers

This commit is contained in:
Alexey Kulish 2016-02-26 22:06:51 +03:00
parent 0280cad46f
commit fdedcfb1d3
6 changed files with 78 additions and 21 deletions

View file

@ -84,7 +84,8 @@ public class MapMarkersHelper {
public MapMarkersHelper(OsmandApplication ctx) {
this.ctx = ctx;
this.settings = ctx.getSettings();
settings = ctx.getSettings();
startFromMyLocation = settings.ROUTE_MAP_MARKERS_START_MY_LOC.get();
readFromSettings();
}
@ -94,6 +95,7 @@ public class MapMarkersHelper {
public void setStartFromMyLocation(boolean startFromMyLocation) {
this.startFromMyLocation = startFromMyLocation;
settings.ROUTE_MAP_MARKERS_START_MY_LOC.set(startFromMyLocation);
}
private void readFromSettings() {
@ -203,6 +205,16 @@ public class MapMarkersHelper {
return mapMarkersHistory;
}
public List<MapMarker> getSelectedMarkers() {
List<MapMarker> list = new ArrayList<>();
for (MapMarker m : this.mapMarkers) {
if (m.selected) {
list.add(m);
}
}
return list;
}
public List<LatLon> getActiveMarkersLatLon() {
List<LatLon> list = new ArrayList<>();
for (MapMarker m : this.mapMarkers) {

View file

@ -1156,6 +1156,8 @@ public class OsmandSettings {
MAP_MARKERS_MODE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, MapMarkersMode.TOOLBAR);
}
public final OsmandPreference<Boolean> ROUTE_MAP_MARKERS_START_MY_LOC = new BooleanPreference("route_map_markers_start_my_loc", false).makeGlobal().cache();
public ITileSource getMapTileSource(boolean warnWhenSelected) {
String tileName = MAP_TILE_SOURCES.get();
if (tileName != null) {

View file

@ -1210,6 +1210,13 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents,
top = Math.max(top, l.getLatitude());
bottom = Math.min(bottom, l.getLatitude());
}
List<TargetPoint> targetPoints = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
for (TargetPoint l : targetPoints) {
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;

View file

@ -51,6 +51,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.tools.DashFragmentData;
@ -581,8 +582,36 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
routeButton.onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.getMapLayers().getMapControlsLayer().doRoute();
boolean hasTargets = false;
if (visibleType == DashboardType.MAP_MARKERS_SELECTION) {
TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
List<MapMarker> markers = markersHelper.getSelectedMarkers();
if (markers.size() > 0) {
int i = 0;
if (markersHelper.isStartFromMyLocation()) {
targetPointsHelper.clearStartPoint(false);
} else {
MapMarker m = markers.get(i++);
targetPointsHelper.setStartPoint(new LatLon(m.getLatitude(), m.getLongitude()),
false, m.getPointDescription(mapActivity));
}
List<TargetPoint> targetPoints = new ArrayList<>();
for (int k = i; k < markers.size(); k++) {
MapMarker m = markers.get(k);
TargetPoint t = new TargetPoint(new LatLon(m.getLatitude(), m.getLongitude()),
m.getPointDescription(mapActivity));
targetPoints.add(t);
}
targetPointsHelper.reorderAllTargetPoints(targetPoints, false);
hasTargets = true;
} else {
targetPointsHelper.clearStartPoint(false);
targetPointsHelper.clearPointToNavigate(false);
}
}
hideDashboard();
mapActivity.getMapLayers().getMapControlsLayer().doRoute(hasTargets);
}
};
@ -700,6 +729,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
if (visible == this.visible && type == visibleType) {
return;
}
mapActivity.getRoutingHelper().removeListener(this);
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
this.previousVisibleType = prevItem;
this.visible = visible;
@ -712,6 +742,15 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
DashboardOnMap.staticVisible = visible;
DashboardOnMap.staticVisibleType = type;
mapActivity.enableDrawer();
getMyApplication().getMapMarkersHelper().removeListener(this);
if (mapActivity.getMapLayers().getMapMarkersLayer().clearRoute()) {
mapActivity.refreshMap();
}
if (swipeDismissListener != null) {
swipeDismissListener.discardUndo();
}
if (visible) {
mapActivity.getContextMenu().hideMenues();
mapViewLocation = mapActivity.getMapLocation();
@ -721,11 +760,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
mapActivity.getMapViewTrackingUtilities().setDashboard(this);
mapActivity.disableDrawer();
dashboardView.setVisibility(View.VISIBLE);
if (visibleType == DashboardType.MAP_MARKERS || previousVisibleType == DashboardType.MAP_MARKERS_SELECTION) {
if (mapActivity.getMapLayers().getMapMarkersLayer().clearRoute()) {
mapActivity.refreshMap();
}
}
if (isActionButtonVisible()) {
setActionButton(visibleType);
actionButton.setVisibility(View.VISIBLE);
@ -777,14 +811,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
// addOrUpdateDashboardFragments();
mapActivity.getRoutingHelper().addListener(this);
} else {
if (visibleType == DashboardType.MAP_MARKERS || visibleType == DashboardType.MAP_MARKERS_SELECTION) {
getMyApplication().getMapMarkersHelper().removeListener(this);
mapActivity.getMapLayers().getMapMarkersLayer().clearRoute();
}
if (swipeDismissListener != null) {
swipeDismissListener.discardUndo();
}
mapActivity.getRoutingHelper().removeListener(this);
mapActivity.getMapViewTrackingUtilities().setDashboard(null);
hide(dashboardView.findViewById(R.id.animateContent), animation);

View file

@ -37,6 +37,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.search.SearchAddressFragment;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
@ -90,6 +91,7 @@ public class MapControlsLayer extends OsmandMapLayer {
private MapHudButton mapZoomIn;
private MapHudButton layersHud;
private long lastZoom;
private boolean hasTargets;
public MapControlsLayer(MapActivity activity) {
this.mapActivity = activity;
@ -363,12 +365,13 @@ public class MapControlsLayer extends OsmandMapLayer {
routePlanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
doRoute();
doRoute(false);
}
});
}
public void doRoute() {
public void doRoute(boolean hasTargets) {
this.hasTargets = hasTargets;
if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
onNavigationClick();
} else {
@ -387,13 +390,20 @@ public class MapControlsLayer extends OsmandMapLayer {
MapActivity.clearPrevActivityIntent();
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
if (settings.USE_MAP_MARKERS.get()) {
if (settings.USE_MAP_MARKERS.get() && !hasTargets) {
mapActivity.getMapActions().setFirstMapMarkerAsTarget();
}
mapActivity.getMapActions().enterRoutePlanningMode(null, null);
TargetPoint start = getTargets().getPointToStart();
if (hasTargets && start != null) {
mapActivity.getMapActions().enterRoutePlanningMode(
new LatLon(start.getLatitude(), start.getLongitude()), start.getOriginalPointDescription());
} else {
mapActivity.getMapActions().enterRoutePlanningMode(null, null);
}
} else {
showRouteInfoControlDialog();
}
hasTargets = false;
}

View file

@ -716,7 +716,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
if (mSwiping) {
mSwipeDownView.setTranslationX(deltaX);
mSwipeDownView.setAlpha(Math.max(0f, Math.min(1f,
ViewCompat.setAlpha(mSwipeDownView, Math.max(0f, Math.min(1f,
1f - 2f * Math.abs(deltaX) / mViewWidth)));
return true;
}
@ -814,7 +814,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
ViewGroup.LayoutParams lp;
for (PendingDismissData pendingDismiss : mPendingDismisses) {
pendingDismiss.view.setAlpha(1f);
ViewCompat.setAlpha(pendingDismiss.view, 1f);
pendingDismiss.view.setTranslationX(0);
lp = pendingDismiss.childView.getLayoutParams();
lp.height = originalLayoutHeight;