Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-06-06 02:01:46 +02:00
commit 0a21d4e841
2 changed files with 60 additions and 36 deletions

View file

@ -31,9 +31,16 @@ import net.osmand.util.MapUtils;
public class OsmandRegions {
private static final String MAP_TYPE = "region_map";
// regionSrtm = object.getMapIndex().getRule("region_srtm", null);
// regionWiki = object.getMapIndex().getRule("region_wiki", null);
// regionRoads = object.getMapIndex().getRule("region_roads", null);
// regionHillshade = object.getMapIndex().getRule("region_hillshade", null);
private BinaryMapIndexReader reader;
Map<String, LinkedList<BinaryMapDataObject>> countriesByDownloadName = new HashMap<String, LinkedList<BinaryMapDataObject>>();
Map<String, String> fullNamesToLocaleNames = new HashMap<String, String>();
Map<String, String> fullMapNamesToDownloadNames = new HashMap<String, String>();
Map<String, String> downloadNamesToFullNames = new HashMap<String, String>();
Map<String, String> fullNamesToLowercaseIndex = new HashMap<String, String>();
QuadTree<String> quadTree = null ;
@ -46,11 +53,6 @@ public class OsmandRegions {
Integer nameType = null;
Integer nameLocaleType = null;
String locale = "en";
Integer regionSrtm;
Integer regionWiki;
Integer regionMap;
Integer regionRoads;
Integer regionHillshade;
public void prepareFile(String fileName) throws IOException {
@ -258,6 +260,10 @@ public class OsmandRegions {
this.locale = locale;
}
public String getMapDownloadType(String fullname) {
return fullMapNamesToDownloadNames.get(fullname);
}
public void initLocaleNames() throws IOException {
// final Collator clt = OsmAndCollator.primaryCollator();
final Map<String, String> parentRelations = new LinkedHashMap<String, String>();
@ -266,6 +272,13 @@ public class OsmandRegions {
@Override
public boolean publish(BinaryMapDataObject object) {
initTypes(object);
int[] types = object.getTypes();
for(int i = 0; i < types.length; i++ ) {
TagValuePair tp = object.getMapIndex().decodeType(types[i]);
if("boundary".equals(tp.value)) {
return false;
}
}
String parentFullName = getParentFullName(object);
String fullName = getFullName(object);
if(!Algorithms.isEmpty(parentFullName)) {
@ -297,10 +310,14 @@ public class OsmandRegions {
String downloadName = getDownloadName(object);
if(downloadName != null) {
downloadNamesToFullNames.put(downloadName, fullName);
if(isDownloadOfType(object, MAP_TYPE)) {
fullMapNamesToDownloadNames.put(fullName, downloadName);
}
}
return false;
}
@Override
public boolean isCancelled() {
return false;
@ -330,6 +347,17 @@ public class OsmandRegions {
}
}
private boolean isDownloadOfType(BinaryMapDataObject object, String type) {
int[] addtypes = object.getAdditionalTypes();
for(int i = 0; i < addtypes.length; i++) {
TagValuePair tp = object.getMapIndex().decodeType(addtypes[i]);
if(type.equals(tp.tag) && "yes".equals(tp.value)) {
return true;
}
}
return false;
}
public void cacheAllCountries() throws IOException {
@ -402,11 +430,7 @@ public class OsmandRegions {
nameLocaleType = object.getMapIndex().getRule("name:" + locale, null);
parentFullName = object.getMapIndex().getRule("region_parent_name", null);
fullNameType = object.getMapIndex().getRule("region_full_name", null);
regionSrtm = object.getMapIndex().getRule("region_srtm", null);
regionWiki = object.getMapIndex().getRule("region_wiki", null);
regionMap = object.getMapIndex().getRule("region_map", null);
regionRoads = object.getMapIndex().getRule("region_roads", null);
regionHillshade = object.getMapIndex().getRule("region_hillshade", null);
if (downloadNameType == null || nameType == null) {
throw new IllegalStateException();
}

View file

@ -117,7 +117,8 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
currentObjects != null) {
path.reset();
for (BinaryMapDataObject o : currentObjects) {
boolean downloaded = checkIfObjectDownloaded(o);
String downloadName = osmandRegions.getDownloadName(o);
boolean downloaded = checkIfObjectDownloaded(downloadName);
if (!downloaded) {
continue;
}
@ -136,10 +137,10 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
private boolean checkIfObjectDownloaded(BinaryMapDataObject o) {
final String regionName = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getDownloadName(o))
private boolean checkIfObjectDownloaded(String downloadName) {
final String regionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName)
+ IndexConstants.BINARY_MAP_INDEX_EXT;
final String roadsRegionName = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getDownloadName(o)) + "-roads"
final String roadsRegionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) + "-roads"
+ IndexConstants.BINARY_MAP_INDEX_EXT;
return rm.getIndexFileNames().containsKey(regionName) || rm.getIndexFileNames().containsKey(roadsRegionName);
}
@ -237,35 +238,34 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
btnName.append(view.getResources().getString(R.string.shared_string_download));
filter.setLength(0);
Set<String> set = new TreeSet<String>();
int cx = queriedBox.getCenter31X();
int cy = queriedBox.getCenter31Y();
int cx = view.getCurrentRotatedTileBox().getCenter31X();
int cy = view.getCurrentRotatedTileBox().getCenter31Y();
if ((currentObjects != null && currentObjects.size() > 0)) {
for (int i = 0; i < currentObjects.size(); i++) {
// TODO regions=boundary
final BinaryMapDataObject o = currentObjects.get(i);
if (!osmandRegions.contain(o, cx, cy)) {
continue;
}
if(checkIfObjectDownloaded(o)) {
return null;
String fullName = osmandRegions.getFullName(o);
String downloadName = osmandRegions.getMapDownloadType(fullName);
if (!Algorithms.isEmpty(downloadName)) {
String name = osmandRegions.getLocaleName(downloadName); // Algorithms.capitalizeFirstLetterAndLowercase(o.getName());
if (checkIfObjectDownloaded(downloadName)) {
return null;
}
if (!set.add(name)) {
continue;
}
if (set.size() > 1) {
btnName.append(" ").append(view.getResources().getString(R.string.shared_string_or))
.append(" ");
filter.append(", ");
} else {
btnName.append(" ");
}
filter.append(name);
btnName.append(name);
}
String name = osmandRegions.getLocaleName(o); //Algorithms.capitalizeFirstLetterAndLowercase(o.getName());
if (!set.add(name)) {
continue;
}
if (set.size() > 1) {
btnName.append(" ").append(view.getResources().getString(R.string.shared_string_or)).append(" ");
filter.append(", ");
} else {
btnName.append(" ");
}
filter.append(name);
// String parent = osmandRegions.getParentFullName(o);
// if (osmandRegions.getParentFullName(o) != null) {
// name = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getPrefix(o)) + " "
// + name;
// }
btnName.append(name);
}
}
}