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 avoidElements = 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 maxSpeed; } } } Double value = highwaySpeed.get(road.getHighway()); if (value == null) { value = minDefaultSpeed; } return value / 3.6d; } @Override public double defineSpeedPriority(RouteDataObject road) { String highway = road.getHighway(); double priority = highway != null && highwayPriorities.containsKey(highway) ? highwayPriorities.get(highway) : 1d; return priority; } @Override public double getMinDefaultSpeed() { return minDefaultSpeed / 3.6d; } @Override public double getMaxDefaultSpeed() { return maxDefaultSpeed / 3.6d; } @Override public double calculateTurnTime(RouteSegment segment, RouteSegment next, int segmentEnd) { if (leftTurn > 0 || rightTurn > 0) { if (next.road.getPointsLength() > 1) { double a1 = segment.directionRoute(segmentEnd, segment.segmentStart > segmentEnd); double a2 = next.directionRoute(next.segmentStart, next.segmentStart < next.getRoad().getPointsLength() - 1); double diff = Math.abs(MapUtils.alignAngleDifference(a1 - a2)); // more like UT if (diff < Math.PI / 4) { return leftTurn; } else if (diff < 2 * Math.PI / 3 && diff <= 3 * Math.PI / 4) { return rightTurn; } } return 0; } return 0; } }