[API] Suggested changes
Signed-off-by: hemanggs <hemangmanhas@gmail.com>
This commit is contained in:
parent
f1f4994638
commit
b3d5a6a23d
6 changed files with 40 additions and 56 deletions
|
@ -985,9 +985,8 @@ Java_app_organicmaps_Framework_nativeGetCoordUrl(JNIEnv * env, jclass, jdouble l
|
|||
{
|
||||
::Framework * fr = frm();
|
||||
double const scale = (zoomLevel > 0 ? zoomLevel : fr->GetDrawScale());
|
||||
std::string nameStr = jni::ToNativeString(env, name);
|
||||
static const char kHttpSharePrefix[] = "https://omaps.app/";
|
||||
string const url = ge0::GenerateCoordUrl(lat, lon, scale, nameStr);
|
||||
std::string const nameStr = jni::ToNativeString(env, name);
|
||||
std::string const url = ge0::GenerateCoordUrl(lat, lon, scale, nameStr);
|
||||
return jni::ToJavaString(env, url);
|
||||
|
||||
}
|
||||
|
|
|
@ -149,10 +149,6 @@ public class Framework
|
|||
return nativeGetGe0Url(lat, lon, zoomLevel, name).replaceFirst(
|
||||
Constants.Url.SHORT_SHARE_PREFIX, Constants.Url.HTTP_SHARE_PREFIX);
|
||||
}
|
||||
public static String getCoordUrl(double lat, double lon, double zoomLevel, String name)
|
||||
{
|
||||
return nativeGetCoordUrl(lat, lon, zoomLevel, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Bitmap with route altitude image chart taking into account current map style.
|
||||
|
|
|
@ -120,9 +120,7 @@ public class SharingUtils
|
|||
final String subject = context.getString(R.string.share);
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
|
||||
|
||||
final String geoUrl = Framework.nativeGetGe0Url(loc.getLatitude(), loc.getLongitude(), Framework
|
||||
.nativeGetDrawScale(), "");
|
||||
final String coordUrl = Framework.getCoordUrl(loc.getLatitude(), loc.getLongitude(), Framework
|
||||
final String coordUrl = Framework.nativeGetCoordUrl(loc.getLatitude(), loc.getLongitude(), Framework
|
||||
.nativeGetDrawScale(), "");
|
||||
final String httpUrl = Framework.getHttpGe0Url(loc.getLatitude(), loc.getLongitude(), Framework
|
||||
.nativeGetDrawScale(), "");
|
||||
|
@ -142,10 +140,8 @@ public class SharingUtils
|
|||
context.getString(R.string.bookmark_share_email_subject);
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
|
||||
|
||||
final String geoUrl = Framework.nativeGetGe0Url(object.getLat(), object.getLon(),
|
||||
object.getScale(), object.getName());
|
||||
final String coordUrl = Framework.getCoordUrl(object.getLat(), object.getLon(),
|
||||
object.getScale(), object.getName());
|
||||
final String coordUrl = Framework.nativeGetCoordUrl(object.getLat(), object.getLon(),
|
||||
object.getScale(), object.getName());
|
||||
final String httpUrl = Framework.getHttpGe0Url(object.getLat(), object.getLon(),
|
||||
object.getScale(), object.getName());
|
||||
final String address = TextUtils.isEmpty(object.getAddress()) ? object.getName() : object.getAddress();
|
||||
|
@ -163,10 +159,8 @@ public class SharingUtils
|
|||
final String subject = context.getString(R.string.bookmark_share_email_subject);
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
|
||||
|
||||
final String geoUrl = Framework.nativeGetGe0Url(bookmark.getLat(), bookmark.getLon(),
|
||||
bookmark.getScale(), bookmark.getName());
|
||||
final String coordUrl = Framework.getCoordUrl(bookmark.getLat(), bookmark.getLon(),
|
||||
bookmark.getScale(), bookmark.getName());
|
||||
final String coordUrl = Framework.nativeGetCoordUrl(bookmark.getLat(), bookmark.getLon(),
|
||||
bookmark.getScale(), bookmark.getName());
|
||||
final String httpUrl = Framework.getHttpGe0Url(bookmark.getLat(), bookmark.getLon(),
|
||||
bookmark.getScale(), bookmark.getName());
|
||||
StringBuilder text = new StringBuilder();
|
||||
|
|
|
@ -344,12 +344,15 @@ UNIT_TEST(PlainCoordinateUrl_Valid)
|
|||
TestSuccess("https://omaps.app/12.34567,76.54321,10.5", 12.34567, 76.54321, 10.5, "");
|
||||
TestSuccess("https://omaps.app/12.34567,76.54321,15.75/Place", 12.34567, 76.54321, 15.75, "Place");
|
||||
TestSuccess("https://omaps.app/13.02227,77.76043,18.0", 13.02227, 77.76043, 18.0, "");
|
||||
TestSuccess("https://omaps.app/13.02227,77.76043,18.0#", 13.02227, 77.76043, 18.0, "");
|
||||
TestSuccess("https://omaps.app/13.02227,77.76043,18.0?", 13.02227, 77.76043, 18.0, "");
|
||||
TestSuccess("https://omaps.app/13.02227,77.76043,20/AnotherPlace", 13.02227, 77.76043, 20.0, "AnotherPlace");
|
||||
TestSuccess("https://omaps.app/13.02227,77.76043,17.5/Place///?foo=bar#section", 13.02227, 77.76043, 17.5, "Place");
|
||||
|
||||
// Out of range clamping
|
||||
TestSuccess("https://omaps.app/13.02227,77.76043,100", 13.02227, 77.76043, 20.0, "");
|
||||
TestSuccess("https://omaps.app/13.02227,77.76043,0.5", 13.02227, 77.76043, 1.0, "");
|
||||
TestSuccess("https://omaps.app/13.02227,77.76043,-0.5", 13.02227, 77.76043, 1.0, "");
|
||||
TestSuccess("https://omaps.app/13.02227,77.76043,22.5", 13.02227, 77.76043, 20.0, "");
|
||||
|
||||
TestSuccess("https://omaps.app/13.02227,77.76043,abc", 13.02227, 77.76043, 17.0, "");
|
||||
|
|
|
@ -342,40 +342,32 @@ UNIT_TEST(GenerateShortShowMapUrl_UnicodeMixedWithOtherChars)
|
|||
TEST_EQUAL("om://8wAAAAAAAA/Back%20in_\xe2\x98\x84%21\xd1\x8e\xd0\xbc", res, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GenerateCoordUrl_SmokeTest)
|
||||
UNIT_TEST(PlainCoordinateUrl_Valid_Generator)
|
||||
{
|
||||
string res = GenerateCoordUrl(0, 0, 19, "Name");
|
||||
TEST_EQUAL("https://omaps.app/0.00000,0.00000,19/Name", res, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GenerateCoordUrl_NameIsEmpty)
|
||||
{
|
||||
string res = GenerateCoordUrl(0, 0, 19, "");
|
||||
TEST_EQUAL("https://omaps.app/0.00000,0.00000,19", res, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GenerateCoordUrl_SpaceIsReplacedWithUnderscore)
|
||||
{
|
||||
string res = GenerateCoordUrl(0, 0, 19, "Hello World");
|
||||
TEST_EQUAL("https://omaps.app/0.00000,0.00000,19/Hello_World", res, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GenerateCoordUrl_UnderscoreIsReplacedWithSpaceEncoded)
|
||||
{
|
||||
string res = GenerateCoordUrl(0, 0, 19, "Hello_World");
|
||||
TEST_EQUAL("https://omaps.app/0.00000,0.00000,19/Hello%20World", res, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GenerateCoordUrl_ControlCharsAreEscaped)
|
||||
{
|
||||
string res = GenerateCoordUrl(0, 0, 19, "Hello\tWorld\n");
|
||||
TEST_EQUAL("https://omaps.app/0.00000,0.00000,19/Hello%09World%0A", res, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GenerateCoordUrl_FractionalZoom)
|
||||
{
|
||||
string res = GenerateCoordUrl(10, 20, 8.25, "Name");
|
||||
TEST_EQUAL("https://omaps.app/10.00000,20.00000,8/Name", res, ());
|
||||
{
|
||||
auto const url = GenerateCoordUrl(0, 0, 19, "Name");
|
||||
TEST_EQUAL("https://omaps.app/0.00000,0.00000,19/Name", url, ());
|
||||
}
|
||||
{
|
||||
auto const url = GenerateCoordUrl(0, 0, 19, "");
|
||||
TEST_EQUAL("https://omaps.app/0.00000,0.00000,19", url, ());
|
||||
}
|
||||
{
|
||||
auto const url = GenerateCoordUrl(0, 0, 19, "Hello World");
|
||||
TEST_EQUAL("https://omaps.app/0.00000,0.00000,19/Hello_World", url, ());
|
||||
}
|
||||
{
|
||||
auto const url = GenerateCoordUrl(0, 0, 19, "Hello_World");
|
||||
TEST_EQUAL("https://omaps.app/0.00000,0.00000,19/Hello%20World", url, ());
|
||||
}
|
||||
{
|
||||
auto const url = GenerateCoordUrl(0, 0, 19, "Hello\tWorld\n");
|
||||
TEST_EQUAL("https://omaps.app/0.00000,0.00000,19/Hello%09World%0A", url, ());
|
||||
}
|
||||
{
|
||||
auto const url = GenerateCoordUrl(10, 20, 8.25, "Name");
|
||||
TEST_EQUAL("https://omaps.app/10.00000,20.00000,8/Name", url, ());
|
||||
}
|
||||
}
|
||||
|
||||
UNIT_TEST(GenerateGeoUri_SmokeTest)
|
||||
|
|
|
@ -105,17 +105,17 @@ std::string GenerateShortShowMapUrl(double lat, double lon, double zoom, std::st
|
|||
|
||||
std::string GenerateCoordUrl(double lat, double lon, double zoom, std::string const & name)
|
||||
{
|
||||
static const std::string kHttpSharePrefix = "https://omaps.app/";
|
||||
std::string url = kHttpSharePrefix;
|
||||
std::string url = "https://omaps.app/";
|
||||
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "%.5f,%.5f,%.0f", lat, lon, zoom);
|
||||
auto const writtenChars = snprintf(buf, sizeof(buf), "%.5f,%.5f,%.0f", lat, lon, zoom);
|
||||
CHECK(writtenChars > 0 && writtenChars < static_cast<int>(sizeof(buf)), ("Buffer is too small", writtenChars, lat, lon, zoom));
|
||||
url.append(buf);
|
||||
|
||||
if (!name.empty())
|
||||
{
|
||||
url.push_back('/');
|
||||
url.append(UrlEncodeString(TransformName(name)));
|
||||
url.push_back('/');
|
||||
url.append(UrlEncodeString(TransformName(name)));
|
||||
}
|
||||
|
||||
return url;
|
||||
|
|
Reference in a new issue