diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java index b7fc3d03e66..9279b0e7671 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java @@ -12,6 +12,7 @@ import gnu.trove.list.array.TIntArrayList; import gnu.trove.map.hash.TLongObjectHashMap; +import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.TransportRoute; @@ -22,6 +23,8 @@ import net.osmand.osm.edit.Way; import net.osmand.util.MapUtils; +import org.apache.commons.logging.Log; + public class TransportRoutePlanner { private static final boolean MEASURE_TIME = false; @@ -29,6 +32,7 @@ public class TransportRoutePlanner { private static final int MIN_DIST_STOP_TO_GEOMETRY = 150; public static final long GEOMETRY_WAY_ID = -1; public static final long STOPS_WAY_ID = -2; + private final static Log LOG = PlatformUtil.getLog(TransportRoutePlanner.class); public List buildRoute(TransportRoutingContext ctx, LatLon start, LatLon end) throws IOException, InterruptedException { ctx.startCalcTime = System.currentTimeMillis(); @@ -41,6 +45,7 @@ public List buildRoute(TransportRoutingContext ctx, LatLon endSegments.put(s.getId(), s); } if(startStops.size() == 0) { + LOG.info("Public transport. Start stop is empty"); return Collections.emptyList(); } PriorityQueue queue = new PriorityQueue(startStops.size(), new SegmentsComparator(ctx)); @@ -581,6 +586,7 @@ public static List convertToTransportRoutingResult(NativeT TLongObjectHashMap convertedStopsCache = new TLongObjectHashMap<>(); if (res.length == 0) { + LOG.info("Public transport. No route found"); return new ArrayList(); } List convertedRes = new ArrayList(); diff --git a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java index 07cfa281fda..d0ba9c25218 100644 --- a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java @@ -14,7 +14,6 @@ import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.ValueHolder; -import net.osmand.map.WorldRegion; import net.osmand.osm.edit.Node; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -225,8 +224,12 @@ private void recalculateRouteInBackground(LatLon start, LatLon end) { private void startRouteCalculationThread(TransportRouteCalculationParams params) { synchronized (this) { app.getSettings().LAST_ROUTE_APPLICATION_MODE.set(routingHelper.getAppMode()); - RouteRecalculationTask newTask = new RouteRecalculationTask(this, params, - app.getSettings().SAFE_MODE.get() ? null : NativeOsmandLibrary.getLoadedLibrary()); + NativeOsmandLibrary library = null; + if (!app.getSettings().SAFE_MODE.get()) { + library = NativeOsmandLibrary.getLoadedLibrary(); + initNativeRouteFiles(params); + } + RouteRecalculationTask newTask = new RouteRecalculationTask(this, params, library); lastTask = newTask; startProgress(params); updateProgress(params); @@ -235,6 +238,21 @@ private void startRouteCalculationThread(TransportRouteCalculationParams params) } } + private void initNativeRouteFiles(TransportRouteCalculationParams params) { + NativeOsmandLibrary library = NativeOsmandLibrary.getLoadedLibrary(); + if (library == null) { + return; + } + QuadRect bbox = new QuadRect(); + MapUtils.insetLatLonRect(bbox, params.start.getLatitude(), params.start.getLongitude()); + MapUtils.insetLatLonRect(bbox, params.end.getLatitude(), params.end.getLongitude()); + int leftX = MapUtils.get31TileNumberX(bbox.left); + int rightX = MapUtils.get31TileNumberX(bbox.right); + int topY = MapUtils.get31TileNumberY(bbox.top); + int bottomY = MapUtils.get31TileNumberY(bbox.bottom); + params.ctx.getResourceManager().getRenderer().checkInitialized(15, library, leftX, rightX, bottomY, topY); + } + public void setProgressBar(TransportRouteCalculationProgressCallback progressRoute) { this.progressRoute = progressRoute; } @@ -512,6 +530,7 @@ private List calculateRouteImpl(TransportRouteCalculationP TransportRoutingContext ctx = new TransportRoutingContext(cfg, library, files); ctx.calculationProgress = params.calculationProgress; if (ctx.library != null && !settings.PT_SAFE_MODE.get()) { + log.info("Public transport. Use native library"); NativeTransportRoutingResult[] nativeRes = library.runNativePTRouting( MapUtils.get31TileNumberX(params.start.getLongitude()), MapUtils.get31TileNumberY(params.start.getLatitude()), @@ -520,6 +539,7 @@ private List calculateRouteImpl(TransportRouteCalculationP cfg, ctx.calculationProgress); return TransportRoutePlanner.convertToTransportRoutingResult(nativeRes, cfg); } else { + log.info("Public transport. No native library present"); TransportRoutePlanner planner = new TransportRoutePlanner(); return planner.buildRoute(ctx, params.start, params.end); }