This commit is contained in:
Victor Shcherb 2015-10-25 17:08:20 +01:00
parent a73f88b326
commit 69a6210b4a

View file

@ -77,6 +77,13 @@ public class OsmandRegions {
Integer metricType = null; Integer metricType = null;
Integer leftHandDrivingType = null; Integer leftHandDrivingType = null;
Integer roadSignsType = null; Integer roadSignsType = null;
public String get(Integer tp, BinaryMapDataObject object) {
if(tp == null) {
return null;
}
return object.getNameByType(tp);
}
} }
@ -95,32 +102,20 @@ public class OsmandRegions {
final String lc = downloadName.toLowerCase(); final String lc = downloadName.toLowerCase();
if (downloadNamesToFullNames.containsKey(lc)) { if (downloadNamesToFullNames.containsKey(lc)) {
String fullName = downloadNamesToFullNames.get(lc); String fullName = downloadNamesToFullNames.get(lc);
if (includingParent) { return getLocaleNameByFullName(fullName, includingParent);
if (fullNamesToLocaleNames.containsKey(fullName)) {
return fullNamesToLocaleNames.get(fullName);
}
} else {
if (fullNamesNoParentToLocaleNames.containsKey(fullName)) {
return fullNamesNoParentToLocaleNames.get(fullName);
}
}
} }
return downloadName.replace('_', ' '); return downloadName.replace('_', ' ');
} }
public String getLocaleNameByFullName(String fullName, boolean includingParent) { public String getLocaleNameByFullName(String fullName, boolean includingParent) {
if (includingParent) { RegionData rd = fullNamesToRegionData.get(fullName);
if (fullNamesToLocaleNames.containsKey(fullName)) { if(rd == null) {
return fullNamesToLocaleNames.get(fullName); return fullName.replace('_', ' ');
} else { }
return fullName.replace('_', ' '); if (includingParent && rd.parent != null) {
} return rd.parent.getLocaleName() + " " + rd.getLocaleName();
} else { } else {
if (fullNamesNoParentToLocaleNames.containsKey(fullName)) { return rd.getLocaleName();
return fullNamesNoParentToLocaleNames.get(fullName);
} else {
return fullName.replace('_', ' ');
}
} }
} }
@ -138,48 +133,12 @@ public class OsmandRegions {
return null; return null;
} }
public String getLocaleName(BinaryMapDataObject object) {
String locName = "";
if(locName == null || locName.length() == 0){
if(nameLocaleType != null) {
locName = object.getNameByType(nameLocaleType);
}
}
if(locName == null || locName.length() == 0){
if(nameEnType != null) {
locName = object.getNameByType(nameEnType);
}
}
if(locName == null || locName.length() == 0){
if(nameType != null) {
locName = object.getNameByType(nameType);
}
}
return locName;
}
public String getParentFullName(BinaryMapDataObject o) {
if(parentFullName == null) {
return null;
}
return o.getNameByType(parentFullName);
}
public String getFullName(BinaryMapDataObject o) {
if(fullNameType == null) {
return null;
}
return o.getNameByType(fullNameType);
}
public boolean isInitialized(){ public boolean isInitialized(){
return reader != null; return reader != null;
} }
public boolean contain(BinaryMapDataObject bo, int tx, int ty) { public boolean contain(BinaryMapDataObject bo, int tx, int ty) {
int t = 0; int t = 0;
for (int i = 1; i < bo.getPointsLength(); i++) { for (int i = 1; i < bo.getPointsLength(); i++) {
@ -365,54 +324,27 @@ public class OsmandRegions {
return false; return false;
} }
} }
String parentFullName = getParentFullName(object); RegionData rd = new RegionData();
String fullName = getFullName(object); rd.downloadsId = mapIndexFields.get(mapIndexFields.downloadNameType, object);
if(!Algorithms.isEmpty(parentFullName)) { rd.regionFullName = mapIndexFields.get(mapIndexFields.fullNameType, object);
fullNamesToParentFullNames.put(fullName, parentFullName); rd.regionParentFullName = mapIndexFields.get(mapIndexFields.parentFullName, object);
parentRelations.put(fullName, parentFullName); if(!Algorithms.isEmpty(rd.regionParentFullName)) {
} parentRelations.put(rd.regionFullName, rd.regionParentFullName);
String locName = getLocaleName(object);
if(!Algorithms.isEmpty(locName)){
fullNamesToLocaleNames.put(fullName, locName);
fullNamesNoParentToLocaleNames.put(fullName, locName);
} }
rd.regionName = mapIndexFields.get(mapIndexFields.nameType, object);
rd.regionNameLocale = mapIndexFields.get(mapIndexFields.nameLocaleType, object);
rd.regionNameEn = mapIndexFields.get(mapIndexFields.nameEnType, object);
rd.regionLang = mapIndexFields.get(mapIndexFields.langType, object);
rd.regionLeftHandDriving = mapIndexFields.get(mapIndexFields.leftHandDrivingType, object);
rd.regionMetric = mapIndexFields.get(mapIndexFields.metricType, object);
rd.regionRoadSigns = mapIndexFields.get(mapIndexFields.roadSignsType, object);
String lang = getLang(object);
if(!Algorithms.isEmpty(lang)){
fullNamesToLangs.put(fullName, lang);
}
String metric = getMetric(object);
if(!Algorithms.isEmpty(metric)){
fullNamesToMetrics.put(fullName, metric);
}
String leftHandDriving = getLeftHandDriving(object);
if(!Algorithms.isEmpty(leftHandDriving)){
fullNamesToLeftHandDrivings.put(fullName, leftHandDriving);
}
String roadSigns = getRoadSigns(object); String roadSigns = getRoadSigns(object);
if(!Algorithms.isEmpty(roadSigns)){ if(!Algorithms.isEmpty(roadSigns)){
fullNamesToRoadSigns.put(fullName, roadSigns); fullNamesToRoadSigns.put(fullName, roadSigns);
} }
MapIndex mi = object.getMapIndex(); rd.searchText = getSearchIndex(object);
TIntObjectIterator<String> it = object.getObjectNames().iterator();
StringBuilder ind = new StringBuilder();
while(it.hasNext()) {
it.advance();
TagValuePair tp = mi.decodeType(it.key());
if (tp.tag.equals("key_name") && Algorithms.isEmpty(locName)) {
String str = Algorithms.capitalizeFirstLetterAndLowercase(it.value().replace('_', '-'));
fullNamesToLocaleNames.put(fullName, str);
fullNamesNoParentToLocaleNames.put(fullName, str);
}
if(tp.tag.startsWith("name") || tp.tag.equals("key_name")) {
final String vl = it.value().toLowerCase();
// if (!CollatorStringMatcher.ccontains(clt, ind.toString(), vl)) {
if(ind.indexOf(vl) == -1) {
ind.append(" ").append(vl);
}
}
}
fullNamesToLowercaseIndex.put(fullName, ind.toString()); fullNamesToLowercaseIndex.put(fullName, ind.toString());
String downloadName = getDownloadName(object); String downloadName = getDownloadName(object);
if(downloadName != null) { if(downloadName != null) {
@ -426,6 +358,25 @@ public class OsmandRegions {
} }
private String getSearchIndex(BinaryMapDataObject object) {
MapIndex mi = object.getMapIndex();
TIntObjectIterator<String> it = object.getObjectNames().iterator();
StringBuilder ind = new StringBuilder();
while(it.hasNext()) {
it.advance();
TagValuePair tp = mi.decodeType(it.key());
if(tp.tag.startsWith("name") || tp.tag.equals("key_name")) {
final String vl = it.value().toLowerCase();
// if (!CollatorStringMatcher.ccontains(clt, ind.toString(), vl)) {
if(ind.indexOf(vl) == -1) {
ind.append(" ").append(vl);
}
}
}
return ind.toString();
}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return false; return false;
@ -458,6 +409,7 @@ public class OsmandRegions {
} }
private boolean isDownloadOfType(BinaryMapDataObject object, String type) { private boolean isDownloadOfType(BinaryMapDataObject object, String type) {
int[] addtypes = object.getAdditionalTypes(); int[] addtypes = object.getAdditionalTypes();
for(int i = 0; i < addtypes.length; i++) { for(int i = 0; i < addtypes.length; i++) {
@ -601,12 +553,35 @@ public class OsmandRegions {
public static class RegionData { public static class RegionData {
// filled by osmand regions
protected RegionData parent = null;
protected String regionLeftHandDriving;
protected String regionLang;
protected String regionMetric;
protected String regionRoadSigns;
protected String regionFullName;
protected String regionParentFullName;
protected String regionName;
protected String regionNameEn;
protected String regionNameLocale;
///
String regionId; String regionId;
private String downloadsId; private String downloadsId;
private String name; private String name;
private String searchText; private String searchText;
private LatLon center; private LatLon center;
public String getLocaleName() {
if(!Algorithms.isEmpty(regionNameLocale)) {
return regionNameLocale;
}
if(!Algorithms.isEmpty(regionNameEn)) {
return regionNameEn;
}
return regionName;
}
public LatLon getCenter() { public LatLon getCenter() {
return center; return center;
} }