Added a method to get WorldRegions by latlon

This commit is contained in:
PaulStets 2018-05-13 14:03:45 +03:00
parent d89b3a1797
commit ecb25c835d
2 changed files with 49 additions and 46 deletions

View file

@ -695,11 +695,51 @@ public class OsmandRegions {
}
}
public BinaryMapDataObject findBinaryMapDataObject(LatLon latLon) throws IOException {
public List<WorldRegion> getWoldRegions(LatLon latLon) {
List<WorldRegion> result = new ArrayList<>();
List<BinaryMapDataObject> 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<BinaryMapDataObject> 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<BinaryMapDataObject> getBinaryMapDataObjects(LatLon latLon) throws IOException {
int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
BinaryMapDataObject res = null;
List<BinaryMapDataObject> 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;
}
}

View file

@ -459,40 +459,15 @@ public class DownloadResources extends DownloadResourceGroup {
return findIndexItemsAt(app, latLon, type, false);
}
public static List<IndexItem> findIndexItemsAt(OsmandApplication app, LatLon latLon, DownloadActivityType type, boolean includeDownloaded) throws IOException {
public static List<IndexItem> findIndexItemsAt(OsmandApplication app, LatLon latLon, DownloadActivityType type, boolean includeDownloaded) {
List<IndexItem> res = new ArrayList<>();
OsmandRegions regions = app.getRegions();
DownloadIndexesThread downloadThread = app.getDownloadThread();
int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
List<BinaryMapDataObject> mapDataObjects;
try {
mapDataObjects = regions.queryBbox(point31x, point31x, point31y, point31y);
} catch (IOException e) {
throw new IOException("Error while calling queryBbox");
}
if (mapDataObjects != null) {
Iterator<BinaryMapDataObject> 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<WorldRegion> downloadRegions = regions.getWoldRegions(latLon);
for (WorldRegion downloadRegion : downloadRegions) {
if (downloadRegion != null) {
if (includeDownloaded || !isIndexItemDownloaded(downloadThread, type, downloadRegion, res)) {
addIndexItem(downloadThread, type, downloadRegion, res);
}
}
}