remove outdated OSRM code and small refactoring

This commit is contained in:
nazar-kutz 2021-01-10 23:51:02 +02:00
parent 170deedad4
commit d6bfe96014
5 changed files with 6 additions and 72 deletions

View file

@ -25,7 +25,6 @@ public class OnlineRoutingEngine {
private String stringKey;
private EngineType type;
private String customUrl;
private String vehicleKey;
private Map<String, String> params = new HashMap<>();
@ -61,6 +60,7 @@ public class OnlineRoutingEngine {
}
public String getBaseUrl() {
String customUrl = getParameter(EngineParameter.CUSTOM_URL);
if (Algorithms.isEmpty(customUrl)) {
return type.getStandardUrl();
}

View file

@ -29,11 +29,7 @@ public abstract class EngineType {
OnlineRoutingEngine engine,
List<LatLon> path);
public List<LatLon> parseResponse(@NonNull String content) throws JSONException {
return parseResponse(new JSONObject(content), content);
}
protected abstract List<LatLon> parseResponse(JSONObject obj, @NonNull String content) throws JSONException;
public abstract List<LatLon> parseResponse(@NonNull String content) throws JSONException;
public static EngineType[] values() {
EngineType[] types = new EngineType[] {

View file

@ -51,7 +51,8 @@ public class GraphhoperEngine extends EngineType {
}
@Override
protected List<LatLon> parseResponse(JSONObject obj, @NonNull String content) throws JSONException {
public List<LatLon> parseResponse(@NonNull String content) throws JSONException {
JSONObject obj = new JSONObject(content);
return GeoPolylineParserUtil.parse(
obj.getJSONArray("routes").getJSONObject(0).getString("geometry"),
GeoPolylineParserUtil.PRECISION_5);

View file

@ -43,7 +43,8 @@ public class OsrmEngine extends EngineType {
}
@Override
protected List<LatLon> parseResponse(@NonNull JSONObject obj, @NonNull String content) throws JSONException {
public List<LatLon> parseResponse(@NonNull String content) throws JSONException {
JSONObject obj = new JSONObject(content);
return GeoPolylineParserUtil.parse(
obj.getJSONArray("routes").getJSONObject(0).getString("geometry"),
GeoPolylineParserUtil.PRECISION_5);

View file

@ -368,10 +368,6 @@ public class RouteProvider {
res = findBROUTERRoute(params);
} else if (params.mode.getRouteService() == RouteService.ONLINE) {
res = findOnlineRoute(params);
// } else if (params.type == RouteService.ORS) {
// res = findORSRoute(params);
// } else if (params.type == RouteService.OSRM) {
// res = findOSRMRoute(params);
} else if (params.mode.getRouteService() == RouteService.STRAIGHT ||
params.mode.getRouteService() == RouteService.DIRECT_TO) {
res = findStraightRoute(params);
@ -1240,66 +1236,6 @@ public class RouteProvider {
return points;
}
private void appendOSRMLoc(StringBuilder uri, LatLon il) {
uri.append(";").append(il.getLongitude());
uri.append(",").append(il.getLatitude());
}
protected RouteCalculationResult findOSRMRoute(RouteCalculationParams params)
throws MalformedURLException, IOException, JSONException {
// http://router.project-osrm.org/route/v1/driving/4.83,52.28;4.95,52.28
List<Location> res = new ArrayList<Location>();
StringBuilder uri = new StringBuilder();
// possibly hide that API key because it is privacy of osmand
// A6421860EBB04234AB5EF2D049F2CD8F key is compromised
String scheme = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
scheme = "https";
} else {
scheme = "http";
}
uri.append(scheme + "://router.project-osrm.org/route/v1/driving/"); //$NON-NLS-1$
uri.append(String.valueOf(params.start.getLongitude()));
uri.append(",").append(String.valueOf(params.start.getLatitude()));
if(params.intermediates != null && params.intermediates.size() > 0) {
for(LatLon il : params.intermediates) {
appendOSRMLoc(uri, il);
}
}
appendOSRMLoc(uri, params.end);
// to get more waypoints, add overview=full option
// uri.append("?overview=full")
log.info("URL route " + uri);
URLConnection connection = NetworkUtils.getHttpURLConnection(uri.toString());
connection.setRequestProperty("User-Agent", Version.getFullVersion(params.ctx));
StringBuilder content = new StringBuilder();
BufferedReader rs = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String s;
while((s = rs.readLine()) != null) {
content.append(s);
}
JSONObject obj = new JSONObject(content.toString());
try {
rs.close();
} catch(IOException e){
}
List<LatLon> route = GeoPolylineParserUtil.parse(obj.getJSONArray("routes").getJSONObject(0).getString("geometry"),
GeoPolylineParserUtil.PRECISION_5);
if (route.isEmpty()) {
return new RouteCalculationResult("Route is empty");
}
for (LatLon pt : route) {
WptPt wpt = new WptPt();
wpt.lat = pt.getLatitude();
wpt.lon = pt.getLongitude();
res.add(createLocation(wpt));
}
params.intermediates = null;
return new RouteCalculationResult(res, null, params, null, true);
}
protected RouteCalculationResult findBROUTERRoute(RouteCalculationParams params) throws MalformedURLException,
IOException, ParserConfigurationException, FactoryConfigurationError, SAXException {
int numpoints = 2 + (params.intermediates != null ? params.intermediates.size() : 0);