From fa0f4dc4b1a7083078c3ed97c825be9b4d409dc5 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 9 Dec 2014 22:34:33 +0100 Subject: [PATCH] Display lanes for car driving without navigation --- .../osmand/router/RouteResultPreparation.java | 30 +++++++++++++++++++ .../mapwidgets/RouteInfoWidgetsFactory.java | 3 ++ 2 files changed, 33 insertions(+) diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 365fbe0e62..3e1d852af1 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -850,6 +850,36 @@ public class RouteResultPreparation { return calculateRawTurnLanes(splitLaneOptions, 0); } + public static int[] parseLanes(RouteDataObject ro, double dirToNorthEastPi) { + int lns = 0; + try { + 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) { + if(ro.getValue("lanes:forward") != null) { + lns = Integer.parseInt(ro.getValue("lanes:forward")); + } + } else { + if(ro.getValue("lanes:backward") != null) { + lns = Integer.parseInt(ro.getValue("lanes:backward")); + } + } + if (lns == 0 && ro.getValue("lanes") != null) { + lns = Integer.parseInt(ro.getValue("lanes")) / 2; + } + } else { + lns = Integer.parseInt(ro.getValue("lanes")); + } + if(lns > 0 ) { + return new int[lns]; + } + } catch (NumberFormatException e) { + } + return null; + } + private static int[] calculateRawTurnLanes(String[] splitLaneOptions, int calcTurnType) { int[] lanes = new int[splitLaneOptions.length]; for (int i = 0; i < splitLaneOptions.length; i++) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 55a6b2ffa6..0f34a9a0dc 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -614,6 +614,9 @@ public class RouteInfoWidgetsFactory { if(ro != null) { float degree = lp == null || !lp.hasBearing() ? 0 : lp.getBearing(); loclanes = RouteResultPreparation.parseTurnLanes(ro, degree / 180 * Math.PI); + if(loclanes == null) { + loclanes = RouteResultPreparation.parseLanes(ro, degree / 180 * Math.PI); + } } } else if (rh != null && rh.isRouteCalculated() ) { if (rh.isFollowingMode() && view.getSettings().SHOW_LANES.get()) {