From fb83b64ac456728c3c28cd3e445bdea89d654951 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 7 Apr 2014 00:55:53 +0200 Subject: [PATCH] Fix bug in countries with mph limits --- OsmAnd-java/src/net/osmand/router/GeneralRouter.java | 6 ++++-- .../src/net/osmand/router/RoutingConfiguration.java | 12 +++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/GeneralRouter.java b/OsmAnd-java/src/net/osmand/router/GeneralRouter.java index ad2364ee0f..84e9e192bc 100644 --- a/OsmAnd-java/src/net/osmand/router/GeneralRouter.java +++ b/OsmAnd-java/src/net/osmand/router/GeneralRouter.java @@ -21,7 +21,7 @@ import net.osmand.util.MapUtils; public class GeneralRouter implements VehicleRouter { - private static final float CAR_SHORTEST_DEFAULT_SPEED = 45/3.6f; + private static final float CAR_SHORTEST_DEFAULT_SPEED = 55/3.6f; public static final String USE_SHORTEST_WAY = "short_way"; public static final String AVOID_FERRIES = "avoid_ferries"; public static final String AVOID_TOLL = "avoid_toll"; @@ -45,7 +45,9 @@ public class GeneralRouter implements VehicleRouter { private float leftTurn; private float roundaboutTurn; private float rightTurn; + // speed in m/s private float minDefaultSpeed = 10; + // speed in m/s private float maxDefaultSpeed = 10; @@ -278,7 +280,7 @@ public class GeneralRouter implements VehicleRouter { @Override public float defineVehicleSpeed(RouteDataObject road) { - return getObjContext(RouteDataObjectAttribute.ROAD_SPEED) .evaluateFloat(road, getMinDefaultSpeed() * 3.6f) / 3.6f; + return getObjContext(RouteDataObjectAttribute.ROAD_SPEED) .evaluateFloat(road, getMinDefaultSpeed()); } @Override diff --git a/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java b/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java index fe8da2f45a..a73bd6ea45 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java +++ b/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java @@ -143,6 +143,7 @@ public class RoutingConfiguration { final RoutingConfiguration.Builder config = new RoutingConfiguration.Builder(); GeneralRouter currentRouter = null; RouteDataObjectAttribute currentAttribute = null; + String preType = null; Stack rulesStck = new Stack(); parser.setInput(is, "UTF-8"); int tok; @@ -160,8 +161,9 @@ public class RoutingConfiguration { } else if ("point".equals(name) || "way".equals(name)) { String attribute = parser.getAttributeValue("", "attribute"); currentAttribute = RouteDataObjectAttribute.getValueOf(attribute); + preType = parser.getAttributeValue("", "type"); } else { - parseRoutingRule(parser, currentRouter, currentAttribute, rulesStck); + parseRoutingRule(parser, currentRouter, currentAttribute, preType, rulesStck); } } else if (tok == XmlPullParser.END_TAG) { String pname = parser.getName(); @@ -207,7 +209,7 @@ public class RoutingConfiguration { } private static void parseRoutingRule(XmlPullParser parser, GeneralRouter currentRouter, RouteDataObjectAttribute attr, - Stack stack) { + String parentType, Stack stack) { String pname = parser.getName(); if (checkTag(pname)) { if(attr == null){ @@ -221,11 +223,15 @@ public class RoutingConfiguration { rr.value1 = parser.getAttributeValue("", "value1"); rr.value2 = parser.getAttributeValue("", "value2"); rr.type = parser.getAttributeValue("", "type"); + if((rr.type == null || rr.type.length() == 0) && + parentType != null && parentType.length() > 0) { + rr.type = parentType; + } RouteAttributeContext ctx = currentRouter.getObjContext(attr); if("select".equals(rr.tagName)) { String val = parser.getAttributeValue("", "value"); - String type = parser.getAttributeValue("", "type"); + String type = rr.type; ctx.registerNewRule(val, type); addSubclause(rr, ctx); for (int i = 0; i < stack.size(); i++) {