diff --git a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java index bc07bb87a5..22aa6eb7dc 100644 --- a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java +++ b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java @@ -695,11 +695,51 @@ public class OsmandRegions { } } - public BinaryMapDataObject findBinaryMapDataObject(LatLon latLon) throws IOException { + public List getWoldRegions(LatLon latLon) { + List result = new ArrayList<>(); + List mapDataObjects = null; + try { + mapDataObjects = getBinaryMapDataObjects(latLon); + } catch (IOException e) { + e.printStackTrace(); + } + if (mapDataObjects != null) { + for (BinaryMapDataObject obj : mapDataObjects) { + result.add(getRegionData(getFullName(obj))); + } + } + return result; + } + + public BinaryMapDataObject findBinaryMapDataObject(LatLon latLon) { + List mapDataObjects = null; + try { + mapDataObjects = getBinaryMapDataObjects(latLon); + } catch (IOException e) { + e.printStackTrace(); + } + BinaryMapDataObject res = null; + double smallestArea = -1; + if (mapDataObjects != null) { + for (BinaryMapDataObject o : mapDataObjects) { + double area = OsmandRegions.getArea(o); + if (smallestArea == -1) { + smallestArea = area; + res = o; + } else if (area < smallestArea) { + smallestArea = area; + res = o; + } + } + } + + return res; + } + + private List getBinaryMapDataObjects(LatLon latLon) throws IOException { int point31x = MapUtils.get31TileNumberX(latLon.getLongitude()); int point31y = MapUtils.get31TileNumberY(latLon.getLatitude()); - BinaryMapDataObject res = null; List mapDataObjects; try { mapDataObjects = queryBbox(point31x, point31x, point31y, point31y); @@ -729,19 +769,7 @@ public class OsmandRegions { } } } - double smallestArea = -1; - for (BinaryMapDataObject o : mapDataObjects) { - double area = OsmandRegions.getArea(o); - if (smallestArea == -1) { - smallestArea = area; - res = o; - } else if (area < smallestArea) { - smallestArea = area; - res = o; - } - } } - return res; + return mapDataObjects; } - } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 4d1bceee13..1548b7f3d6 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -459,40 +459,15 @@ public class DownloadResources extends DownloadResourceGroup { return findIndexItemsAt(app, latLon, type, false); } - public static List findIndexItemsAt(OsmandApplication app, LatLon latLon, DownloadActivityType type, boolean includeDownloaded) throws IOException { - + public static List findIndexItemsAt(OsmandApplication app, LatLon latLon, DownloadActivityType type, boolean includeDownloaded) { List res = new ArrayList<>(); OsmandRegions regions = app.getRegions(); DownloadIndexesThread downloadThread = app.getDownloadThread(); - - int point31x = MapUtils.get31TileNumberX(latLon.getLongitude()); - int point31y = MapUtils.get31TileNumberY(latLon.getLatitude()); - - List mapDataObjects; - try { - mapDataObjects = regions.queryBbox(point31x, point31x, point31y, point31y); - } catch (IOException e) { - throw new IOException("Error while calling queryBbox"); - } - if (mapDataObjects != null) { - Iterator it = mapDataObjects.iterator(); - while (it.hasNext()) { - BinaryMapDataObject o = it.next(); - if (o.getTypes() != null) { - boolean isRegion = true; - for (int i = 0; i < o.getTypes().length; i++) { - BinaryMapIndexReader.TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]); - if ("boundary".equals(tp.value)) { - isRegion = false; - break; - } - } - WorldRegion downloadRegion = regions.getRegionData(regions.getFullName(o)); - if (downloadRegion != null && isRegion && regions.contain(o, point31x, point31y)) { - if (includeDownloaded || !isIndexItemDownloaded(downloadThread, type, downloadRegion, res)) { - addIndexItem(downloadThread, type, downloadRegion, res); - } - } + List downloadRegions = regions.getWoldRegions(latLon); + for (WorldRegion downloadRegion : downloadRegions) { + if (downloadRegion != null) { + if (includeDownloaded || !isIndexItemDownloaded(downloadThread, type, downloadRegion, res)) { + addIndexItem(downloadThread, type, downloadRegion, res); } } }