use of net.osmand.LocationsHolder in project OsmAnd-tools by osmandapp.
the class OsmAndMapsService method approximate.
private List<RouteSegmentResult> approximate(RoutingContext ctx, RoutePlannerFrontEnd router, Map<String, Object> props, List<LatLon> polyline) throws IOException, InterruptedException {
GpxRouteApproximation gctx = new GpxRouteApproximation(ctx);
List<GpxPoint> gpxPoints = router.generateGpxPoints(gctx, new LocationsHolder(polyline));
GpxRouteApproximation r = router.searchGpxRoute(gctx, gpxPoints, null);
List<RouteSegmentResult> route = new ArrayList<RouteSegmentResult>();
for (GpxPoint pnt : r.finalPoints) {
route.addAll(pnt.routeToTarget);
}
if (router.useNativeApproximation) {
RouteResultPreparation preparation = new RouteResultPreparation();
// preparation.prepareTurnResults(gctx.ctx, route);
preparation.addTurnInfoDescriptions(route);
}
putResultProps(ctx, route, props);
return route;
}
use of net.osmand.LocationsHolder in project OsmAnd-tools by osmandapp.
the class MapRouterLayer method selfRoute.
public List<Entity> selfRoute(LatLon start, LatLon end, List<LatLon> intermediates, boolean gpx, List<RouteSegmentResult> previousRoute, RouteCalculationMode rm) {
this.gpx = gpx;
List<Entity> res = new ArrayList<Entity>();
long time = System.currentTimeMillis();
final boolean animateRoutingCalculation = DataExtractionSettings.getSettings().isAnimateRouting();
if (animateRoutingCalculation) {
nextTurn.setVisible(true);
playPauseButton.setVisible(true);
stopButton.setVisible(true);
pause = true;
playPauseButton.setText("Play");
}
stop = false;
System.out.println("Self made route from " + start + " to " + end);
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 null;
}
String m = DataExtractionSettings.getSettings().getRouteMode();
String[] props = m.split("\\,");
RoutePlannerFrontEnd router = new RoutePlannerFrontEnd();
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");
}
}
RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(2000, DEFAULT_NATIVE_MEMORY_LIMIT * 10);
RoutingConfiguration config = DataExtractionSettings.getSettings().getRoutingConfig().setDirectionPoints(directionPointsFile).build(props[0], /* RoutingConfiguration.DEFAULT_MEMORY_LIMIT */
memoryLimit, paramsR);
PrecalculatedRouteDirection precalculatedRouteDirection = null;
// config.ZOOM_TO_LOAD_TILES = 14;
try {
config.routeCalculationTime = new SimpleDateFormat("dd.MM.yyyy HH:mm", Locale.US).parse("19.07.2019 12:40").getTime();
} catch (Exception e) {
}
config.routeCalculationTime = System.currentTimeMillis();
final RoutingContext ctx = router.buildRoutingContext(config, DataExtractionSettings.getSettings().useNativeRouting() ? NativeSwingRendering.getDefaultFromSettings() : null, files, rm);
ctx.leftSideNavigation = false;
ctx.previouslyCalculatedRoute = previousRoute;
log.info("Use " + config.routerName + " mode for routing");
final DataTileManager<Entity> points = map.getPoints();
map.setPoints(points);
ctx.setVisitor(createSegmentVisitor(animateRoutingCalculation, points));
// Choose native or not native
long nt = System.nanoTime();
startProgressThread(ctx);
try {
GpxRouteApproximation gctx = new GpxRouteApproximation(ctx);
List<GpxPoint> gpxPoints = router.generateGpxPoints(gctx, new LocationsHolder(intermediates));
List<RouteSegmentResult> searchRoute = gpx ? getGpxAproximation(router, gctx, gpxPoints) : router.searchRoute(ctx, start, end, intermediates, precalculatedRouteDirection);
throwExceptionIfRouteNotFound(ctx, searchRoute);
System.out.println("Routing time " + (System.nanoTime() - nt) / 1.0e9f);
if (animateRoutingCalculation) {
playPauseButton.setVisible(false);
nextTurn.setText("FINISH");
waitNextPress();
nextTurn.setText(">>");
}
this.previousRoute = searchRoute;
calculateResult(res, searchRoute);
} finally {
if (ctx.calculationProgress != null) {
ctx.calculationProgress.isCancelled = true;
}
}
} catch (Exception e) {
ExceptionHandler.handle(e);
} finally {
playPauseButton.setVisible(false);
nextTurn.setVisible(false);
stopButton.setVisible(false);
if (map.getPoints() != null) {
map.getPoints().clear();
}
}
System.out.println("!!! Finding self route: " + res.size() + " " + (System.currentTimeMillis() - time) + " ms");
}
return res;
}
Aggregations