Search in sources :

Example 1 with TransportRoutingContext

use of net.osmand.router.TransportRoutingContext 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;
}
Also used : TransportRoutingContext(net.osmand.router.TransportRoutingContext) Builder(net.osmand.router.RoutingConfiguration.Builder) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) GeneralRouter(net.osmand.router.GeneralRouter) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) NativeTransportRoutingResult(net.osmand.router.NativeTransportRoutingResult) TransportRoutingConfiguration(net.osmand.router.TransportRoutingConfiguration) TransportRoutePlanner(net.osmand.router.TransportRoutePlanner)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedHashMap (java.util.LinkedHashMap)1 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)1 GeneralRouter (net.osmand.router.GeneralRouter)1 NativeTransportRoutingResult (net.osmand.router.NativeTransportRoutingResult)1 Builder (net.osmand.router.RoutingConfiguration.Builder)1 TransportRoutePlanner (net.osmand.router.TransportRoutePlanner)1 TransportRoutingConfiguration (net.osmand.router.TransportRoutingConfiguration)1 TransportRoutingContext (net.osmand.router.TransportRoutingContext)1