From 1129316ff6694a127d309960ee25e54dc6d902c7 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 10 Aug 2016 22:03:22 +0200 Subject: [PATCH] Fix processing error --- .../osmand/binary/BinaryMapIndexReader.java | 76 ++----------------- 1 file changed, 8 insertions(+), 68 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java index 0989e7cad0..19815a24f1 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java @@ -818,14 +818,20 @@ public class BinaryMapIndexReader { } } - public List searchMapIndex(SearchRequest req) throws IOException { + return searchMapIndex(req, null); + } + + public List searchMapIndex(SearchRequest req, MapIndex filterMapIndex) throws IOException { req.numberOfVisitedObjects = 0; req.numberOfAcceptedObjects = 0; req.numberOfAcceptedSubtrees = 0; req.numberOfReadSubtrees = 0; List foundSubtrees = new ArrayList(); for (MapIndex mapIndex : mapIndexes) { + if(filterMapIndex == null || mapIndex == filterMapIndex) { + continue; + } // lazy initializing rules if (mapIndex.encodingRules.isEmpty()) { codedIS.seek(mapIndex.filePointer); @@ -885,73 +891,7 @@ public class BinaryMapIndexReader { return req.getSearchResults(); } - public List searchMapIndex(SearchRequest req, MapIndex mapIndex) throws IOException { - req.numberOfVisitedObjects = 0; - req.numberOfAcceptedObjects = 0; - req.numberOfAcceptedSubtrees = 0; - req.numberOfReadSubtrees = 0; - List foundSubtrees = new ArrayList(); - - // lazy initializing rules - if (mapIndex.encodingRules.isEmpty()) { - codedIS.seek(mapIndex.filePointer); - int oldLimit = codedIS.pushLimit(mapIndex.length); - readMapIndex(mapIndex, true); - codedIS.popLimit(oldLimit); - } - - for (MapRoot level : mapIndex.getRoots()) { - if ((level.minZoom <= req.zoom && level.maxZoom >= req.zoom) || req.zoom == -1) { - if (level.right < req.left || level.left > req.right || level.top > req.bottom || level.bottom < req.top) { - continue; - } - - // lazy initializing trees - if (level.trees == null) { - level.trees = new ArrayList(); - codedIS.seek(level.filePointer); - int oldLimit = codedIS.pushLimit(level.length); - readMapLevel(level); - codedIS.popLimit(oldLimit); - } - - for (MapTree tree : level.trees) { - if (tree.right < req.left || tree.left > req.right || tree.top > req.bottom || tree.bottom < req.top) { - continue; - } - codedIS.seek(tree.filePointer); - int oldLimit = codedIS.pushLimit(tree.length); - searchMapTreeBounds(tree, level, req, foundSubtrees); - codedIS.popLimit(oldLimit); - } - - Collections.sort(foundSubtrees, new Comparator() { - @Override - public int compare(MapTree o1, MapTree o2) { - return o1.mapDataBlock < o2.mapDataBlock ? -1 : (o1.mapDataBlock == o2.mapDataBlock ? 0 : 1); - } - }); - for (MapTree tree : foundSubtrees) { - if (!req.isCancelled()) { - codedIS.seek(tree.mapDataBlock); - int length = codedIS.readRawVarint32(); - int oldLimit = codedIS.pushLimit(length); - readMapDataBlocks(req, tree, mapIndex); - codedIS.popLimit(oldLimit); - } - } - foundSubtrees.clear(); - } - - } - - - if (req.numberOfVisitedObjects > 0) { - log.info("Search is done. Visit " + req.numberOfVisitedObjects + " objects. Read " + req.numberOfAcceptedObjects + " objects."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - log.info("Read " + req.numberOfReadSubtrees + " subtrees. Go through " + req.numberOfAcceptedSubtrees + " subtrees."); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ - } - return req.getSearchResults(); - } + protected void readMapDataBlocks(SearchRequest req, MapTree tree, MapIndex root) throws IOException { List tempResults = null;