Add regions download

This commit is contained in:
vshcherb 2013-09-24 21:41:04 +02:00
parent 19ce935266
commit 7e5414e527
3 changed files with 103 additions and 72 deletions

View file

@ -269,6 +269,7 @@ public class OsmandRegions {
testCountry(or, 28.8056, 29.9858, "africa", "egypt" ); testCountry(or, 28.8056, 29.9858, "africa", "egypt" );
testCountry(or, 35.7521, 139.7887, "japan"); testCountry(or, 35.7521, 139.7887, "japan");
testCountry(or, 46.5145, 102.2580, "mongolia"); testCountry(or, 46.5145, 102.2580, "mongolia");
testCountry(or, 62.54, 43.36, "arkhangelsk", "northwestern-federal-district");
} }

View file

@ -106,21 +106,41 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
results.values = indexFiles; results.values = indexFiles;
results.count = indexFiles.size(); results.count = indexFiles.size();
} else { } else {
String[] vars = constraint.toString().split("\\s"); String[] ors = constraint.toString().split("\\,");
for (int i = 0; i < vars.length; i++) { List<List<String>> conds = new ArrayList<List<String>>();
vars[i] = vars[i].trim().toLowerCase(); for(String or : ors) {
final ArrayList<String> cond = new ArrayList<String>();
for(String term : or.split("\\s")) {
final String t = term.trim().toLowerCase();
if(t.length() > 0) {
cond.add(t);
}
}
if(cond.size() > 0) {
conds.add(cond);
}
} }
List<IndexItem> filter = new ArrayList<IndexItem>(); List<IndexItem> filter = new ArrayList<IndexItem>();
ClientContext c = downloadActivity.getMyApplication(); ClientContext c = downloadActivity.getMyApplication();
for (IndexItem item : indexFiles) { for (IndexItem item : indexFiles) {
boolean add = true; boolean add = true;
for (String var : vars) { final String visibleName = item.getVisibleName(c).toLowerCase();
if (var.length() > 0) { for(List<String> or : conds) {
if (!item.getVisibleName(c).toLowerCase().contains(var) boolean tadd = true;
for (String var : or) {
if (!visibleName.contains(var)
/*&& !item.getDescription().toLowerCase().contains(var)*/) { /*&& !item.getDescription().toLowerCase().contains(var)*/) {
add = false; tadd = false;
break;
} }
} }
if(!tadd) {
add = false;
} else {
add = true;
break;
}
} }
if (add) { if (add) {
filter.add(item); filter.add(item);

View file

@ -122,63 +122,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
float w = Math.abs(latLonBox.width() / 2); float w = Math.abs(latLonBox.width() / 2);
float h = Math.abs(latLonBox.height() / 2); float h = Math.abs(latLonBox.height() / 2);
final RectF rf = new RectF(latLonBox.left - w, latLonBox.top + h, latLonBox.right + w, latLonBox.bottom - h); final RectF rf = new RectF(latLonBox.left - w, latLonBox.top + h, latLonBox.right + w, latLonBox.bottom - h);
AsyncTask<Object, Object, List<BinaryMapDataObject>> task = new AsyncTask<Object, Object, List<BinaryMapDataObject>>() { AsyncTask<Object, Object, List<BinaryMapDataObject>> task = createNewTask(zoom, rf);
@Override
protected List<BinaryMapDataObject> doInBackground(Object... params) {
if (queriedBBox.contains(rf)) {
return null;
}
if(zoom < ZOOM_TO_SHOW_MAP_NAMES) {
basemapExists = rm.getRenderer().basemapExists();
}
List<BinaryMapDataObject> result = null;
int left = MapUtils.get31TileNumberX(rf.left);
int right = MapUtils.get31TileNumberX(rf.right);
int top = MapUtils.get31TileNumberY(rf.top);
int bottom = MapUtils.get31TileNumberY(rf.bottom);
final boolean empty = rm.getRenderer().checkIfMapIsEmpty(left, right, top, bottom, zoom);
noMapsPresent = empty;
if(!empty && zoom >= ZOOM_TO_SHOW_MAP_NAMES) {
return Collections.emptyList();
}
try {
result = osmandRegions.queryBbox(left, right, top, bottom);
} catch (IOException e) {
return result;
}
Iterator<BinaryMapDataObject> it = result.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
if (zoom < ZOOM_TO_SHOW_BORDERS) {
//
} else {
if (!osmandRegions.contain(o, left / 2 + right / 2, top / 2 + bottom / 2)) {
it.remove();
}
}
}
return result;
}
@Override
protected void onPreExecute() {
currentTask = this;
}
@Override
protected void onPostExecute(List<BinaryMapDataObject> result) {
if (result != null) {
queriedBBox = rf;
objectsToDraw = result;
queriedZoom = zoom;
}
currentTask = null;
if (pendingTask != null) {
pendingTask.execute();
pendingTask = null;
}
}
};
if (currentTask == null) { if (currentTask == null) {
task.execute(); task.execute();
} else { } else {
@ -190,20 +134,25 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
if (zoom >= ZOOM_TO_SHOW_MAP_NAMES) { if (zoom >= ZOOM_TO_SHOW_MAP_NAMES) {
StringBuilder s = new StringBuilder(view.getResources().getString(R.string.download_files)); StringBuilder s = new StringBuilder(view.getResources().getString(R.string.download_files));
filter.setLength(0); filter.setLength(0);
Set<String> set = new TreeSet<String>();
if ((currentObjects != null && currentObjects.size() > 0)) { if ((currentObjects != null && currentObjects.size() > 0)) {
for (int i = 0; i < currentObjects.size(); i++) { for (int i = 0; i < currentObjects.size(); i++) {
if (i > 0) { final BinaryMapDataObject o = currentObjects.get(i);
String name = Algorithms.capitalizeFirstLetterAndLowercase(o.getName());
if(!set.add(name)) {
continue;
}
if (set.size() > 1) {
s.append(" & "); s.append(" & ");
filter.append(", ");
} else { } else {
s.append(" "); s.append(" ");
} }
final BinaryMapDataObject o = currentObjects.get(i); filter.append(name);
String string = Algorithms.capitalizeFirstLetterAndLowercase(o.getName());
filter.append(string + " ");
if (osmandRegions.getPrefix(o) != null) { if (osmandRegions.getPrefix(o) != null) {
string = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getPrefix(o)) + " " + string; name = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getPrefix(o)) + " " + name;
} }
s.append(string); s.append(name);
} }
} }
downloadBtn.setVisibility(View.VISIBLE); downloadBtn.setVisibility(View.VISIBLE);
@ -216,13 +165,14 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
downloadBtn.setText(view.getResources().getString(R.string.download_files) + " " + downloadBtn.setText(view.getResources().getString(R.string.download_files) + " " +
view.getResources().getString(R.string.base_world_map)); view.getResources().getString(R.string.base_world_map));
} }
path.reset();
for (BinaryMapDataObject o : currentObjects) { for (BinaryMapDataObject o : currentObjects) {
final String key = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getDownloadName(o)) + final String key = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getDownloadName(o)) +
IndexConstants.BINARY_MAP_INDEX_EXT; IndexConstants.BINARY_MAP_INDEX_EXT;
if (!rm.getIndexFileNames().containsKey(key)) { if (!rm.getIndexFileNames().containsKey(key)) {
continue; continue;
} }
path.reset();
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0)); double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0)); double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
path.moveTo(view.getRotatedMapXForPoint(lat, lon), view.getRotatedMapYForPoint(lat, lon)); path.moveTo(view.getRotatedMapXForPoint(lat, lon), view.getRotatedMapYForPoint(lat, lon));
@ -232,14 +182,74 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
path.lineTo(view.getRotatedMapXForPoint(lat, lon), path.lineTo(view.getRotatedMapXForPoint(lat, lon),
view.getRotatedMapYForPoint(lat, lon)); view.getRotatedMapYForPoint(lat, lon));
} }
canvas.drawPath(path, paint);
} }
canvas.drawPath(path, paint);
} }
} }
} }
} }
private AsyncTask<Object, Object, List<BinaryMapDataObject>> createNewTask(final int zoom, final RectF rf) {
return new AsyncTask<Object, Object, List<BinaryMapDataObject>>() {
@Override
protected List<BinaryMapDataObject> doInBackground(Object... params) {
if (queriedBBox.contains(rf)) {
return null;
}
if (zoom < ZOOM_TO_SHOW_MAP_NAMES) {
basemapExists = rm.getRenderer().basemapExists();
}
List<BinaryMapDataObject> result = null;
int left = MapUtils.get31TileNumberX(rf.left);
int right = MapUtils.get31TileNumberX(rf.right);
int top = MapUtils.get31TileNumberY(rf.top);
int bottom = MapUtils.get31TileNumberY(rf.bottom);
final boolean empty = rm.getRenderer().checkIfMapIsEmpty(left, right, top, bottom, zoom);
noMapsPresent = empty;
if (!empty && zoom >= ZOOM_TO_SHOW_MAP_NAMES) {
return Collections.emptyList();
}
try {
result = osmandRegions.queryBbox(left, right, top, bottom);
} catch (IOException e) {
return result;
}
Iterator<BinaryMapDataObject> it = result.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
if (zoom < ZOOM_TO_SHOW_BORDERS) {
//
} else {
if (!osmandRegions.contain(o, left / 2 + right / 2, top / 2 + bottom / 2)) {
it.remove();
}
}
}
return result;
}
@Override
protected void onPreExecute() {
currentTask = this;
}
@Override
protected void onPostExecute(List<BinaryMapDataObject> result) {
if (result != null) {
queriedBBox = rf;
objectsToDraw = result;
queriedZoom = zoom;
}
currentTask = null;
if (pendingTask != null) {
pendingTask.execute();
pendingTask = null;
}
}
};
}
@Override @Override
public void destroyLayer() { public void destroyLayer() {