use of net.osmand.router.NativeTransportRoutingResult in project OsmAnd-tools by osmandapp.
the class MapTransportLayer method buildRoute.
public void buildRoute(boolean schedule) {
long time = System.currentTimeMillis();
if (start != null && end != null) {
try {
BinaryMapIndexReader[] files = DataExtractionSettings.getSettings().getObfReaders();
if (files.length == 0) {
JOptionPane.showMessageDialog(OsmExtractionUI.MAIN_APP.getFrame(), "Please specify obf file in settings", "Obf file not found", JOptionPane.ERROR_MESSAGE);
return;
}
System.out.println("Transport route from " + start + " to " + end);
Builder builder = DataExtractionSettings.getSettings().getRoutingConfig();
String m = DataExtractionSettings.getSettings().getRouteMode();
String[] props = m.split("\\,");
Map<String, String> paramsR = new LinkedHashMap<String, String>();
for (String p : props) {
if (p.contains("=")) {
paramsR.put(p.split("=")[0], p.split("=")[1]);
} else {
paramsR.put(p, "true");
}
}
GeneralRouter prouter = builder.getRouter("public_transport");
TransportRoutingConfiguration cfg = new TransportRoutingConfiguration(prouter, paramsR);
cfg.useSchedule = schedule;
TransportRoutePlanner planner = new TransportRoutePlanner();
TransportRoutingContext ctx = new TransportRoutingContext(cfg, DataExtractionSettings.getSettings().useNativeRouting() ? NativeSwingRendering.getDefaultFromSettings() : null, files);
if (ctx.library != null) {
NativeTransportRoutingResult[] nativeRes = ctx.library.runNativePTRouting(MapUtils.get31TileNumberX(start.getLongitude()), MapUtils.get31TileNumberY(start.getLatitude()), MapUtils.get31TileNumberX(end.getLongitude()), MapUtils.get31TileNumberY(end.getLatitude()), cfg, ctx.calculationProgress);
if (nativeRes.length > 0) {
this.results = TransportRoutePlanner.convertToTransportRoutingResult(nativeRes, cfg);
} else {
System.out.println("No luck, empty result from Native");
}
} else {
startProgressThread(ctx);
this.results = planner.buildRoute(ctx, start, end);
}
this.currentRoute = 0;
throwExceptionIfRouteNotFound(ctx, results);
} catch (Exception e) {
ExceptionHandler.handle(e);
} finally {
infoButton.setVisible(false);
prevRoute.setVisible(false);
nextRoute.setVisible(false);
if (map.getPoints() != null) {
map.getPoints().clear();
}
}
System.out.println("Finding self routes " + results.size() + " " + (System.currentTimeMillis() - time) + " ms");
}
return;
}
Aggregations