Display lanes in driving mode

This commit is contained in:
Victor Shcherb 2014-11-25 10:48:15 +01:00
parent d59f555e80
commit b4db8bdbd9
4 changed files with 48 additions and 16 deletions

View file

@ -660,7 +660,7 @@ public class RouteResultPreparation {
return Math.max(1, (lns + 1) / 2);
}
protected String getTurnLanesString(RouteSegmentResult segment) {
protected static String getTurnLanesString(RouteSegmentResult segment) {
if (segment.getObject().getOneway() == 0) {
if (segment.isForwardDirection()) {
return segment.getObject().getValue("turn:lanes:forward");
@ -722,7 +722,27 @@ public class RouteResultPreparation {
return count;
}
private int[] calculateRawTurnLanes(String[] splitLaneOptions, int calcTurnType) {
public static int[] parseTurnLanes(RouteDataObject ro, double dirToNorthEastPi) {
String turnLanes = null;
if (ro.getOneway() == 0) {
// we should get direction to detect forward or backward
double cmp = ro.directionRoute(0, true);
if(Math.abs(MapUtils.alignAngleDifference(dirToNorthEastPi -cmp)) < Math.PI / 2) {
turnLanes = ro.getValue("turn:lanes:forward");
} else {
turnLanes = ro.getValue("turn:lanes:backward");
}
} else {
turnLanes = ro.getValue("turn:lanes");
}
if(turnLanes == null) {
return null;
}
String[] splitLaneOptions = turnLanes.split("\\|", -1);
return calculateRawTurnLanes(splitLaneOptions, 0);
}
private static int[] calculateRawTurnLanes(String[] splitLaneOptions, int calcTurnType) {
int[] lanes = new int[splitLaneOptions.length];
for (int i = 0; i < splitLaneOptions.length; i++) {
String[] laneOptions = splitLaneOptions[i].split(";");

View file

@ -823,7 +823,10 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> SHOW_TRAFFIC_WARNINGS = new BooleanPreference("show_traffic_warnings", true).makeProfile().cache();
public final OsmandPreference<Boolean> SHOW_CAMERAS = new BooleanPreference("show_cameras", true).makeProfile().cache();
public final OsmandPreference<Boolean> SHOW_LANES = new BooleanPreference("show_lanes", true).makeProfile().cache();
public final CommonPreference<Boolean> SHOW_LANES = new BooleanPreference("show_lanes", true).makeProfile().cache();
{
SHOW_LANES.setModeDefaultValue(ApplicationMode.DEFAULT, false);
}
public final OsmandPreference<Boolean> SPEAK_TRAFFIC_WARNINGS = new BooleanPreference("speak_traffic_warnings", true).makeProfile().cache();
public final OsmandPreference<Boolean> SPEAK_STREET_NAMES = new BooleanPreference("speak_street_names", true).makeProfile().cache();

View file

@ -152,7 +152,7 @@ public class MapInfoLayer extends OsmandMapLayer {
RouteInfoWidgetsFactory ric = new RouteInfoWidgetsFactory(scaleCoefficient);
MapInfoWidgetsFactory mic = new MapInfoWidgetsFactory(scaleCoefficient);
OsmandApplication app = view.getApplication();
lanesControl = ric.createLanesControl(app.getRoutingHelper(), view);
lanesControl = ric.createLanesControl(map, view);
lanesControl.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_free));
alarmControl = ric.createAlarmInfoControl(app, map);

View file

@ -29,6 +29,7 @@ import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.TurnPathHelper;
import net.osmand.plus.views.controls.MapRouteInfoControl;
import net.osmand.router.RouteResultPreparation;
import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
import android.content.Context;
@ -545,7 +546,7 @@ public class RouteInfoWidgetsFactory {
return p;
}
public BaseMapWidget createLanesControl(final RoutingHelper routingHelper, final OsmandMapTileView view) {
public BaseMapWidget createLanesControl(final MapActivity map, final OsmandMapTileView view) {
final List<Path> paths = new ArrayList<Path>();
final Path laneStraight = getPathFromTurnType(paths, TurnType.C, null);
@ -560,11 +561,12 @@ public class RouteInfoWidgetsFactory {
paintRouteDirection.setColor(view.getResources().getColor(R.color.nav_arrow));
paintRouteDirection.setAntiAlias(true);
final float w = 72 * scaleCoefficient / miniCoeff;
final MapViewTrackingUtilities trackingUtilities = map.getMapViewTrackingUtilities();
final OsmAndLocationProvider locationProvider = map.getMyApplication().getLocationProvider();
final RoutingHelper rh = map.getMyApplication().getRoutingHelper();
final BaseMapWidget lanesControl = new BaseMapWidget(view.getContext()) {
int[] lanes = null;
private TurnType turn;
boolean imminent = false;
@ -604,13 +606,21 @@ public class RouteInfoWidgetsFactory {
boolean visible = false;
int locimminent = -1;
int[] loclanes = null;
TurnType primary = null;
if (routingHelper != null && routingHelper.isRouteCalculated() && view.getSettings().SHOW_LANES.get()) {
if (routingHelper.isFollowingMode()) {
NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), false);
// TurnType primary = null;
if ((rh == null || !rh.isFollowingMode()) && trackingUtilities.isMapLinkedToLocation()
&& view.getSettings().SHOW_LANES.get()) {
RouteDataObject ro = locationProvider.getLastKnownRouteSegment();
Location lp = locationProvider.getLastKnownLocation();
if(ro != null) {
float degree = lp == null || !lp.hasBearing() ? 0 : lp.getBearing();
loclanes = RouteResultPreparation.parseTurnLanes(ro, degree / 180 * Math.PI);
}
} else if (rh != null && rh.isRouteCalculated() ) {
if (rh.isFollowingMode() && view.getSettings().SHOW_LANES.get()) {
NextDirectionInfo r = rh.getNextRouteDirectionInfo(new NextDirectionInfo(), false);
if(r != null && r.directionInfo != null && r.directionInfo.getTurnType() != null) {
loclanes = r.directionInfo.getTurnType().getLanes();
primary = r.directionInfo.getTurnType();
// primary = r.directionInfo.getTurnType();
locimminent = r.imminent;
// Do not show too far
if ((r.distanceTo > 700 && r.directionInfo.getTurnType().isSkipToSpeak()) || r.distanceTo > 1200) {
@ -620,11 +630,11 @@ public class RouteInfoWidgetsFactory {
} else {
int di = MapRouteInfoControl.getDirectionInfo();
if (di >= 0 && MapRouteInfoControl.isControlVisible()
&& di < routingHelper.getRouteDirections().size()) {
RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
&& di < rh.getRouteDirections().size()) {
RouteDirectionInfo next = rh.getRouteDirections().get(di);
if (next != null) {
loclanes = next.getTurnType().getLanes();
primary = next.getTurnType();
// primary = next.getTurnType();
}
}
}
@ -633,7 +643,6 @@ public class RouteInfoWidgetsFactory {
if (visible) {
if (!Arrays.equals(lanes, loclanes)) {
lanes = loclanes;
turn = primary;
requestLayout();
invalidate();
}