Fix bug in countries with mph limits

This commit is contained in:
vshcherb 2014-04-07 00:55:53 +02:00
parent 99423c5b04
commit fb83b64ac4
2 changed files with 13 additions and 5 deletions

View file

@ -21,7 +21,7 @@ import net.osmand.util.MapUtils;
public class GeneralRouter implements VehicleRouter { 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 USE_SHORTEST_WAY = "short_way";
public static final String AVOID_FERRIES = "avoid_ferries"; public static final String AVOID_FERRIES = "avoid_ferries";
public static final String AVOID_TOLL = "avoid_toll"; public static final String AVOID_TOLL = "avoid_toll";
@ -45,7 +45,9 @@ public class GeneralRouter implements VehicleRouter {
private float leftTurn; private float leftTurn;
private float roundaboutTurn; private float roundaboutTurn;
private float rightTurn; private float rightTurn;
// speed in m/s
private float minDefaultSpeed = 10; private float minDefaultSpeed = 10;
// speed in m/s
private float maxDefaultSpeed = 10; private float maxDefaultSpeed = 10;
@ -278,7 +280,7 @@ public class GeneralRouter implements VehicleRouter {
@Override @Override
public float defineVehicleSpeed(RouteDataObject road) { 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 @Override

View file

@ -143,6 +143,7 @@ public class RoutingConfiguration {
final RoutingConfiguration.Builder config = new RoutingConfiguration.Builder(); final RoutingConfiguration.Builder config = new RoutingConfiguration.Builder();
GeneralRouter currentRouter = null; GeneralRouter currentRouter = null;
RouteDataObjectAttribute currentAttribute = null; RouteDataObjectAttribute currentAttribute = null;
String preType = null;
Stack<RoutingRule> rulesStck = new Stack<RoutingConfiguration.RoutingRule>(); Stack<RoutingRule> rulesStck = new Stack<RoutingConfiguration.RoutingRule>();
parser.setInput(is, "UTF-8"); parser.setInput(is, "UTF-8");
int tok; int tok;
@ -160,8 +161,9 @@ public class RoutingConfiguration {
} else if ("point".equals(name) || "way".equals(name)) { } else if ("point".equals(name) || "way".equals(name)) {
String attribute = parser.getAttributeValue("", "attribute"); String attribute = parser.getAttributeValue("", "attribute");
currentAttribute = RouteDataObjectAttribute.getValueOf(attribute); currentAttribute = RouteDataObjectAttribute.getValueOf(attribute);
preType = parser.getAttributeValue("", "type");
} else { } else {
parseRoutingRule(parser, currentRouter, currentAttribute, rulesStck); parseRoutingRule(parser, currentRouter, currentAttribute, preType, rulesStck);
} }
} else if (tok == XmlPullParser.END_TAG) { } else if (tok == XmlPullParser.END_TAG) {
String pname = parser.getName(); String pname = parser.getName();
@ -207,7 +209,7 @@ public class RoutingConfiguration {
} }
private static void parseRoutingRule(XmlPullParser parser, GeneralRouter currentRouter, RouteDataObjectAttribute attr, private static void parseRoutingRule(XmlPullParser parser, GeneralRouter currentRouter, RouteDataObjectAttribute attr,
Stack<RoutingRule> stack) { String parentType, Stack<RoutingRule> stack) {
String pname = parser.getName(); String pname = parser.getName();
if (checkTag(pname)) { if (checkTag(pname)) {
if(attr == null){ if(attr == null){
@ -221,11 +223,15 @@ public class RoutingConfiguration {
rr.value1 = parser.getAttributeValue("", "value1"); rr.value1 = parser.getAttributeValue("", "value1");
rr.value2 = parser.getAttributeValue("", "value2"); rr.value2 = parser.getAttributeValue("", "value2");
rr.type = parser.getAttributeValue("", "type"); 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); RouteAttributeContext ctx = currentRouter.getObjContext(attr);
if("select".equals(rr.tagName)) { if("select".equals(rr.tagName)) {
String val = parser.getAttributeValue("", "value"); String val = parser.getAttributeValue("", "value");
String type = parser.getAttributeValue("", "type"); String type = rr.type;
ctx.registerNewRule(val, type); ctx.registerNewRule(val, type);
addSubclause(rr, ctx); addSubclause(rr, ctx);
for (int i = 0; i < stack.size(); i++) { for (int i = 0; i < stack.size(); i++) {