Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-10-25 22:24:19 +01:00
commit d5eca3cf62
2 changed files with 98 additions and 146 deletions

View file

@ -24,6 +24,7 @@ import net.osmand.binary.BinaryMapDataObject;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapIndexReader.MapIndex; import net.osmand.binary.BinaryMapIndexReader.MapIndex;
import net.osmand.binary.BinaryMapIndexReader.TagValuePair; import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree; import net.osmand.data.QuadTree;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -33,42 +34,51 @@ import net.osmand.util.MapUtils;
public class OsmandRegions { public class OsmandRegions {
private static final String MAP_TYPE = "region_map"; private static final String MAP_TYPE = "region_map";
// regionSrtm = object.getMapIndex().getRule("region_srtm", null);
// regionWiki = object.getMapIndex().getRule("region_wiki", null); public static final String FIELD_LEFT_HAND_DRIVING = "left_hand_driving";
// regionRoads = object.getMapIndex().getRule("region_roads", null); public static final String FIELD_DOWNLOAD_NAME = "download_name";
// regionHillshade = object.getMapIndex().getRule("region_hillshade", null); public static final String FIELD_NAME = "name";
public static final String FIELD_NAME_EN = "name:en";
public static final String FIELD_REGION_PARENT_NAME = "region_parent_name";
public static final String FIELD_REGION_FULL_NAME = "region_full_name";
public static final String FIELD_LANG = "lang";
public static final String FIELD_METRIC = "metric";
public static final String FIELD_ROAD_SIGNS = "road_signs";
private BinaryMapIndexReader reader; private BinaryMapIndexReader reader;
Map<String, RegionData> fullNamesToRegionData = new HashMap<String, RegionData>();
Map<String, LinkedList<BinaryMapDataObject>> countriesByDownloadName = new HashMap<String, LinkedList<BinaryMapDataObject>>(); Map<String, LinkedList<BinaryMapDataObject>> countriesByDownloadName = new HashMap<String, LinkedList<BinaryMapDataObject>>();
Map<String, String> fullNamesToLocaleNames = new HashMap<String, String>();
Map<String, String> fullNamesNoParentToLocaleNames = new HashMap<String, String>();
Map<String, String> fullMapNamesToDownloadNames = new HashMap<String, String>();
Map<String, String> downloadNamesToFullNames = new HashMap<String, String>(); Map<String, String> downloadNamesToFullNames = new HashMap<String, String>();
Map<String, String> fullNamesToLowercaseIndex = new HashMap<String, String>(); // Map<String, String> fullNamesToLocaleNames = new HashMap<String, String>();
Map<String, String> fullNamesToParentFullNames = new HashMap<String, String>(); // Map<String, String> fullNamesNoParentToLocaleNames = new HashMap<String, String>();
Map<String, String> fullNamesToDownloadNames = new HashMap<String, String>(); // Map<String, String> fullMapNamesToDownloadNames = new HashMap<String, String>();
Map<String, String> fullNamesToLangs = new HashMap<String, String>(); // Map<String, String> fullNamesToLowercaseIndex = new HashMap<String, String>();
Map<String, String> fullNamesToMetrics = new HashMap<String, String>(); // Map<String, String> fullNamesToParentFullNames = new HashMap<String, String>();
Map<String, String> fullNamesToLeftHandDrivings = new HashMap<String, String>(); // Map<String, String> fullNamesToDownloadNames = new HashMap<String, String>();
Map<String, String> fullNamesToRoadSigns = new HashMap<String, String>(); // Map<String, String> fullNamesToLangs = new HashMap<String, String>();
// Map<String, String> fullNamesToMetrics = new HashMap<String, String>();
// Map<String, String> fullNamesToLeftHandDrivings = new HashMap<String, String>();
// Map<String, String> fullNamesToRoadSigns = new HashMap<String, String>();
QuadTree<String> quadTree = null ; QuadTree<String> quadTree = null ;
String locale = "en";
MapIndexFields mapIndexFields = new MapIndexFields();
public Map<String, String> getFullNamesToLowercaseCopy() { private class MapIndexFields {
return new HashMap<String, String>(fullNamesToLowercaseIndex); MapIndex mapIndex;
Integer parentFullName = null;
Integer fullNameType = null;
Integer downloadNameType = null;
Integer nameEnType = null;
Integer nameType = null;
Integer nameLocaleType = null;
Integer langType = null;
Integer metricType = null;
Integer leftHandDrivingType = null;
Integer roadSignsType = null;
} }
Integer parentFullName = null;
Integer fullNameType = null;
Integer downloadNameType = null;
Integer nameEnType = null;
Integer nameType = null;
Integer nameLocaleType = null;
String locale = "en";
Integer langType = null;
Integer metricType = null;
Integer leftHandDrivingType = null;
Integer roadSignsType = null;
public void prepareFile(String fileName) throws IOException { public void prepareFile(String fileName) throws IOException {
@ -80,64 +90,6 @@ public class OsmandRegions {
return countriesByDownloadName.containsKey(name); return countriesByDownloadName.containsKey(name);
} }
public String getLang(String fullName) {
return fullNamesToLangs.get(fullName);
}
public String getMetric(String fullName) {
return fullNamesToMetrics.get(fullName);
}
public String getLeftHandDriving(String fullName) {
return fullNamesToLeftHandDrivings.get(fullName);
}
public String getRoadSigns(String fullName) {
return fullNamesToRoadSigns.get(fullName);
}
private String getLang(BinaryMapDataObject o) {
if (langType != null) {
return o.getNameByType(langType);
} else {
return null;
}
}
private String getMetric(BinaryMapDataObject o) {
if (metricType != null) {
return o.getNameByType(metricType);
} else {
return null;
}
}
private String getLeftHandDriving(BinaryMapDataObject o) {
if (leftHandDrivingType != null) {
return o.getNameByType(leftHandDrivingType);
} else {
return null;
}
}
private String getRoadSigns(BinaryMapDataObject o) {
if (roadSignsType != null) {
return o.getNameByType(roadSignsType);
} else {
return null;
}
}
public String getDownloadName(BinaryMapDataObject o) {
if(downloadNameType == null) {
return null;
}
return o.getNameByType(downloadNameType);
}
public Integer getNameEnType() {
return nameEnType;
}
public String getLocaleName(String downloadName, boolean includingParent) { public String getLocaleName(String downloadName, boolean includingParent) {
final String lc = downloadName.toLowerCase(); final String lc = downloadName.toLowerCase();
@ -586,22 +538,20 @@ public class OsmandRegions {
private void initTypes(BinaryMapDataObject object) { private void initTypes(BinaryMapDataObject object) {
if (downloadNameType == null) { if (mapIndexFields == null) {
downloadNameType = object.getMapIndex().getRule("download_name", null); mapIndexFields = new MapIndexFields();
nameType = object.getMapIndex().getRule("name", null); mapIndexFields.mapIndex = object.getMapIndex();
nameEnType = object.getMapIndex().getRule("name:en", null); mapIndexFields.downloadNameType = object.getMapIndex().getRule(FIELD_DOWNLOAD_NAME, null);
nameLocaleType = object.getMapIndex().getRule("name:" + locale, null); mapIndexFields.nameType = object.getMapIndex().getRule(FIELD_NAME, null);
parentFullName = object.getMapIndex().getRule("region_parent_name", null); mapIndexFields.nameEnType = object.getMapIndex().getRule(FIELD_NAME_EN, null);
fullNameType = object.getMapIndex().getRule("region_full_name", null); mapIndexFields.nameLocaleType = object.getMapIndex().getRule(FIELD_NAME+":"+locale, null);
mapIndexFields.parentFullName = object.getMapIndex().getRule(FIELD_REGION_PARENT_NAME, null);
langType = object.getMapIndex().getRule("lang", null); mapIndexFields.fullNameType = object.getMapIndex().getRule(FIELD_REGION_FULL_NAME, null);
metricType = object.getMapIndex().getRule("metric", null); mapIndexFields.langType = object.getMapIndex().getRule(FIELD_LANG, null);
leftHandDrivingType = object.getMapIndex().getRule("left_hand_driving", null); mapIndexFields.metricType = object.getMapIndex().getRule(FIELD_METRIC, null);
roadSignsType = object.getMapIndex().getRule("road_signs", null); mapIndexFields.leftHandDrivingType = object.getMapIndex().getRule(FIELD_LEFT_HAND_DRIVING, null);
mapIndexFields.roadSignsType = object.getMapIndex().getRule(FIELD_ROAD_SIGNS, null);
if (downloadNameType == null || nameType == null) { mapIndexFields.nameType = object.getMapIndex().getRule(FIELD_NAME, null);
throw new IllegalStateException();
}
} }
} }
@ -649,5 +599,32 @@ public class OsmandRegions {
} }
public static class RegionData {
String regionId;
private String downloadsId;
private String name;
private String searchText;
private LatLon center;
public LatLon getCenter() {
return center;
}
public String getSearchText() {
return searchText;
}
public String getName() {
return name;
}
public String getRegionId() {
return regionId;
}
public String getDownloadsId() {
return downloadsId;
}
}
} }

View file

@ -30,43 +30,23 @@ public class WorldRegion {
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(WorldRegion.class); private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(WorldRegion.class);
// Region data // Region data
private String regionId; private OsmandRegions.RegionData regionData;
private String downloadsId;
private String name;
private String searchText;
private LatLon center;
// Hierarchy // Hierarchy
private WorldRegion superregion; private WorldRegion superregion;
private List<WorldRegion> subregions; private List<WorldRegion> subregions;
private List<WorldRegion> flattenedSubregions; private List<WorldRegion> flattenedSubregions;
public String getLang(OsmandRegions osmandRegions) { public OsmandRegions.RegionData getRegionData() {
return osmandRegions.getLang(regionId); return regionData;
}
public String getMetric(OsmandRegions osmandRegions) {
return osmandRegions.getMetric(regionId);
}
public String getLeftHandDriving(OsmandRegions osmandRegions) {
return osmandRegions.getLeftHandDriving(regionId);
}
public String getRoadSigns(OsmandRegions osmandRegions) {
return osmandRegions.getRoadSigns(regionId);
}
public String getRegionId() {
return regionId;
}
public String getDownloadsId() {
return downloadsId;
} }
public String getName() { public String getName() {
return name; return regionData.getName();
}
private String getRegionId() {
return regionData.getRegionId();
} }
public WorldRegion getSuperregion() { public WorldRegion getSuperregion() {
@ -88,12 +68,12 @@ public class WorldRegion {
WorldRegion that = (WorldRegion) o; WorldRegion that = (WorldRegion) o;
return !(name != null ? !name.toLowerCase().equals(that.name.toLowerCase()) : that.name != null); return !(getName() != null ? !getName().toLowerCase().equals(that.getName().toLowerCase()) : that.getName() != null);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return name != null ? name.hashCode() : 0; return getName() != null ? getName().hashCode() : 0;
} }
public WorldRegion() { public WorldRegion() {
@ -129,9 +109,6 @@ public class WorldRegion {
return this; return this;
} }
public String getSearchText() {
return searchText;
}
private void addSubregion(WorldRegion subregion, WorldRegion world) { private void addSubregion(WorldRegion subregion, WorldRegion world) {
subregion.superregion = this; subregion.superregion = this;
@ -167,27 +144,27 @@ public class WorldRegion {
WorldRegion centralAmericaRegion = createRegionAs(CENTRAL_AMERICA_REGION_ID, WorldRegion centralAmericaRegion = createRegionAs(CENTRAL_AMERICA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_central_america)); loadedItems, osmandRegions, res.getString(R.string.index_name_central_america));
addSubregion(centralAmericaRegion, this); addSubregion(centralAmericaRegion, this);
regionsLookupTable.put(centralAmericaRegion.regionId, centralAmericaRegion); regionsLookupTable.put(centralAmericaRegion.getRegionId(), centralAmericaRegion);
WorldRegion europeRegion = createRegionAs(EUROPE_REGION_ID, WorldRegion europeRegion = createRegionAs(EUROPE_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_europe)); loadedItems, osmandRegions, res.getString(R.string.index_name_europe));
addSubregion(europeRegion, this); addSubregion(europeRegion, this);
regionsLookupTable.put(europeRegion.regionId, europeRegion); regionsLookupTable.put(europeRegion.getRegionId(), europeRegion);
WorldRegion northAmericaRegion = createRegionAs(NORTH_AMERICA_REGION_ID, WorldRegion northAmericaRegion = createRegionAs(NORTH_AMERICA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_north_america)); loadedItems, osmandRegions, res.getString(R.string.index_name_north_america));
addSubregion(northAmericaRegion, this); addSubregion(northAmericaRegion, this);
regionsLookupTable.put(northAmericaRegion.regionId, northAmericaRegion); regionsLookupTable.put(northAmericaRegion.getRegionId(), northAmericaRegion);
WorldRegion russiaRegion = createRegionAs(RUSSIA_REGION_ID, WorldRegion russiaRegion = createRegionAs(RUSSIA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_russia)); loadedItems, osmandRegions, res.getString(R.string.index_name_russia));
addSubregion(russiaRegion, this); addSubregion(russiaRegion, this);
regionsLookupTable.put(russiaRegion.regionId, russiaRegion); regionsLookupTable.put(russiaRegion.getRegionId(), russiaRegion);
WorldRegion southAmericaRegion = createRegionAs(SOUTH_AMERICA_REGION_ID, WorldRegion southAmericaRegion = createRegionAs(SOUTH_AMERICA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_south_america)); loadedItems, osmandRegions, res.getString(R.string.index_name_south_america));
addSubregion(southAmericaRegion, this); addSubregion(southAmericaRegion, this);
regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion); regionsLookupTable.put(southAmericaRegion.getRegionId(), southAmericaRegion);
// Process all regions // Process all regions
for (; ; ) { for (; ; ) {
@ -208,7 +185,7 @@ public class WorldRegion {
WorldRegion newRegion = new WorldRegion().init(regionId, osmandRegions, null); WorldRegion newRegion = new WorldRegion().init(regionId, osmandRegions, null);
parentRegion.addSubregion(newRegion, this); parentRegion.addSubregion(newRegion, this);
regionsLookupTable.put(newRegion.regionId, newRegion); regionsLookupTable.put(newRegion.getRegionId(), newRegion);
// Remove // Remove
processedRegions++; processedRegions++;
@ -252,10 +229,6 @@ public class WorldRegion {
return worldRegion; return worldRegion;
} }
public LatLon getCenter() {
// TODO
return center;
}
private String capitalize(String s) { private String capitalize(String s) {
String[] words = s.split(" "); String[] words = s.split(" ");
@ -286,4 +259,6 @@ public class WorldRegion {
} }
} }