diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java index f73bf023cf..0adb877759 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java @@ -57,6 +57,7 @@ public class BinaryMapRouteReaderAdapter { private float floatValue; private int type; private List conditions = null; + private int forward; public RouteTypeRule(String t, String v) { this.t = t.intern(); @@ -75,6 +76,10 @@ public class BinaryMapRouteReaderAdapter { } } + public int isForward() { + return forward; + } + public String getTag() { return t; } @@ -174,6 +179,14 @@ public class BinaryMapRouteReaderAdapter { } else if(t.equalsIgnoreCase("maxspeed") && v != null){ type = MAXSPEED; floatValue = RouteDataObject.parseSpeed(v, 0); + } else if(t.equalsIgnoreCase("maxspeed:forward") && v != null){ + type = MAXSPEED; + forward = 1; + floatValue = RouteDataObject.parseSpeed(v, 0); + } else if(t.equalsIgnoreCase("maxspeed:backward") && v != null){ + type = MAXSPEED; + forward = -1; + floatValue = RouteDataObject.parseSpeed(v, 0); } else if (t.equalsIgnoreCase("lanes") && v != null) { intValue = -1; int i = 0; diff --git a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java index 1b53badcea..c5c6465b96 100644 --- a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java @@ -204,11 +204,16 @@ public class RouteDataObject { return types; } - public float getMaximumSpeed(){ + public float getMaximumSpeed(boolean direction){ int sz = types.length; float maxSpeed = 0; for (int i = 0; i < sz; i++) { RouteTypeRule r = region.quickGetEncodingRule(types[i]); + if(r.isForward() != 0) { + if((r.isForward() > 1) != direction) { + continue; + } + } float mx = r.maxSpeed(); if (mx > 0) { maxSpeed = mx; diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 393e7bbbff..a866b2ba21 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -310,7 +310,7 @@ public class RouteResultPreparation { additional.append("rtime = \"").append(res.getRoutingTime()).append("\" "); additional.append("name = \"").append(name).append("\" "); // float ms = res.getSegmentSpeed(); - float ms = res.getObject().getMaximumSpeed(); + float ms = res.getObject().getMaximumSpeed(res.isForwardDirection()); if(ms > 0) { additional.append("maxspeed = \"").append(ms * 3.6f).append("\" ").append(res.getObject().getHighway()).append(" "); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index ffe840350d..cd51c1eb7f 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -11,14 +11,13 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; import net.osmand.Location; -import net.osmand.ResultMatcher; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; import net.osmand.binary.RouteDataObject; import net.osmand.data.Amenity; -import net.osmand.data.PointDescription; import net.osmand.data.Amenity.AmenityRoutePoint; import net.osmand.data.LocationPoint; +import net.osmand.data.PointDescription; import net.osmand.osm.PoiType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; @@ -258,7 +257,13 @@ public class WaypointHelper { public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc, boolean showCameras) { - float mxspeed = ro.getMaximumSpeed(); + boolean direction = true; + if(loc.hasBearing()) { + double diff = MapUtils.alignAngleDifference(ro.directionRoute(0, true) - + loc.getBearing() / (2 * Math.PI)); + direction = Math.abs(diff) < Math.PI; + } + float mxspeed = ro.getMaximumSpeed(direction); float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f; AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc, delta); if (speedAlarm != null) { diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index c65233ed42..4575a1886a 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -666,7 +666,7 @@ public class RouteCalculationResult { public float getCurrentMaxSpeed() { RouteSegmentResult res = getCurrentSegmentResult(); if(res != null) { - return res.getObject().getMaximumSpeed(); + return res.getObject().getMaximumSpeed(res.isForwardDirection()); } return 0; } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 20060f649d..12491f9924 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -34,6 +34,7 @@ import net.osmand.plus.views.controls.MapRouteInfoControl; import net.osmand.router.RouteResultPreparation; import net.osmand.router.TurnType; import net.osmand.util.Algorithms; +import net.osmand.util.MapUtils; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; @@ -298,7 +299,14 @@ public class RouteInfoWidgetsFactory { if ((rh == null || !rh.isFollowingMode()) && trackingUtilities.isMapLinkedToLocation()) { RouteDataObject ro = locationProvider.getLastKnownRouteSegment(); if(ro != null) { - mx = ro.getMaximumSpeed(); + boolean direction = true; + Location loc = locationProvider.getLastKnownLocation(); + if(loc != null && loc.hasBearing()) { + double diff = MapUtils.alignAngleDifference(ro.directionRoute(0, true) - + loc.getBearing() / (2 * Math.PI)); + direction = Math.abs(diff) < Math.PI; + } + mx = ro.getMaximumSpeed(direction); } } else { mx = rh.getCurrentMaxSpeed();