package net.osmand.router; import java.util.LinkedHashMap; import java.util.Map; import net.osmand.binary.RouteDataObject; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; import net.osmand.osm.MapUtils; import net.osmand.router.BinaryRoutePlanner.RouteSegment; public class GeneralRouter extends VehicleRouter { Map highwaySpeed = new LinkedHashMap(); Map highwayPriorities = new LinkedHashMap(); Map highwayFuturePriorities = new LinkedHashMap(); Map avoid = new LinkedHashMap(); Map obstacles = new LinkedHashMap(); boolean followSpeedLimitations = true; boolean restrictionsAware = true; boolean onewayAware = true; double minDefaultSpeed = 10; double maxDefaultSpeed = 10; double leftTurn = 0; double rightTurn = 0; GeneralRouterProfile profile; public enum GeneralRouterProfile { CAR, PEDESTRIAN, BICYCLE } @Override public boolean acceptLine(RouteDataObject way) { if(!highwaySpeed.containsKey(way.getHighway())) { return false; } int[] s = way.getTypes(); for(int i=0; i 0) { return m; } } Double value = null; for (int i = 0; i < road.types.length; i++) { RouteTypeRule r = road.region.quickGetEncodingRule(road.types[i]); String highway = r.highwayRoad(); if (highway != null && highwaySpeed.containsKey(highway)) { value = highwaySpeed.get(highway); break; } else if(highwaySpeed.containsKey(r.getTag()+"$"+r.getValue())){ value = highwaySpeed.get(r.getTag()+"$"+r.getValue()); break; } } if (value == null) { value = minDefaultSpeed; } return value / 3.6d; } @Override public double defineSpeedPriority(RouteDataObject road) { double priority = 1; for (int i = 0; i < road.types.length; i++) { RouteTypeRule r = road.region.quickGetEncodingRule(road.types[i]); String highway = r.highwayRoad(); if (highway != null && highwayPriorities.containsKey(highway)) { priority *= highwayPriorities.get(highway); } else if(highwayPriorities.containsKey(r.getTag()+"$"+r.getValue())){ priority *= highwayPriorities.get(r.getTag()+"$"+r.getValue()); } } return priority; } @Override public double getMinDefaultSpeed() { return minDefaultSpeed / 3.6d; } @Override public double getMaxDefaultSpeed() { return maxDefaultSpeed / 3.6d; } @Override public double calculateTurnTime(RouteSegment segment, int segmentEnd, RouteSegment prev, int prevSegmentEnd) { if (leftTurn > 0 || rightTurn > 0) { double a1 = segment.getRoad().directionRoute(segment.segmentStart, segment.segmentStart < segmentEnd); double a2 = prev.getRoad().directionRoute(prevSegmentEnd, segmentEnd < prev.segmentStart); double diff = Math.abs(MapUtils.alignAngleDifference(a1 - a2 - Math.PI)); // more like UT if (diff > 2 * Math.PI / 3) { return leftTurn; } else if (diff > Math.PI / 2) { return rightTurn; } return 0; } return 0; } }