generate OpenStreetMap shortlinks using current char set (~ instead of @)

OpenStreetMap has changed the shortlink charset to use ~ instead of @ to be
support services like Twitter where @ has meaning.  OpenStreetMap still will
parse the old format, but only generates new shortlinks using "~".  This
commit changes OsmAnd to have the same behavior.

References:
https://wiki.openstreetmap.org/wiki/Shortlink#Code_for_encoding_.26_decoding
e84b2bd22f/app/assets/javascripts/application.js (L188)

---------------- OsmAnd-java/src/net/osmand/util/MapUtils.java ----------------
This commit is contained in:
Hans-Christoph Steiner 2015-01-13 12:09:14 +01:00
parent 50eed92015
commit 9bb03894a5
2 changed files with 23 additions and 1 deletions

View file

@ -172,6 +172,22 @@ public class GeoPointParserUtil {
actual = GeoPointParserUtil.parse(url); actual = GeoPointParserUtil.parse(url);
assertApproximateGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); assertApproximateGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
// http://osm.org/go/TyFYuF6P~~-?m // current shortlink format with "~"
// https://www.openstreetmap.org/?mlat=34.993933029174805&mlon=-106.61568069458008#map=15/34.99393/-106.61568
z = 20;
url = "http://osm.org/go/TyFYuF6P~~-?m";
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url);
assertApproximateGeoPoint(actual, new GeoParsedPoint(longLat, longLon, z));
// http://osm.org/go/TyFYuF6P@@--?m= // old, deprecated shortlink format with "@"
// https://www.openstreetmap.org/?mlat=34.993933029174805&mlon=-106.61568069458008#map=15/34.99393/-106.61568
z = 21;
url = "http://osm.org/go/TyFYuF6P@@--?m=";
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url);
assertApproximateGeoPoint(actual, new GeoParsedPoint(longLat, longLon, z));
// http://openstreetmap.de/zoom=11&lat=34&lon=-106 // http://openstreetmap.de/zoom=11&lat=34&lon=-106
z = 11; z = 11;
url = "http://openstreetmap.de/zoom=" + z + "&lat=" + ilat + "&lon=" + ilon; url = "http://openstreetmap.de/zoom=" + z + "&lat=" + ilat + "&lon=" + ilon;
@ -355,6 +371,10 @@ public class GeoPointParserUtil {
"http://osm.org/go/0LQ127-?m", "http://osm.org/go/0LQ127-?m",
"http://osm.org/go/0EEQjE==", "http://osm.org/go/0EEQjE==",
"http://osm.org/go/0EEQjEEb", "http://osm.org/go/0EEQjEEb",
"http://osm.org/go/0EE~jEEb",
"http://osm.org/go/0EE@jEEb",
"http://osm.org/go/~~~~",
"http://osm.org/go/@@@@",
"https://www.openstreetmap.org/#map=0/0/0", "https://www.openstreetmap.org/#map=0/0/0",
"https://www.openstreetmap.org/#map=0/180/180", "https://www.openstreetmap.org/#map=0/180/180",
"https://www.openstreetmap.org/#map=0/-180/-180", "https://www.openstreetmap.org/#map=0/-180/-180",

View file

@ -35,7 +35,7 @@ public class MapUtils {
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '@' '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '~'
}; };
public static double getDistance(LatLon l, double latitude, double longitude){ public static double getDistance(LatLon l, double latitude, double longitude){
@ -308,6 +308,8 @@ public class MapUtils {
} }
public static GeoParsedPoint decodeShortLinkString(String s) { public static GeoParsedPoint decodeShortLinkString(String s) {
// convert old shortlink format to current one
s = s.replaceAll("@", "~");
int i = 0; int i = 0;
long x = 0; long x = 0;
long y = 0; long y = 0;