Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-06-29 23:51:35 +02:00
commit 0fb64be0a7
24 changed files with 316 additions and 262 deletions

View file

@ -67,15 +67,15 @@ public class BinaryInspector {
if(args.length == 1 && "test".equals(args[0])) {
in.inspector(new String[]{
"-vpoi",
// "-vmap",// "-vmapobjects",
"-vmap", "-vmapobjects",
// "-vrouting",
// "-vaddress", "-vcities","-vstreetgroups",
// "-vstreets", "-vbuildings", "-vintersections",
"-vaddress", "-vcities","-vstreetgroups",
"-vstreets", "-vbuildings", "-vintersections",
"-zoom=16",
// "-bbox=1.74,51.17,1.75,51.16",
// "-vstats",
// "/Users/victorshcherb/osmand/maps/srtm/Netherlands_europe_2.srtm.obf"
// "/Users/victorshcherb/osmand/maps/World_basemap_2.obf"
"/Users/victorshcherb/osmand/osm-gen/Map.obf"
});
} else {
@ -566,6 +566,7 @@ public class BinaryInspector {
BinaryMapAddressReaderAdapter.VILLAGES_TYPE,
BinaryMapAddressReaderAdapter.POSTCODES_TYPE
};
String lang = "ru";
for (int j = 0; j < cityType.length; j++) {
int type = cityType[j];
@ -587,7 +588,7 @@ public class BinaryInspector {
int size = index.preloadStreets(c, null);
List<Street> streets = new ArrayList<Street>(c.getStreets());
print(MessageFormat.format("\t\t''{0}'' [{1,number,#}], {2,number,#} street(s) size {3,number,#} bytes",
new Object[]{c.getEnName(), c.getId(), streets.size(), size}));
new Object[]{c.getName(lang), c.getId(), streets.size(), size}));
if(!verbose.vstreets)
{
println("");
@ -605,20 +606,20 @@ public class BinaryInspector {
final List<Street> intersections = t.getIntersectedStreets();
println(MessageFormat.format("\t\t\t''{0}'' [{1,number,#}], {2,number,#} building(s), {3,number,#} intersections(s)",
new Object[]{t.getEnName(), t.getId(), buildings.size(), intersections.size()}));
new Object[]{t.getName(lang), t.getId(), buildings.size(), intersections.size()}));
if (buildings != null && !buildings.isEmpty() && verbose.vbuildings) {
println("\t\t\t\tBuildings:");
for (Building b : buildings) {
println(MessageFormat.format("\t\t\t\t{0} [{1,number,#}]",
new Object[]{b.getName(true), b.getId()}));
new Object[]{b.getName(lang), b.getId()}));
}
}
if (intersections != null && !intersections.isEmpty() && verbose.vintersections) {
print("\t\t\t\tIntersects with:");
for (Street s : intersections) {
println("\t\t\t\t\t" + s.getEnName());
println("\t\t\t\t\t" + s.getName(lang));
}
}
}

View file

@ -4,6 +4,7 @@ import gnu.trove.list.array.TIntArrayList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import net.osmand.CollatorStringMatcher;
@ -42,6 +43,7 @@ public class BinaryMapAddressReaderAdapter {
public static class AddressRegion extends BinaryIndexPart {
String enName;
int indexNameOffset = -1;
List<String> attributeTagsTable = new ArrayList<String>();
List<CitiesBlock> cities = new ArrayList<BinaryMapAddressReaderAdapter.CitiesBlock>();
LatLon calculatedCenter = null;
@ -96,6 +98,12 @@ public class BinaryMapAddressReaderAdapter {
case OsmandOdb.OsmAndAddressIndex.NAME_EN_FIELD_NUMBER :
region.enName = codedIS.readString();
break;
case OsmandOdb.OsmAndAddressIndex.ATTRIBUTETAGSTABLE_FIELD_NUMBER :
int length2 = codedIS.readRawVarint32();
int oldLimit = codedIS.pushLimit(length2);
region.attributeTagsTable = map.readStringTable();
codedIS.popLimit(oldLimit);
break;
case OsmandOdb.OsmAndAddressIndex.CITIES_FIELD_NUMBER :
CitiesBlock block = new CitiesBlock();
region.cities.add(block);
@ -131,7 +139,9 @@ public class BinaryMapAddressReaderAdapter {
}
}
protected void readCities(List<City> cities, SearchRequest<City> resultMatcher, StringMatcher matcher, boolean useEn) throws IOException {
protected void readCities(List<City> cities, SearchRequest<City> resultMatcher, StringMatcher matcher,
List<String> additionalTagsTable) throws IOException {
while(true){
int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t);
@ -142,7 +152,7 @@ public class BinaryMapAddressReaderAdapter {
int fp = codedIS.getTotalBytesRead();
int length = codedIS.readRawVarint32();
int oldLimit = codedIS.pushLimit(length);
City c = readCityHeader(matcher, fp, useEn);
City c = readCityHeader(matcher, fp, additionalTagsTable);
if(c != null){
if (resultMatcher == null || resultMatcher.publish(c)) {
cities.add(c);
@ -194,16 +204,30 @@ public class BinaryMapAddressReaderAdapter {
}
}
protected City readCityHeader(StringMatcher nameMatcher, int filePointer, boolean useEn) throws IOException{
protected City readCityHeader(StringMatcher matcher, int filePointer, List<String> additionalTagsTable) throws IOException{
int x = 0;
int y = 0;
City c = null;
boolean englishNameMatched = false;
LinkedList<String> additionalTags = null;
while(true){
int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t);
switch (tag) {
case 0:
if(matcher != null) {
boolean matches = matcher.matches(c.getName());
if(!matches) {
for(String n : c.getAllNames()) {
matches = matcher.matches(n);
if(matches) {
break;
}
}
}
if(!matches ) {
return null;
}
}
return c;
case OsmandOdb.CityIndex.CITY_TYPE_FIELD_NUMBER :
int type = codedIS.readUInt32();
@ -211,30 +235,31 @@ public class BinaryMapAddressReaderAdapter {
break;
case OsmandOdb.CityIndex.ID_FIELD_NUMBER :
c.setId(codedIS.readUInt64());
if(nameMatcher != null && useEn && !englishNameMatched){
codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return null;
break;
case OsmandOdb.CityIndex.ATTRIBUTETAGIDS_FIELD_NUMBER :
int tgid = codedIS.readUInt32();
if(additionalTags == null) {
additionalTags = new LinkedList<String>();
if(additionalTagsTable != null && tgid < additionalTagsTable.size()) {
additionalTags.add(additionalTagsTable.get(tgid));
}
}
break;
case OsmandOdb.CityIndex.ATTRIBUTEVALUES_FIELD_NUMBER:
String nm = codedIS.readString();
if(additionalTags != null && additionalTags.size() > 0) {
String tg = additionalTags.pollFirst();
if(tg.startsWith("name:")) {
c.setName(tg.substring("name:".length()), nm);
}
}
break;
case OsmandOdb.CityIndex.NAME_EN_FIELD_NUMBER :
String enName = codedIS.readString();
if (nameMatcher != null && enName.length() > 0 && nameMatcher.matches(enName)) {
englishNameMatched = true;
}
c.setEnName(enName);
break;
case OsmandOdb.CityIndex.NAME_FIELD_NUMBER :
String name = codedIS.readString();
if(nameMatcher != null){
if(!useEn){
if(!nameMatcher.matches(name)) {
codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return null;
}
} else if(nameMatcher.matches(Junidecode.unidecode(name))){
englishNameMatched = true;
}
}
if(c == null) {
c = City.createPostcode(name);
}
@ -246,9 +271,6 @@ public class BinaryMapAddressReaderAdapter {
case OsmandOdb.CityIndex.Y_FIELD_NUMBER :
y = codedIS.readUInt32();
c.setLocation(MapUtils.get31LatitudeY(y), MapUtils.get31LongitudeX(x));
if(c.getEnName().length() == 0){
c.setEnName(Junidecode.unidecode(c.getName()));
}
break;
case OsmandOdb.CityIndex.SHIFTTOCITYBLOCKINDEX_FIELD_NUMBER :
int offset = readInt();
@ -274,9 +296,6 @@ public class BinaryMapAddressReaderAdapter {
if(loadLocation){
s.setLocation(MapUtils.getLatitudeFromTile(24, y), MapUtils.getLongitudeFromTile(24, x));
}
if(s.getEnName().length() == 0){
s.setEnName(Junidecode.unidecode(s.getName()));
}
return s;
case OsmandOdb.StreetIndex.ID_FIELD_NUMBER :
s.setId(codedIS.readUInt64());
@ -347,9 +366,6 @@ public class BinaryMapAddressReaderAdapter {
switch (tag) {
case 0:
s.setLocation(MapUtils.getLatitudeFromTile(24, y), MapUtils.getLongitudeFromTile(24, x));
if(s.getEnName().length() == 0){
s.setEnName(Junidecode.unidecode(s.getName()));
}
return s;
case OsmandOdb.BuildingIndex.ID_FIELD_NUMBER :
s.setId(codedIS.readUInt64());
@ -389,9 +405,6 @@ public class BinaryMapAddressReaderAdapter {
if(x2 != 0 && y2 != 0) {
b.setLatLon2(new LatLon(MapUtils.getLatitudeFromTile(24, y2), MapUtils.getLongitudeFromTile(24, x2)));
}
if(b.getEnName().length() == 0){
b.setEnName(Junidecode.unidecode(b.getName()));
}
return b;
case OsmandOdb.BuildingIndex.ID_FIELD_NUMBER :
b.setId(codedIS.readUInt64());
@ -508,7 +521,7 @@ public class BinaryMapAddressReaderAdapter {
codedIS.seek(list.get(j + 1));
int len = codedIS.readRawVarint32();
int old = codedIS.pushLimit(len);
obj = readCityHeader(null, list.get(j + 1), false);
obj = readCityHeader(null, list.get(j + 1), null);
codedIS.popLimit(old);
}
if (obj != null) {
@ -519,8 +532,16 @@ public class BinaryMapAddressReaderAdapter {
Street s = new Street(obj);
readStreet(s, null, false, MapUtils.get31TileNumberX(l.getLongitude()) >> 7,
MapUtils.get31TileNumberY(l.getLatitude()) >> 7, obj.isPostcode() ? obj.getName() : null);
if (matcher.matches(s.getName())) {
boolean matches = matcher.matches(s.getName());
if(!matches) {
for(String n : s.getAllNames()) {
matches = matcher.matches(n);
if(matches) {
break;
}
}
}
if (matches) {
req.publish(s);
}
codedIS.popLimit(old);
@ -532,7 +553,7 @@ public class BinaryMapAddressReaderAdapter {
codedIS.seek(list.get(j));
int len = codedIS.readRawVarint32();
int old = codedIS.pushLimit(len);
City obj = readCityHeader(matcher, list.get(j), false);
City obj = readCityHeader(matcher, list.get(j), null);
if (obj != null) {
req.publish(obj);
}

View file

@ -554,9 +554,9 @@ public class BinaryMapIndexReader {
public List<City> getCities(String region, SearchRequest<City> resultMatcher,
int cityType) throws IOException {
return getCities(region, resultMatcher, null, false, cityType);
return getCities(region, resultMatcher, null, null, cityType);
}
public List<City> getCities(String region, SearchRequest<City> resultMatcher, StringMatcher matcher, boolean useEn,
public List<City> getCities(String region, SearchRequest<City> resultMatcher, StringMatcher matcher, String lang,
int cityType) throws IOException {
List<City> cities = new ArrayList<City>();
AddressRegion r = getRegionByName(region);
@ -567,7 +567,7 @@ public class BinaryMapIndexReader {
if(block.type == cityType) {
codedIS.seek(block.filePointer);
int old = codedIS.pushLimit(block.length);
addressAdapter.readCities(cities, resultMatcher, matcher, useEn);
addressAdapter.readCities(cities, resultMatcher, matcher, r.attributeTagsTable);
codedIS.popLimit(old);
}
}
@ -576,16 +576,16 @@ public class BinaryMapIndexReader {
public List<City> getCities(AddressRegion region, SearchRequest<City> resultMatcher,
int cityType) throws IOException {
return getCities(region, resultMatcher, null, false, cityType);
return getCities(region, resultMatcher, null, cityType);
}
public List<City> getCities(AddressRegion region, SearchRequest<City> resultMatcher, StringMatcher matcher, boolean useEn,
public List<City> getCities(AddressRegion region, SearchRequest<City> resultMatcher, StringMatcher matcher,
int cityType) throws IOException {
List<City> cities = new ArrayList<City>();
for(CitiesBlock block : region.cities) {
if(block.type == cityType) {
codedIS.seek(block.filePointer);
int old = codedIS.pushLimit(block.length);
addressAdapter.readCities(cities, resultMatcher, matcher, useEn);
addressAdapter.readCities(cities, resultMatcher, matcher, region.attributeTagsTable);
codedIS.popLimit(old);
}
}
@ -2272,7 +2272,7 @@ public class BinaryMapIndexReader {
reader.preloadBuildings(s, buildAddressRequest((ResultMatcher<Building>) null));
buildings += s.getBuildings().size();
}
println(c.getName() + " " + c.getLocation() + " " + c.getStreets().size() + " " + buildings + " " + c.getEnName());
println(c.getName() + " " + c.getLocation() + " " + c.getStreets().size() + " " + buildings + " " + c.getEnName(true));
}
// int[] count = new int[1];
List<City> villages = reader.getCities(reg, buildAddressRequest((ResultMatcher<City>) null), BinaryMapAddressReaderAdapter.VILLAGES_TYPE);

View file

@ -5,10 +5,7 @@ import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.hash.TIntLongHashMap;
import gnu.trove.set.hash.TLongHashSet;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@ -16,7 +13,6 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import net.osmand.Collator;
import net.osmand.CollatorStringMatcher;
@ -548,13 +544,13 @@ public class BinaryMapPoiReaderAdapter {
Amenity am = readPoiPoint(0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, x, y, zoom, req, region, false);
codedIS.popLimit(oldLim);
if (am != null) {
boolean matches = matcher.matches(am.getName(false).toLowerCase()) || matcher.matches(am.getName(true).toLowerCase());
boolean matches = matcher.matches(am.getName().toLowerCase()) ||
matcher.matches(am.getEnName(true).toLowerCase());
if (!matches) {
Iterator<Entry<String, String>> it = am.getAdditionalInfo().entrySet().iterator();
while (!matches && it.hasNext()) {
Entry<String, String> n = it.next();
if (n.getKey().startsWith("name:")) {
matches = matcher.matches(n.getValue().toLowerCase());
for(String s : am.getAllNames()) {
matches = matcher.matches(s.toLowerCase());
if(matches) {
break;
}
}
}
@ -663,9 +659,6 @@ public class BinaryMapPoiReaderAdapter {
}
switch (tag) {
case 0:
if(Algorithms.isEmpty(am.getEnName())){
am.setEnName(Junidecode.unidecode(am.getName()));
}
req.numberOfAcceptedObjects++;
if (req.radius > 0) {
LatLon loc = am.getLocation();

View file

@ -346,10 +346,10 @@ public class BinaryMapTransportReaderAdapter {
if(dataObject.getName().length() > 0){
dataObject.setName(stringTable.get(dataObject.getName().charAt(0)));
}
if(dataObject.getEnName().length() > 0){
dataObject.setEnName(stringTable.get(dataObject.getEnName().charAt(0)));
if(dataObject.getEnName(false).length() > 0){
dataObject.setEnName(stringTable.get(dataObject.getEnName(false).charAt(0)));
}
if(dataObject.getName().length() > 0 && dataObject.getEnName().length() == 0){
if(dataObject.getName().length() > 0 && dataObject.getName("en").length() == 0){
dataObject.setEnName(Junidecode.unidecode(dataObject.getName()));
}
@ -371,11 +371,8 @@ public class BinaryMapTransportReaderAdapter {
if (s.getName().length() > 0) {
s.setName(stringTable.get(s.getName().charAt(0)));
}
if (s.getEnName().length() > 0) {
s.setEnName(stringTable.get(s.getEnName().charAt(0)));
}
if (s.getEnName().length() == 0) {
s.setEnName(Junidecode.unidecode(s.getName()));
if (s.getEnName(false).length() > 0) {
s.setEnName(stringTable.get(s.getEnName(false).charAt(0)));
}
}
@ -445,7 +442,7 @@ public class BinaryMapTransportReaderAdapter {
switch (tag) {
case 0:
dataObject.setReferencesToRoutes(req.cacheTypes.toArray());
if(dataObject.getEnName().length() == 0){
if(dataObject.getName("en").length() == 0){
dataObject.setEnName(Junidecode.unidecode(dataObject.getName()));
}
return dataObject;

View file

@ -7,9 +7,12 @@ import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.zip.GZIPInputStream;
import net.osmand.Location;
@ -107,8 +110,15 @@ public class Amenity extends MapObject {
}
public void setAdditionalInfo(Map<String, String> additionalInfo) {
this.additionalInfo = additionalInfo;
openingHours = additionalInfo.get(OPENING_HOURS);
this.additionalInfo = null;
openingHours = null;
if(additionalInfo != null) {
Iterator<Entry<String, String>> it = additionalInfo.entrySet().iterator();
while(it.hasNext()) {
Entry<String, String> e = it.next();
setAdditionalInfo(e.getKey(), e.getValue());
}
}
}
public void setRoutePoint(AmenityRoutePoint routePoint) {
@ -120,14 +130,16 @@ public class Amenity extends MapObject {
}
public void setAdditionalInfo(String tag, String value) {
if(this.additionalInfo == null){
this.additionalInfo = new LinkedHashMap<String, String>();
}
if("name".equals(tag)) {
setName(value);
} else if("name:en".equals(tag)) {
setEnName(value);
} else if(tag.startsWith("name:")) {
setName(tag.substring("name:".length()), value);
} else {
if(this.additionalInfo == null){
this.additionalInfo = new LinkedHashMap<String, String>();
}
this.additionalInfo.put(tag, value);
if (OPENING_HOURS.equals(tag)) {
this.openingHours = value;
@ -187,29 +199,6 @@ public class Amenity extends MapObject {
return lng;
}
public String getName(String lang) {
if (lang != null) {
String translateName;
if (lang.equals("en")) {
translateName = getEnName();
} else {
translateName = getAdditionalInfo("name:" + lang);
}
if (!Algorithms.isEmpty(translateName)) {
return translateName;
}
}
if(!Algorithms.isEmpty(getName())) {
return getName();
}
for (String nm : getAdditionalInfo().keySet()) {
if (nm.startsWith("name:")) {
return getAdditionalInfo(nm);
}
}
return "";
}
public List<String> getNames(String tag, String defTag) {
List<String> l = new ArrayList<String>();
for (String nm : getAdditionalInfo().keySet()) {

View file

@ -72,12 +72,12 @@ public class Building extends MapObject {
}
@Override
public String getName(boolean en) {
String fname = super.getName(en);
if(interpolationInterval !=0){
return fname+"-"+name2 +" (+"+interpolationInterval+") ";
} else if(interpolationType != null) {
return fname+"-"+name2 +" ("+interpolationType.toString().toLowerCase()+") ";
public String getName(String lang) {
String fname = super.getName(lang);
if (interpolationInterval != 0) {
return fname + "-" + name2 + " (+" + interpolationInterval + ") ";
} else if (interpolationType != null) {
return fname + "-" + name2 + " (" + interpolationType.toString().toLowerCase() + ") ";
}
return name;
}

View file

@ -1,6 +1,8 @@
package net.osmand.data;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@ -41,9 +43,7 @@ public class City extends MapObject {
}
private CityType type = null;
// Be attentive ! Working with street names ignoring case
private Map<String, Street> streets = new TreeMap<String, Street>(OsmAndCollator.primaryCollator());
private String isin = null;
private List<Street> listOfStreets = new ArrayList<Street>();
private String postcode = null;
private City closestCity = null;
@ -73,18 +73,6 @@ public class City extends MapObject {
return type == null;
}
public boolean isEmptyWithStreets() {
return streets.isEmpty();
}
public Street unregisterStreet(String name) {
return streets.remove(name.toLowerCase());
}
public void removeAllStreets() {
streets.clear();
}
public String getPostcode() {
return postcode;
@ -102,24 +90,13 @@ public class City extends MapObject {
this.closestCity = closestCity;
}
protected Street registerStreet(Street street, boolean en) {
String name = en ? street.getEnName() : street.getName();
name = name.toLowerCase();
if (!Algorithms.isEmpty(name)) {
if (!streets.containsKey(name)) {
return streets.put(name, street);
} else {
// try to merge streets
Street prev = streets.get(name);
prev.mergeWith(street);
return prev;
}
}
return null;
public void registerStreet(Street street) {
listOfStreets.add(street);
}
public Street registerStreet(Street street) {
return registerStreet(street, false);
public void unregisterStreet(Street candidate) {
listOfStreets.remove(candidate);
}
public CityType getType() {
@ -127,12 +104,10 @@ public class City extends MapObject {
}
public Collection<Street> getStreets() {
return streets.values();
return listOfStreets;
}
public Street getStreet(String name) {
return streets.get(name.toLowerCase());
}
@Override
public String toString() {
@ -142,8 +117,25 @@ public class City extends MapObject {
return "City [" + type + "] " + getName(); //$NON-NLS-1$ //$NON-NLS-2$
}
public Street getStreetByName(String name) {
for(Street s : listOfStreets) {
if(s.getName().equalsIgnoreCase(name)) {
return s;
}
}
return null;
}
// GENERATION
// Be attentive ! Working with street names ignoring case
private String isin = null;
public void setIsin(String isin) {
this.isin = isin;
}
}

View file

@ -2,15 +2,25 @@ package net.osmand.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.osmand.Collator;
import net.osmand.OsmAndCollator;
import net.osmand.util.Algorithms;
import net.sf.junidecode.Junidecode;
public abstract class MapObject implements Comparable<MapObject>, Serializable {
protected String name = null;
protected String enName = null;
protected Map<String, String> names = null;
protected LatLon location = null;
protected int fileOffset = 0;
protected Long id = null;
@ -26,14 +36,6 @@ public abstract class MapObject implements Comparable<MapObject>, Serializable {
return null;
}
public String getName(boolean en){
if(en){
return getEnName();
} else {
return getName();
}
}
public String getName() {
if (this.name != null) {
return this.name;
@ -45,9 +47,77 @@ public abstract class MapObject implements Comparable<MapObject>, Serializable {
this.name = name;
}
public String getEnName() {
if(this.enName != null){
public void setName(String lang, String name) {
if(names == null) {
names = new HashMap<String, String>();
}
names.put(lang, name);
}
public List<String> getAllNames() {
List<String> l = new ArrayList<String>();
if(!Algorithms.isEmpty(enName)) {
l.add(enName);
}
if(names != null) {
l.addAll(names.values());
}
return l;
}
public void copyNames(MapObject s) {
if(Algorithms.isEmpty(name)) {
name = s.name;
}
if(Algorithms.isEmpty(enName)) {
enName = s.enName;
}
if(names == null) {
if(s.names != null) {
names = new HashMap<String, String>(s.names);
}
} else if(s.names != null){
Iterator<Entry<String, String>> it = s.names.entrySet().iterator();
while(it.hasNext()) {
Entry<String, String> e = it.next();
if(Algorithms.isEmpty(names.get(e.getKey()))) {
names.put(e.getKey(), e.getValue());
}
}
}
}
public String getName(String lang) {
return getName(lang, false);
}
public String getName(String lang, boolean transliterate) {
if (lang != null) {
if (lang.equals("en")) {
// ignore transliterate option here for backward compatibility
return getEnName(true);
} else {
// get name
if(names != null) {
String nm = names.get(lang);
if(!Algorithms.isEmpty(lang)) {
return nm;
}
if(transliterate) {
return Junidecode.unidecode(getName());
}
}
}
}
return getName();
}
public String getEnName(boolean transliterate) {
if(!Algorithms.isEmpty(enName)){
return this.enName;
} else if(!Algorithms.isEmpty(getName()) && transliterate){
return Junidecode.unidecode(getName());
}
return ""; //$NON-NLS-1$
}
@ -108,19 +178,15 @@ public abstract class MapObject implements Comparable<MapObject>, Serializable {
}
public static class MapObjectComparator implements Comparator<MapObject>{
private final boolean en;
private final String l;
Collator collator = OsmAndCollator.primaryCollator();
public MapObjectComparator(boolean en){
this.en = en;
public MapObjectComparator(String lang){
this.l = lang;
}
@Override
public int compare(MapObject o1, MapObject o2) {
if(en){
return collator.compare(o1.getEnName(), o2.getEnName());
} else {
return collator.compare(o1.getName(), o2.getName());
}
return collator.compare(o1.getName(l), o2.getName(l));
}
}

View file

@ -49,29 +49,7 @@ public class Street extends MapObject {
return buildings;
}
@Override
public void setName(String name) {
if (name.equals(getName())) {
return;
}
if (city != null && city.getStreet(getName()) == this) {
city.unregisterStreet(getName());
super.setName(name);
Street s = city.registerStreet(this);
} else {
super.setName(name);
}
}
public String getNameWithoutCityPart(boolean en) {
String nm = getName(en);
int t = nm.lastIndexOf('(');
if(t > 0) {
return nm.substring(0, t);
}
return nm;
}
public City getCity() {
return city;
@ -95,8 +73,22 @@ public class Street extends MapObject {
});
}
/// GENERATION
public void mergeWith(Street street) {
buildings.addAll(street.getBuildings());
copyNames(street);
}
public String getNameWithoutCityPart(String lang) {
String nm = getName(lang);
int t = nm.lastIndexOf('(');
if (t > 0) {
return nm.substring(0, t);
}
return nm;
}
}

View file

@ -23,11 +23,16 @@ public class EntityParser {
if (mo.getName().length() == 0) {
mo.setName(e.getTag(OSMTagKey.NAME));
}
if (mo.getEnName().length() == 0) {
if (mo.getEnName(false).length() == 0) {
mo.setEnName(e.getTag(OSMTagKey.NAME_EN));
if (mo.getName().length() == 0) {
mo.setName(mo.getEnName());
}
for(String ts : e.getTags().keySet()) {
if(ts.startsWith(OSMTagKey.NAME + ":") && !ts.equals(OSMTagKey.NAME_EN)) {
mo.setName(ts.substring((OSMTagKey.NAME + ":").length()), e.getTag(ts));
}
}
if (mo.getName().length() == 0) {
mo.setName(mo.getEnName(false));
}
if (mo.getLocation() == null) {
LatLon l = null;

View file

@ -921,11 +921,11 @@
<string name="pref_raster_map">Настройки онлайн карт</string>
<string name="pref_vector_map">Настройки локальных карт</string>
<string name="delete_confirmation_msg">Удалить %1$s?</string>
<string name="city_type_suburb">Пригород (suburb)</string>
<string name="city_type_hamlet">Деревня (hamlet)</string>
<string name="city_type_village">Село (village)</string>
<string name="city_type_town">Город (town)</string>
<string name="city_type_city">Город (city)</string>
<string name="city_type_suburb">Пригород</string>
<string name="city_type_hamlet">Деревня</string>
<string name="city_type_village">Село</string>
<string name="city_type_town">Город</string>
<string name="city_type_city">Крупный город</string>
<string name="animate_route_off">Закончить моделирование</string>
<string name="animate_route">Начать моделирование</string>
<string name="file_can_not_be_renamed">Файл не может быть переименован.</string>

View file

@ -525,10 +525,6 @@ public class SearchAddressFragment extends Fragment {
street = null;
building = null;
region = osmandSettings.getLastSearchedRegion();
RegionAddressRepository reg = getApplication().getResourceManager().getRegionRepository(region);
if(reg != null && reg.useEnglishNames() != osmandSettings.usingEnglishNames()){
reg.setUseEnglishNames(osmandSettings.usingEnglishNames());
}
loadData();
updateUI();

View file

@ -98,10 +98,10 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
if(obj.getInterpolationInterval() > 0 || obj.getInterpolationType() != null){
String hno = getCurrentFilter();
if(hno.length() > 0 && obj.belongsToInterpolation(hno)) {
return hno + " [" + obj.getName(region.useEnglishNames())+"]";
return hno + " [" + obj.getName(region.getLang())+"]";
}
}
return obj.getName(region.useEnglishNames());
return obj.getName(region.getLang());
}
@Override

View file

@ -164,6 +164,10 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
searchText.setText("");
}
public String getLangPreferredName(MapObject mo) {
return mo.getName(settings.MAP_PREFERRED_LOCALE.get());
}
protected void addFooterViews() {
}

View file

@ -64,9 +64,8 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
@Override
protected Comparator<? super City> createComparator() {
final boolean en = getMyApplication().getSettings().usingEnglishNames();
final StringMatcherMode startsWith = CollatorStringMatcher.StringMatcherMode.CHECK_ONLY_STARTS_WITH;
return new CityComparator(startsWith, en);
return new CityComparator(startsWith, getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get());
}
@Override
@ -157,33 +156,34 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
public String getText(City obj) {
LatLon l = obj.getLocation();
if (getCurrentFilter().length() > 2 ) {
String name = obj.getName(region.useEnglishNames());
if (obj.getType() != null) {
name += " [" + OsmAndFormatter.toPublicString(obj.getType(), getMyApplication()) + "]";
}
String name = obj.getName(region.getLang());
if(obj.getClosestCity() != null) {
name += " - " + obj.getClosestCity().getName(region.useEnglishNames()) ;
name += " - " + obj.getClosestCity().getName(region.getLang()) ;
LatLon loc = obj.getClosestCity().getLocation();
if(loc != null && l != null) {
name += " " + OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(l, loc), getMyApplication());
}
return name;
} else {
if (obj.getType() != null) {
name += " - " + OsmAndFormatter.toPublicString(obj.getType(), getMyApplication());
}
}
return name;
} else {
return obj.getName(region.useEnglishNames());
return obj.getName(region.getLang());
}
}
@Override
public String getShortText(City obj) {
return obj.getName(region.useEnglishNames());
return obj.getName(region.getLang());
}
@Override
public void itemSelected(City obj) {
settings.setLastSearchedCity(obj.getId(), obj.getName(region.useEnglishNames()), obj.getLocation());
if (region.getCityById(obj.getId(), obj.getName(region.useEnglishNames())) == null) {
settings.setLastSearchedCity(obj.getId(), obj.getName(region.getLang()), obj.getLocation());
if (region.getCityById(obj.getId(), obj.getName(region.getLang())) == null) {
region.addCityToPreloadedList((City) obj);
}
quitActivity(SearchStreetByNameActivity.class);
@ -197,13 +197,13 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
private final class CityComparator implements Comparator<City> {
private final StringMatcherMode startsWith;
private final net.osmand.Collator cs;
private final boolean en;
private final String lang ;
private CityComparator(StringMatcherMode startsWith,
boolean en) {
String lang ) {
this.startsWith = startsWith;
this.cs = OsmAndCollator.primaryCollator();
this.en = en;
this.lang = lang;
}
@Override
@ -214,8 +214,8 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
if (compare != 0) {
return compare;
}
boolean st1 = CollatorStringMatcher.cmatches(cs, lhs.getName(en), part, startsWith);
boolean st2 = CollatorStringMatcher.cmatches(cs, rhs.getName(en), part, startsWith);
boolean st1 = CollatorStringMatcher.cmatches(cs, lhs.getName(lang), part, startsWith);
boolean st2 = CollatorStringMatcher.cmatches(cs, rhs.getName(lang), part, startsWith);
if(st1 != st2) {
return st1 ? 1 : -1;
}

View file

@ -22,7 +22,7 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
@Override
protected Comparator<? super Street> createComparator() {
return new MapObjectComparator(getMyApplication().getSettings().usingEnglishNames());
return new MapObjectComparator(getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get());
}
@Override
@ -71,12 +71,12 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
@Override
public String getText(Street obj) {
return obj.getName(region.useEnglishNames());
return obj.getName(region.getLang());
}
@Override
public void itemSelected(Street obj) {
settings.setLastSearchedIntersectedStreet(obj.getName(region.useEnglishNames()), obj.getLocation());
settings.setLastSearchedIntersectedStreet(obj.getName(region.getLang()), obj.getLocation());
quitActivity(null);
}
}

View file

@ -38,7 +38,7 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
@Override
protected Comparator<? super Street> createComparator() {
return new MapObjectComparator(getMyApplication().getSettings().usingEnglishNames()) {
return new MapObjectComparator(getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get()) {
@Override
public int compare(MapObject o1, MapObject o2) {
if(searchWithCity >= 0 && city != null) {
@ -176,7 +176,7 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
if (namesFilter.isCancelled) {
break;
}
if (emptyQuery || CollatorStringMatcher.cmatches(collator, obj.getNameWithoutCityPart(region.useEnglishNames()),
if (emptyQuery || CollatorStringMatcher.cmatches(collator, obj.getNameWithoutCityPart(settings.MAP_PREFERRED_LOCALE.get()),
query, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) {
Message msg = uiHandler.obtainMessage(MESSAGE_ADD_ENTITY, obj);
msg.sendToTarget();
@ -187,7 +187,8 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
if (namesFilter.isCancelled) {
break;
}
if (CollatorStringMatcher.cmatches(collator, obj.getNameWithoutCityPart(region.useEnglishNames()), query, StringMatcherMode.CHECK_STARTS_FROM_SPACE_NOT_BEGINNING)) {
if (CollatorStringMatcher.cmatches(collator, obj.getNameWithoutCityPart(settings.MAP_PREFERRED_LOCALE.get()),
query, StringMatcherMode.CHECK_STARTS_FROM_SPACE_NOT_BEGINNING)) {
Message msg = uiHandler.obtainMessage(MESSAGE_ADD_ENTITY, obj);
msg.sendToTarget();
}
@ -198,10 +199,10 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
@Override
public String getText(Street obj) {
if(searchWithCity >= 0 || city == null) {
String nameWithCity = obj.getName(region.useEnglishNames()) + " - " + obj.getCity().getName(region.useEnglishNames());
String nameWithCity = getLangPreferredName(obj) + " - " + getLangPreferredName(obj.getCity());
return nameWithCity ;
}
return obj.getName(region.useEnglishNames());
return getLangPreferredName(obj);
}
@Override
@ -217,10 +218,10 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
@Override
public void itemSelected(Street obj) {
if(!Algorithms.objectEquals(settings.getLastSearchedCity(), obj.getCity().getId())) {
settings.setLastSearchedCity(obj.getCity().getId(), obj.getCity().getName(region.useEnglishNames()), obj.getLocation());
settings.setLastSearchedCity(obj.getCity().getId(), getLangPreferredName(obj.getCity()), obj.getLocation());
region.addCityToPreloadedList(obj.getCity());
}
settings.setLastSearchedStreet(obj.getName(region.useEnglishNames()), obj.getLocation());
settings.setLastSearchedStreet(getLangPreferredName(obj), obj.getLocation());
// if(obj.getBuildings().size() == 0){
// quitActivity(null);
// } else {

View file

@ -19,6 +19,8 @@ public interface RegionAddressRepository {
public String getFileName() ;
public String getLang();
public LatLon getEstimatedRegionCenter();
@ -28,11 +30,6 @@ public interface RegionAddressRepository {
// called to close resources
public void close();
public boolean useEnglishNames();
public void setUseEnglishNames(boolean useEnglishNames);
public void preloadCities(ResultMatcher<City> resultMatcher);
@ -62,12 +59,12 @@ public interface RegionAddressRepository {
public static class MapObjectNameDistanceComparator implements Comparator<MapObject> {
private final boolean useEnName;
private Collator collator = Collator.getInstance();
private final LatLon location;
private final String lang;
public MapObjectNameDistanceComparator(boolean useEnName, LatLon location){
this.useEnName = useEnName;
public MapObjectNameDistanceComparator(String lang, LatLon location){
this.lang = lang;
this.location = location;
}
@ -76,7 +73,7 @@ public interface RegionAddressRepository {
if(object1 == null || object2 == null){
return object2 == object1 ? 0 : (object1 == null ? -1 : 1);
} else {
int c = collator.compare(object1.getName(useEnName), object2.getName(useEnName));
int c = collator.compare(object1.getName(lang), object2.getName(lang));
if(c == 0 && location != null){
LatLon l1 = object1.getLocation();
LatLon l2 = object2.getLocation();

View file

@ -25,6 +25,8 @@ import net.osmand.data.MapObject;
import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree;
import net.osmand.data.Street;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
@ -41,11 +43,14 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
private QuadTree<City> citiesQtree = new QuadTree<City>(new QuadRect(0, 0, 1 << (ZOOM_QTREE + 1),
1 << (ZOOM_QTREE + 1)), 8, 0.55f);
private final Map<String, City> postCodes;
private boolean useEnglishNames = false;
private final Collator collator;
private String fileName;
private ResourceManager mgr;
private OsmandPreference<String> langSetting;
public RegionAddressRepositoryBinary(BinaryMapIndexReader file, String name, String fileName) {
public RegionAddressRepositoryBinary(ResourceManager mgr, BinaryMapIndexReader file, String name, String fileName) {
this.mgr = mgr;
langSetting = mgr.getContext().getSettings().MAP_PREFERRED_LOCALE;
this.file = file;
this.region = name;
this.fileName = fileName;
@ -179,12 +184,13 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
return citiesToFill;
}
try {
String lang = getLang();
// essentially index is created that cities towns are first in cities map
if (/*name.length() >= 2 && Algorithms.containsDigit(name) && */searchVillages) {
// also try to identify postcodes
String uName = name.toUpperCase();
List<City> foundCities = file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher),
new CollatorStringMatcher(uName, StringMatcherMode.CHECK_CONTAINS), false,
new CollatorStringMatcher(uName, StringMatcherMode.CHECK_CONTAINS), lang,
BinaryMapAddressReaderAdapter.POSTCODES_TYPE);
for (City code : foundCities) {
citiesToFill.add(code);
@ -196,7 +202,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
}
name = name.toLowerCase();
for (City c : cities.values()) {
String cName = c.getName(useEnglishNames); // lower case not needed, collator ensures that
String cName = c.getName(lang); // lower case not needed, collator ensures that
if (CollatorStringMatcher.cmatches(collator, cName, name, StringMatcherMode.CHECK_STARTS_FROM_SPACE)) {
if (resultMatcher.publish(c)) {
citiesToFill.add(c);
@ -225,8 +231,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
public boolean isCancelled() {
return resultMatcher.isCancelled();
}
}),
new CollatorStringMatcher(name,StringMatcherMode.CHECK_STARTS_FROM_SPACE), useEnglishNames,
}), new CollatorStringMatcher(name,StringMatcherMode.CHECK_STARTS_FROM_SPACE), lang,
BinaryMapAddressReaderAdapter.VILLAGES_TYPE);
for (City c : foundCities) {
@ -243,6 +248,11 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
return citiesToFill;
}
@Override
public String getLang() {
return langSetting.get();
}
@Override
public List<Street> getStreetsIntersectStreets(Street st) {
preloadBuildings(st, null);
@ -253,8 +263,9 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
@Override
public Building getBuildingByName(Street street, String name) {
preloadBuildings(street, null);
String lang = getLang();
for (Building b : street.getBuildings()) {
String bName = b.getName(useEnglishNames);
String bName = b.getName(lang);
if (bName.equals(name)) {
return b;
}
@ -277,11 +288,6 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
return getName() + " repository";
}
@Override
public boolean useEnglishNames() {
return useEnglishNames;
}
@Override
public City getCityById(final long id, String name) {
if (id == -1) {
@ -330,22 +336,16 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
name = name.toLowerCase();
preloadStreets(o, null);
Collection<Street> streets = o.getStreets() ;
String lang = getLang();
for (Street s : streets) {
String sName = useEnglishNames ? s.getEnName() : s.getName(); //lower case not needed, collator ensures that
if (collator.equals(sName,name)) {
String sName = s.getName(lang).toLowerCase();
if (collator.equals(sName, name)) {
return s;
}
}
return null;
}
@Override
public void setUseEnglishNames(boolean useEnglishNames) {
this.useEnglishNames = useEnglishNames;
}
@Override
public void clearCache() {
cities = new LinkedHashMap<Long, City>();

View file

@ -644,7 +644,7 @@ public class ResourceManager {
for (String rName : index.getRegionNames()) {
// skip duplicate names (don't make collision between getName() and name in the map)
// it can be dangerous to use one file to different indexes if it is multithreaded
RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(index, rName, f.getName());
RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(this, index, rName, f.getName());
addressMap.put(rName, rarb);
}
if (index.hasTransportData()) {

View file

@ -101,7 +101,7 @@ public class TransportIndexRepositoryBinary implements TransportIndexRepository
List<TransportRoute> routes = file.getTransportRouteDescriptions(stop);
if(routes != null){
for(TransportRoute route : routes){
res.add(f.format(new String[] { route.getRef() + "", route.getType() + "", route.getName() + "", route.getEnName() + "" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
res.add(f.format(new String[] { route.getRef() + "", route.getType() + "", route.getName() + "", route.getEnName(true) + "" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
}
} catch (IOException e) {

View file

@ -139,7 +139,7 @@ public class TransportInfoLayer extends OsmandMapLayer {
int x = (int) tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
int y = (int) tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
if (Math.abs(x - ex) < getRadius(tileBox) * 3 /2 && Math.abs(y - ey) < getRadius(tileBox) * 3 /2) {
AccessibleToast.makeText(view.getContext(), st.getName(view.getSettings().usingEnglishNames()) + " : " + //$NON-NLS-1$
AccessibleToast.makeText(view.getContext(), st.getName(view.getSettings().MAP_PREFERRED_LOCALE.get()) + " : " + //$NON-NLS-1$
route.getType() + " " + route.getRef() //$NON-NLS-1$
, Toast.LENGTH_LONG).show();
return true;

View file

@ -97,7 +97,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
private String getStopDescription(TransportStop n, boolean useName) {
StringBuilder text = new StringBuilder(250);
text.append(view.getContext().getString(R.string.transport_Stop))
.append(" : ").append(n.getName(view.getSettings().usingEnglishNames())); //$NON-NLS-1$
.append(" : ").append(n.getName(view.getSettings().MAP_PREFERRED_LOCALE.get())); //$NON-NLS-1$
text.append("\n").append(view.getContext().getString(R.string.transport_Routes)).append(" : "); //$NON-NLS-1$ //$NON-NLS-2$
List<TransportIndexRepository> reps = view.getApplication().getResourceManager().searchTransportRepositories(
n.getLocation().getLatitude(), n.getLocation().getLongitude());
@ -185,7 +185,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
private void showDescriptionDialog(TransportStop a) {
Builder bs = new AlertDialog.Builder(view.getContext());
bs.setTitle(a.getName(view.getSettings().usingEnglishNames()));
bs.setTitle(a.getName(view.getSettings().MAP_PREFERRED_LOCALE.get()));
bs.setMessage(getStopDescription(a, true));
bs.show();
}