Add regions download
This commit is contained in:
parent
19ce935266
commit
7e5414e527
3 changed files with 103 additions and 72 deletions
|
@ -269,6 +269,7 @@ public class OsmandRegions {
|
|||
testCountry(or, 28.8056, 29.9858, "africa", "egypt" );
|
||||
testCountry(or, 35.7521, 139.7887, "japan");
|
||||
testCountry(or, 46.5145, 102.2580, "mongolia");
|
||||
testCountry(or, 62.54, 43.36, "arkhangelsk", "northwestern-federal-district");
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -106,21 +106,41 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
|
|||
results.values = indexFiles;
|
||||
results.count = indexFiles.size();
|
||||
} else {
|
||||
String[] vars = constraint.toString().split("\\s");
|
||||
for (int i = 0; i < vars.length; i++) {
|
||||
vars[i] = vars[i].trim().toLowerCase();
|
||||
String[] ors = constraint.toString().split("\\,");
|
||||
List<List<String>> conds = new ArrayList<List<String>>();
|
||||
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>();
|
||||
ClientContext c = downloadActivity.getMyApplication();
|
||||
for (IndexItem item : indexFiles) {
|
||||
boolean add = true;
|
||||
for (String var : vars) {
|
||||
if (var.length() > 0) {
|
||||
if (!item.getVisibleName(c).toLowerCase().contains(var)
|
||||
final String visibleName = item.getVisibleName(c).toLowerCase();
|
||||
for(List<String> or : conds) {
|
||||
boolean tadd = true;
|
||||
for (String var : or) {
|
||||
if (!visibleName.contains(var)
|
||||
/*&& !item.getDescription().toLowerCase().contains(var)*/) {
|
||||
tadd = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!tadd) {
|
||||
add = false;
|
||||
} else {
|
||||
add = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (add) {
|
||||
filter.add(item);
|
||||
|
|
|
@ -122,7 +122,76 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
|
|||
float w = Math.abs(latLonBox.width() / 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);
|
||||
AsyncTask<Object, Object, List<BinaryMapDataObject>> task = new AsyncTask<Object, Object, List<BinaryMapDataObject>>() {
|
||||
AsyncTask<Object, Object, List<BinaryMapDataObject>> task = createNewTask(zoom, rf);
|
||||
if (currentTask == null) {
|
||||
task.execute();
|
||||
} else {
|
||||
pendingTask = task;
|
||||
}
|
||||
}
|
||||
final List<BinaryMapDataObject> currentObjects = objectsToDraw;
|
||||
if ((currentObjects != null && currentObjects.size() > 0) || noMapsPresent) {
|
||||
if (zoom >= ZOOM_TO_SHOW_MAP_NAMES) {
|
||||
StringBuilder s = new StringBuilder(view.getResources().getString(R.string.download_files));
|
||||
filter.setLength(0);
|
||||
Set<String> set = new TreeSet<String>();
|
||||
if ((currentObjects != null && currentObjects.size() > 0)) {
|
||||
for (int i = 0; i < currentObjects.size(); i++) {
|
||||
final BinaryMapDataObject o = currentObjects.get(i);
|
||||
String name = Algorithms.capitalizeFirstLetterAndLowercase(o.getName());
|
||||
if(!set.add(name)) {
|
||||
continue;
|
||||
}
|
||||
if (set.size() > 1) {
|
||||
s.append(" & ");
|
||||
filter.append(", ");
|
||||
} else {
|
||||
s.append(" ");
|
||||
}
|
||||
filter.append(name);
|
||||
if (osmandRegions.getPrefix(o) != null) {
|
||||
name = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getPrefix(o)) + " " + name;
|
||||
}
|
||||
s.append(name);
|
||||
}
|
||||
}
|
||||
downloadBtn.setVisibility(View.VISIBLE);
|
||||
downloadBtn.setText(s.toString());
|
||||
} else {
|
||||
if(!basemapExists) {
|
||||
filter.setLength(0);
|
||||
filter.append("basemap");
|
||||
downloadBtn.setVisibility(View.VISIBLE);
|
||||
downloadBtn.setText(view.getResources().getString(R.string.download_files) + " " +
|
||||
view.getResources().getString(R.string.base_world_map));
|
||||
}
|
||||
path.reset();
|
||||
for (BinaryMapDataObject o : currentObjects) {
|
||||
final String key = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getDownloadName(o)) +
|
||||
IndexConstants.BINARY_MAP_INDEX_EXT;
|
||||
if (!rm.getIndexFileNames().containsKey(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
|
||||
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
|
||||
path.moveTo(view.getRotatedMapXForPoint(lat, lon), view.getRotatedMapYForPoint(lat, lon));
|
||||
for(int j = 1 ; j < o.getPointsLength(); j++) {
|
||||
lat = MapUtils.get31LatitudeY(o.getPoint31YTile(j));
|
||||
lon = MapUtils.get31LongitudeX(o.getPoint31XTile(j));
|
||||
path.lineTo(view.getRotatedMapXForPoint(lat, lon),
|
||||
view.getRotatedMapYForPoint(lat, lon));
|
||||
}
|
||||
}
|
||||
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)) {
|
||||
|
@ -179,65 +248,6 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
|
|||
}
|
||||
}
|
||||
};
|
||||
if (currentTask == null) {
|
||||
task.execute();
|
||||
} else {
|
||||
pendingTask = task;
|
||||
}
|
||||
}
|
||||
final List<BinaryMapDataObject> currentObjects = objectsToDraw;
|
||||
if ((currentObjects != null && currentObjects.size() > 0) || noMapsPresent) {
|
||||
if (zoom >= ZOOM_TO_SHOW_MAP_NAMES) {
|
||||
StringBuilder s = new StringBuilder(view.getResources().getString(R.string.download_files));
|
||||
filter.setLength(0);
|
||||
if ((currentObjects != null && currentObjects.size() > 0)) {
|
||||
for (int i = 0; i < currentObjects.size(); i++) {
|
||||
if (i > 0) {
|
||||
s.append(" & ");
|
||||
} else {
|
||||
s.append(" ");
|
||||
}
|
||||
final BinaryMapDataObject o = currentObjects.get(i);
|
||||
String string = Algorithms.capitalizeFirstLetterAndLowercase(o.getName());
|
||||
filter.append(string + " ");
|
||||
if (osmandRegions.getPrefix(o) != null) {
|
||||
string = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getPrefix(o)) + " " + string;
|
||||
}
|
||||
s.append(string);
|
||||
}
|
||||
}
|
||||
downloadBtn.setVisibility(View.VISIBLE);
|
||||
downloadBtn.setText(s.toString());
|
||||
} else {
|
||||
if(!basemapExists) {
|
||||
filter.setLength(0);
|
||||
filter.append("basemap");
|
||||
downloadBtn.setVisibility(View.VISIBLE);
|
||||
downloadBtn.setText(view.getResources().getString(R.string.download_files) + " " +
|
||||
view.getResources().getString(R.string.base_world_map));
|
||||
}
|
||||
for (BinaryMapDataObject o : currentObjects) {
|
||||
final String key = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getDownloadName(o)) +
|
||||
IndexConstants.BINARY_MAP_INDEX_EXT;
|
||||
if (!rm.getIndexFileNames().containsKey(key)) {
|
||||
continue;
|
||||
}
|
||||
path.reset();
|
||||
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
|
||||
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
|
||||
path.moveTo(view.getRotatedMapXForPoint(lat, lon), view.getRotatedMapYForPoint(lat, lon));
|
||||
for(int j = 1 ; j < o.getPointsLength(); j++) {
|
||||
lat = MapUtils.get31LatitudeY(o.getPoint31YTile(j));
|
||||
lon = MapUtils.get31LongitudeX(o.getPoint31XTile(j));
|
||||
path.lineTo(view.getRotatedMapXForPoint(lat, lon),
|
||||
view.getRotatedMapYForPoint(lat, lon));
|
||||
}
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue