file formatting
This commit is contained in:
parent
6605e1d8d2
commit
a74c1a2549
1 changed files with 80 additions and 109 deletions
|
@ -82,15 +82,18 @@ public class RouteProvider {
|
|||
// ORS("OpenRouteService"), // disable ors due to no public rest service (testing2015 doesn't seem stable)
|
||||
OSRM("OSRM (only car)"),
|
||||
BROUTER("BRouter (offline)"), STRAIGHT("Straight line");
|
||||
|
||||
private final String name;
|
||||
private RouteService(String name){
|
||||
|
||||
private RouteService(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isOnline(){
|
||||
public boolean isOnline() {
|
||||
return this != OSMAND && this != BROUTER;
|
||||
}
|
||||
|
||||
|
@ -101,10 +104,10 @@ public class RouteProvider {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static RouteService[] getAvailableRouters(OsmandApplication ctx){
|
||||
public static RouteService[] getAvailableRouters(OsmandApplication ctx) {
|
||||
List<RouteService> list = new ArrayList<RouteProvider.RouteService>();
|
||||
for(RouteService r : values()) {
|
||||
if(r.isAvailable(ctx)) {
|
||||
if (r.isAvailable(ctx)) {
|
||||
list.add(r);
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +115,7 @@ public class RouteProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public RouteProvider(){
|
||||
public RouteProvider() {
|
||||
}
|
||||
|
||||
public static class GPXRouteParamsBuilder {
|
||||
|
@ -125,7 +128,7 @@ public class RouteProvider {
|
|||
private boolean calculateOsmAndRouteParts;
|
||||
private boolean useIntermediatePointsRTE;
|
||||
|
||||
public GPXRouteParamsBuilder(GPXFile file, OsmandSettings settings){
|
||||
public GPXRouteParamsBuilder(GPXFile file, OsmandSettings settings) {
|
||||
leftSide = settings.DRIVING_REGION.get().leftHandDriving;
|
||||
this.file = file;
|
||||
}
|
||||
|
@ -158,7 +161,7 @@ public class RouteProvider {
|
|||
this.calculateOsmAndRoute = calculateOsmAndRoute;
|
||||
}
|
||||
|
||||
public void setPassWholeRoute(boolean passWholeRoute){
|
||||
public void setPassWholeRoute(boolean passWholeRoute) {
|
||||
this.passWholeRoute = passWholeRoute;
|
||||
}
|
||||
|
||||
|
@ -169,13 +172,12 @@ public class RouteProvider {
|
|||
public GPXRouteParams build(Location start, OsmandSettings settings) {
|
||||
GPXRouteParams res = new GPXRouteParams();
|
||||
res.prepareGPXFile(this);
|
||||
// if(passWholeRoute && start != null){
|
||||
// if (passWholeRoute && start != null) {
|
||||
// res.points.add(0, start);
|
||||
// }
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public void setReverse(boolean reverse) {
|
||||
this.reverse = reverse;
|
||||
}
|
||||
|
@ -189,7 +191,6 @@ public class RouteProvider {
|
|||
copy.prepareGPXFile(this);
|
||||
return copy.getPoints();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class GPXRouteParams {
|
||||
|
@ -228,19 +229,19 @@ public class RouteProvider {
|
|||
return null;
|
||||
}
|
||||
|
||||
public GPXRouteParams prepareGPXFile(GPXRouteParamsBuilder builder){
|
||||
public GPXRouteParams prepareGPXFile(GPXRouteParamsBuilder builder) {
|
||||
GPXFile file = builder.file;
|
||||
boolean reverse = builder.reverse;
|
||||
passWholeRoute = builder.passWholeRoute;
|
||||
calculateOsmAndRouteParts = builder.calculateOsmAndRouteParts;
|
||||
useIntermediatePointsRTE = builder.useIntermediatePointsRTE;
|
||||
builder.calculateOsmAndRoute = false; // Disabled temporary builder.calculateOsmAndRoute;
|
||||
if(!file.points.isEmpty()) {
|
||||
wpt = new ArrayList<LocationPoint>(file.points );
|
||||
if (!file.points.isEmpty()) {
|
||||
wpt = new ArrayList<LocationPoint>(file.points);
|
||||
}
|
||||
if(file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)){
|
||||
if (file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)) {
|
||||
directions = parseOsmAndGPXRoute(points, file, OSMAND_ROUTER.equals(file.author), builder.leftSide, 10);
|
||||
if(reverse){
|
||||
if (reverse) {
|
||||
// clear directions all turns should be recalculated
|
||||
directions = null;
|
||||
Collections.reverse(points);
|
||||
|
@ -269,7 +270,6 @@ public class RouteProvider {
|
|||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Location createLocation(WptPt pt){
|
||||
|
@ -287,9 +287,6 @@ public class RouteProvider {
|
|||
return loc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public RouteCalculationResult calculateRouteImpl(RouteCalculationParams params){
|
||||
long time = System.currentTimeMillis();
|
||||
if (params.start != null && params.end != null) {
|
||||
|
@ -382,9 +379,6 @@ public class RouteProvider {
|
|||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private RouteCalculationResult calculateOsmAndRouteWithIntermediatePoints(RouteCalculationParams routeParams,
|
||||
final List<Location> intermediates) throws IOException {
|
||||
RouteCalculationParams rp = new RouteCalculationParams();
|
||||
|
@ -417,9 +411,6 @@ public class RouteProvider {
|
|||
return findVectorMapsRoute(rp, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private List<RouteDirectionInfo> calcDirections(int[] startI, int[] endI,
|
||||
final List<RouteDirectionInfo> inputDirections) {
|
||||
List<RouteDirectionInfo> directions = new ArrayList<RouteDirectionInfo>();
|
||||
|
@ -451,9 +442,6 @@ public class RouteProvider {
|
|||
return directions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void insertFinalSegment(RouteCalculationParams routeParams, List<Location> points,
|
||||
List<RouteDirectionInfo> directions, boolean calculateOsmAndRouteParts) {
|
||||
if(points.size() > 0) {
|
||||
|
@ -578,9 +566,6 @@ public class RouteProvider {
|
|||
return ctx.getString(resId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected RouteCalculationResult findYOURSRoute(RouteCalculationParams params) throws MalformedURLException, IOException,
|
||||
ParserConfigurationException, FactoryConfigurationError, SAXException {
|
||||
List<Location> res = new ArrayList<Location>();
|
||||
|
@ -728,9 +713,6 @@ public class RouteProvider {
|
|||
return calcOfflineRouteImpl(params, router, ctx, complexCtx, st, en, inters, precalculated);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private RoutingConfiguration initOsmAndRoutingConfig(Builder config, final RouteCalculationParams params, OsmandSettings settings,
|
||||
GeneralRouter generalRouter) throws IOException, FileNotFoundException {
|
||||
GeneralRouterProfile p ;
|
||||
|
@ -775,9 +757,6 @@ public class RouteProvider {
|
|||
return cf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private RouteCalculationResult calcOfflineRouteImpl(final RouteCalculationParams params,
|
||||
RoutePlannerFrontEnd router, RoutingContext ctx, RoutingContext complexCtx, LatLon st, LatLon en,
|
||||
List<LatLon> inters, PrecalculatedRouteDirection precalculated) throws IOException {
|
||||
|
@ -840,9 +819,6 @@ public class RouteProvider {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private RouteCalculationResult applicationModeNotSupported(RouteCalculationParams params) {
|
||||
return new RouteCalculationResult("Application mode '"+ params.mode.toHumanStringCtx(params.ctx)+ "'is not supported.");
|
||||
}
|
||||
|
@ -855,8 +831,6 @@ public class RouteProvider {
|
|||
return new RouteCalculationResult("Empty result");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static List<RouteDirectionInfo> parseOsmAndGPXRoute(List<Location> res, GPXFile gpxFile, boolean osmandRouter,
|
||||
boolean leftSide, float defSpeed) {
|
||||
List<RouteDirectionInfo> directions = null;
|
||||
|
@ -1054,7 +1028,7 @@ public class RouteProvider {
|
|||
return new RouteCalculationResult(res, null, params, null);
|
||||
}
|
||||
|
||||
public GPXFile createOsmandRouterGPX(RouteCalculationResult srcRoute, OsmandApplication ctx){
|
||||
public GPXFile createOsmandRouterGPX(RouteCalculationResult srcRoute, OsmandApplication ctx) {
|
||||
TargetPointsHelper helper = ctx.getTargetPointsHelper();
|
||||
int currentRoute = srcRoute.currentRoute;
|
||||
List<Location> routeNodes = srcRoute.getImmutableAllLocations();
|
||||
|
@ -1079,18 +1053,18 @@ public class RouteProvider {
|
|||
trkSegment.points.add(startpoint);
|
||||
}
|
||||
|
||||
for(int i = cRoute; i< routeNodes.size(); i++){
|
||||
for (int i = cRoute; i< routeNodes.size(); i++) {
|
||||
Location loc = routeNodes.get(i);
|
||||
WptPt pt = new WptPt();
|
||||
pt.lat = loc.getLatitude();
|
||||
pt.lon = loc.getLongitude();
|
||||
if(loc.hasSpeed()){
|
||||
if (loc.hasSpeed()) {
|
||||
pt.speed = loc.getSpeed();
|
||||
}
|
||||
if(loc.hasAltitude()){
|
||||
if (loc.hasAltitude()) {
|
||||
pt.ele = loc.getAltitude();
|
||||
}
|
||||
if(loc.hasAccuracy()){
|
||||
if (loc.hasAccuracy()) {
|
||||
pt.hdop = loc.getAccuracy();
|
||||
}
|
||||
trkSegment.points.add(pt);
|
||||
|
@ -1108,7 +1082,7 @@ public class RouteProvider {
|
|||
Map<String, String> extensions = pt.getExtensionsToWrite();
|
||||
extensions.put("time", dirInfo.getExpectedTime() + "");
|
||||
int turnType = dirInfo.getTurnType().getValue();
|
||||
if(TurnType.C != turnType){
|
||||
if (TurnType.C != turnType) {
|
||||
extensions.put("turn", dirInfo.getTurnType().toXmlString());
|
||||
extensions.put("turn-angle", dirInfo.getTurnType().getTurnAngle() + "");
|
||||
}
|
||||
|
@ -1129,23 +1103,23 @@ public class RouteProvider {
|
|||
}
|
||||
}
|
||||
List<TargetPoint> ps = helper.getIntermediatePointsWithTarget();
|
||||
for(int k = 0; k < ps.size(); k++) {
|
||||
for (int k = 0; k < ps.size(); k++) {
|
||||
WptPt pt = new WptPt();
|
||||
pt.lat = ps.get(k).getLatitude();
|
||||
pt.lon = ps.get(k).getLongitude();
|
||||
if(k < ps.size()) {
|
||||
if (k < ps.size()) {
|
||||
pt.name = ps.get(k).getOnlyName() +"";
|
||||
if(k == ps.size() - 1) {
|
||||
String target = ctx.getString(R.string.destination_point, "" );
|
||||
if(pt.name.startsWith(target)) {
|
||||
pt.name = ctx.getString(R.string.destination_point, pt.name );
|
||||
if (k == ps.size() - 1) {
|
||||
String target = ctx.getString(R.string.destination_point, "");
|
||||
if (pt.name.startsWith(target)) {
|
||||
pt.name = ctx.getString(R.string.destination_point, pt.name);
|
||||
}
|
||||
} else {
|
||||
String prefix = (k + 1) +". ";
|
||||
if(Algorithms.isEmpty(pt.name)) {
|
||||
pt.name = ctx.getString(R.string.target_point, pt.name );
|
||||
pt.name = ctx.getString(R.string.target_point, pt.name);
|
||||
}
|
||||
if(pt.name.startsWith(prefix)) {
|
||||
if (pt.name.startsWith(prefix)) {
|
||||
pt.name = prefix + pt.name;
|
||||
}
|
||||
}
|
||||
|
@ -1156,11 +1130,11 @@ public class RouteProvider {
|
|||
return gpx;
|
||||
}
|
||||
|
||||
|
||||
private void appendOSRMLoc(StringBuilder uri, LatLon il) {
|
||||
uri.append("&loc=").append(String.valueOf(il.getLatitude()));
|
||||
uri.append(",").append(String.valueOf(il.getLongitude()));
|
||||
}
|
||||
|
||||
protected RouteCalculationResult findOSRMRoute(RouteCalculationParams params)
|
||||
throws MalformedURLException, IOException, JSONException {
|
||||
// https://router.project-osrm.org/viaroute?loc=52.28,4.83&loc=52.35,4.95&alt=false&output=gpx
|
||||
|
@ -1214,7 +1188,6 @@ public class RouteProvider {
|
|||
return new RouteCalculationResult(res, null, params, null);
|
||||
}
|
||||
|
||||
|
||||
protected RouteCalculationResult findBROUTERRoute(RouteCalculationParams params) throws MalformedURLException,
|
||||
IOException, ParserConfigurationException, FactoryConfigurationError, SAXException {
|
||||
int numpoints = 2 + (params.intermediates != null ? params.intermediates.size() : 0);
|
||||
|
@ -1251,7 +1224,6 @@ public class RouteProvider {
|
|||
OsmandApplication ctx = (OsmandApplication) params.ctx;
|
||||
List<Location> res = new ArrayList<Location>();
|
||||
|
||||
|
||||
IBRouterService brouterService = ctx.getBRouterService();
|
||||
if (brouterService == null) {
|
||||
return new RouteCalculationResult("BRouter service is not available");
|
||||
|
@ -1329,5 +1301,4 @@ public class RouteProvider {
|
|||
dots.add(location);
|
||||
return new RouteCalculationResult(dots, null, params, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue