From eff51518ce8562510105400ca9b7d7339db8964e Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 31 May 2015 23:34:29 +0200 Subject: [PATCH] Fix issue with route calculation --- .../plus/render/MapRenderRepositories.java | 37 +++++++++++-------- .../osmand/plus/routing/RouteProvider.java | 21 +++++++++++ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 4922cd5f8b..ae95c2f84f 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -258,21 +258,7 @@ public class MapRenderRepositories { long now = System.currentTimeMillis(); // check that everything is initialized - for (String mapName : files.keySet()) { - BinaryMapIndexReader fr = files.get(mapName); - if (fr != null && (fr.containsMapData(leftX, topY, rightX, bottomY, zoom) || - fr.containsRouteData(leftX, topY, rightX, bottomY, zoom))) { - if (!nativeFiles.contains(mapName)) { - long time = System.currentTimeMillis(); - nativeFiles.add(mapName); - if (!library.initMapFile(mapName)) { - continue; - } - log.debug("Native resource " + mapName + " initialized " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } - + checkInitialized(zoom, library, leftX, rightX, bottomY, topY); NativeSearchResult resultHandler = library.searchObjectsForRendering(leftX, rightX, topY, bottomY, zoom, renderingReq, checkForDuplicateObjectIds, this, ""); if (checkWhetherInterrupted()) { @@ -290,6 +276,27 @@ public class MapRenderRepositories { log.info(String.format("Native search: %s ms ", System.currentTimeMillis() - now)); //$NON-NLS-1$ return true; } + + public void checkInitialized(final int zoom, NativeOsmandLibrary library, int leftX, int rightX, int bottomY, + int topY) { + if(library == null) { + return; + } + for (String mapName : files.keySet()) { + BinaryMapIndexReader fr = files.get(mapName); + if (fr != null && (fr.containsMapData(leftX, topY, rightX, bottomY, zoom) || + fr.containsRouteData(leftX, topY, rightX, bottomY, zoom))) { + if (!nativeFiles.contains(mapName)) { + long time = System.currentTimeMillis(); + nativeFiles.add(mapName); + if (!library.initMapFile(mapName)) { + continue; + } + log.debug("Native resource " + mapName + " initialized " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + } + } private void readRouteDataAsMapObjects(SearchRequest sr, BinaryMapIndexReader c, final ArrayList tempResult, final TLongSet ids) { diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 7ebda89056..fe661800b2 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -656,6 +656,27 @@ public class RouteProvider { } // BUILD context NativeOsmandLibrary lib = settings.SAFE_MODE.get() ? null : NativeOsmandLibrary.getLoadedLibrary(); + // check loaded files + int leftX = MapUtils.get31TileNumberX(params.start.getLongitude()); + int rightX = leftX; + int bottomY = MapUtils.get31TileNumberY(params.start.getLatitude()); + int topY = bottomY; + if (params.intermediates != null) { + for (LatLon l : params.intermediates) { + leftX = Math.min(MapUtils.get31TileNumberX(l.getLongitude()), leftX); + rightX = Math.max(MapUtils.get31TileNumberX(l.getLongitude()), rightX); + bottomY = Math.max(MapUtils.get31TileNumberY(l.getLatitude()), bottomY); + topY = Math.min(MapUtils.get31TileNumberY(l.getLatitude()), topY); + } + } + LatLon l = params.end; + leftX = Math.min(MapUtils.get31TileNumberX(l.getLongitude()), leftX); + rightX = Math.max(MapUtils.get31TileNumberX(l.getLongitude()), rightX); + bottomY = Math.max(MapUtils.get31TileNumberY(l.getLatitude()), bottomY); + topY = Math.min(MapUtils.get31TileNumberY(l.getLatitude()), topY); + + params.ctx.getResourceManager().getRenderer().checkInitialized(15, lib, leftX, rightX, bottomY, topY); + RoutingContext ctx = router.buildRoutingContext(cf, lib, files, RouteCalculationMode.NORMAL);