Skip to content

Commit

Permalink
Introduce (ref:XX) language and transliteration support for getRef
Browse files Browse the repository at this point in the history
  • Loading branch information
sonora committed Dec 4, 2016
1 parent c8f2101 commit ba04890
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 21 deletions.
4 changes: 2 additions & 2 deletions OsmAnd-java/src/net/osmand/binary/GeocodingUtilities.java
Expand Up @@ -173,14 +173,14 @@ public List<GeocodingResult> reverseGeocodingSearch(RoutingContext ctx, double l
continue;
}
// System.out.println(road.toString() + " " + Math.sqrt(p.distSquare));
boolean emptyName = Algorithms.isEmpty(road.getName()) && Algorithms.isEmpty(road.getRef(true));
boolean emptyName = Algorithms.isEmpty(road.getName()) && Algorithms.isEmpty(road.getRef("", false, true));
if (!emptyName) {
if (distSquare == 0 || distSquare > p.distSquare) {
distSquare = p.distSquare;
}
GeocodingResult sr = new GeocodingResult();
sr.searchPoint = new LatLon(lat, lon);
sr.streetName = Algorithms.isEmpty(road.getName()) ? road.getRef(true) : road.getName();
sr.streetName = Algorithms.isEmpty(road.getName()) ? road.getRef("", false, true) : road.getName();
sr.point = p;
sr.connectionPoint = new LatLon(MapUtils.get31LatitudeY(p.preciseY), MapUtils.get31LongitudeX(p.preciseX));
sr.regionFP = road.region.getFilePointer();
Expand Down
35 changes: 26 additions & 9 deletions OsmAnd-java/src/net/osmand/binary/RouteDataObject.java
Expand Up @@ -70,8 +70,7 @@ public String getName(){
}
return null;
}



public String getName(String lang){
return getName(lang, false);
}
Expand Down Expand Up @@ -106,13 +105,29 @@ public int[] getNameIds() {
public TIntObjectHashMap<String> getNames() {
return names;
}
public String getRef(boolean direction) {

public String getRef(String lang, boolean transliterate, boolean direction) {
//if (getDestinationRef(direction) != null) {
// return getDestinationRef(direction);
//}
if (names != null) {
return names.get(region.refTypeRule);
if(Algorithms.isEmpty(lang)) {
return names.get(region.refTypeRule);
}
int[] kt = names.keys();
for(int i = 0 ; i < kt.length; i++) {
int k = kt[i];
if(region.routeEncodingRules.size() > k) {
if(("ref:"+lang).equals(region.routeEncodingRules.get(k).getTag())) {
return names.get(k);
}
}
}
String refDefault = names.get(region.refTypeRule);
if(transliterate && refDefault != null && refDefault.length() > 0) {
return Junidecode.unidecode(refDefault);
}
return refDefault;
}
return null;
}
Expand Down Expand Up @@ -145,7 +160,7 @@ public String getDestinationRef(boolean direction) {

public String getDestinationName(String lang, boolean transliterate, boolean direction){
//Issue #3289: Treat destination:ref like a destination, not like a ref
String destRef = ((getDestinationRef(direction) == null) || getDestinationRef(direction).equals(getRef(direction))) ? "" : getDestinationRef(direction);
String destRef = ((getDestinationRef(direction) == null) || getDestinationRef(direction).equals(getRef(lang, transliterate, direction))) ? "" : getDestinationRef(direction);
String destRef1 = ("".equals(destRef)) ? "" : destRef + ", ";

if(names != null) {
Expand Down Expand Up @@ -186,8 +201,10 @@ public String getDestinationName(String lang, boolean transliterate, boolean dir
}
}
}
if(destinationDefault != null) {
return destRef1 + ((transliterate) ? Junidecode.unidecode(destinationDefault) : destinationDefault);
if(transliterate && destinationDefault != null) {
return destRef1 + Junidecode.unidecode(destinationDefault);
} else if (destinationDefault != null) {
return destRef1 + destinationDefault;
}
}
return "".equals(destRef) ? null : destRef;
Expand Down Expand Up @@ -601,7 +618,7 @@ public String coordinates() {
@Override
public String toString() {
String name = getName();
String rf = getRef(true);
String rf = getRef("", false, true);
return MessageFormat.format("Road id {0} name {1} ref {2}", (getId() / 64) + "", name == null ? "" : name,
rf == null ? "" : rf);
}
Expand Down
Expand Up @@ -334,7 +334,7 @@ void printResults(RoutingContext ctx, LatLon start, LatLon end, List<RouteSegmen
if (PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST) {
for (RouteSegmentResult res : result) {
String name = res.getObject().getName();
String ref = res.getObject().getRef(res.isForwardDirection());
String ref = res.getObject().getRef("", false, res.isForwardDirection());
if (name == null) {
name = "";
}
Expand Down
2 changes: 1 addition & 1 deletion OsmAnd/src/net/osmand/plus/GeocodingLookupService.java
Expand Up @@ -159,7 +159,7 @@ public boolean publish(GeocodingResult object) {
if (Algorithms.isEmpty(sname)) {
sname = "";
}
String ref = rd.getRef(true);
String ref = rd.getRef(lang, transliterate, true);
if (!Algorithms.isEmpty(ref)) {
if (!Algorithms.isEmpty(sname)) {
sname += ", ";
Expand Down
5 changes: 3 additions & 2 deletions OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java
Expand Up @@ -112,8 +112,9 @@ public void removeImpassableRoad(RouteDataObject obj) {
protected String getText(RouteDataObject obj) {
return RoutingHelper.formatStreetName(obj.getName(app.getSettings().MAP_PREFERRED_LOCALE.get(),
app.getSettings().MAP_TRANSLITERATE_NAMES.get()),
obj.getRef(true), obj.getDestinationName(app.getSettings().MAP_PREFERRED_LOCALE.get(),
app.getSettings().MAP_TRANSLITERATE_NAMES.get(), true), app.getString(R.string.towards));
obj.getRef(app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get(), true),
obj.getDestinationName(app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get(), true),
app.getString(R.string.towards));
}

public void showDialog(@NonNull final MapActivity mapActivity) {
Expand Down
Expand Up @@ -259,7 +259,8 @@ private static List<RouteSegmentResult> convertVectorResult(List<RouteDirectionI
info.routeEndPointOffset = roundAboutEnd;
}
RouteSegmentResult next = list.get(lind);
info.setRef(next.getObject().getRef(next.isForwardDirection()));
info.setRef(next.getObject().getRef(ctx.getSettings().MAP_PREFERRED_LOCALE.get(),
ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection()));
info.setStreetName(next.getObject().getName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(),
ctx.getSettings().MAP_TRANSLITERATE_NAMES.get()));
info.setDestinationName(next.getObject().getDestinationName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(),
Expand Down
2 changes: 1 addition & 1 deletion OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java
Expand Up @@ -774,7 +774,7 @@ public synchronized String getCurrentName(TurnType[] next){
RouteSegmentResult rs = getCurrentSegmentResult();
if(rs != null) {
String nm = rs.getObject().getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get());
String rf = rs.getObject().getRef(rs.isForwardDirection());
String rf = rs.getObject().getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
String dn = rs.getObject().getDestinationName(settings.MAP_PREFERRED_LOCALE.get(),
settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
return formatStreetName(nm, rf, dn, "»");
Expand Down
6 changes: 4 additions & 2 deletions OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java
Expand Up @@ -586,13 +586,15 @@ public Term getSpeakableStreetName(RouteSegmentResult currentSegment, RouteDirec
// Issue 2377: Play Dest here only if not already previously announced, to avoid repetition
if (includeDest == true) {
RouteDataObject obj = currentSegment.getObject();
current = new Struct(new Term[] { getTermString(getSpeakablePointName(obj.getRef(currentSegment.isForwardDirection()))),
current = new Struct(new Term[] { getTermString(getSpeakablePointName(obj.getRef(settings.MAP_PREFERRED_LOCALE.get(),
settings.MAP_TRANSLITERATE_NAMES.get(), currentSegment.isForwardDirection()))),
getTermString(getSpeakablePointName(obj.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()))),
getTermString(getSpeakablePointName(obj.getDestinationName(settings.MAP_PREFERRED_LOCALE.get(),
settings.MAP_TRANSLITERATE_NAMES.get(), currentSegment.isForwardDirection()))) });
} else {
RouteDataObject obj = currentSegment.getObject();
current = new Struct(new Term[] { getTermString(getSpeakablePointName(obj.getRef(currentSegment.isForwardDirection()))),
current = new Struct(new Term[] { getTermString(getSpeakablePointName(obj.getRef(settings.MAP_PREFERRED_LOCALE.get(),
settings.MAP_TRANSLITERATE_NAMES.get(), currentSegment.isForwardDirection()))),
getTermString(getSpeakablePointName(obj.getName(settings.MAP_PREFERRED_LOCALE.get(),
settings.MAP_TRANSLITERATE_NAMES.get()))),
empty });
Expand Down
Expand Up @@ -585,7 +585,7 @@ public boolean updateInfo(DrawSettings d) {
if (rt != null) {
text = RoutingHelper.formatStreetName(
rt.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()),
rt.getRef(rt.bearingVsRouteDirection(locationProvider.getLastKnownLocation())),
rt.getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(locationProvider.getLastKnownLocation())),
rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(locationProvider.getLastKnownLocation())),
"»");
}
Expand Down
Expand Up @@ -159,7 +159,7 @@ public boolean publish(GeocodingResult object) {
if (Algorithms.isEmpty(sname)) {
sname = "";
}
String ref = rd.getRef(true);
String ref = rd.getRef(lang, transliterate, true);
if (!Algorithms.isEmpty(ref)) {
if (!Algorithms.isEmpty(sname)) {
sname += ", ";
Expand Down

0 comments on commit ba04890

Please sign in to comment.