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.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; } private double directionRoute(RouteSegment segment, int segmentEnd, boolean opp){ boolean plus = segmentEnd == 0; int x = segment.road.getPoint31XTile(segmentEnd); int y = segment.road.getPoint31YTile(segmentEnd); int nx = segmentEnd; int px = x; int py = y; do { if(plus){ nx++; if(nx >= segment.road.getPointsLength()){ break; } } else { nx--; if(nx < 0){ break; } } px = segment.road.getPoint31XTile(nx); py = segment.road.getPoint31YTile(nx); } while(Math.abs(px - x) + Math.abs(py - y) < 100); if(opp){ return Math.atan2(py - y, px - x); } else { return Math.atan2(y - py, x - px); } } @Override public double calculateTurnTime(RouteSegment segment, RouteSegment next, int segmentEnd) { if (leftTurn > 0 || rightTurn > 0) { if (next.road.getPointsLength() > 1) { double a1 = directionRoute(segment, segmentEnd, false); double a2 = directionRoute(next, next.segmentStart, true); double diff = Math.abs(a1 - a2); // more like UT if (diff > 3 * Math.PI / 4 && diff < 5 * Math.PI / 4) { return leftTurn; } if (diff > Math.PI / 3 && diff <= 3 * Math.PI / 4) { return rightTurn; } if (diff < 2 * Math.PI / 3 && diff >= 3 * Math.PI / 4) { return leftTurn; } } return 0; } return 0; } }