[core] [android] - public api configurable base endpoint (#6309)
add runloop to test
This commit is contained in:
@@ -29,6 +29,9 @@ public:
|
||||
bool supportsOptionalRequests() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
void setAPIBaseURL(const std::string&);
|
||||
std::string getAPIBaseURL() const;
|
||||
|
||||
void setAccessToken(const std::string&);
|
||||
std::string getAccessToken() const;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -9,6 +10,9 @@ public:
|
||||
OnlineFileSource();
|
||||
~OnlineFileSource() override;
|
||||
|
||||
void setAPIBaseURL(const std::string& t) { apiBaseURL = t; }
|
||||
std::string getAPIBaseURL() const { return apiBaseURL; }
|
||||
|
||||
void setAccessToken(const std::string& t) { accessToken = t; }
|
||||
std::string getAccessToken() const { return accessToken; }
|
||||
|
||||
@@ -20,6 +24,7 @@ private:
|
||||
class Impl;
|
||||
const std::unique_ptr<Impl> impl;
|
||||
std::string accessToken;
|
||||
std::string apiBaseURL = mbgl::util::API_BASE_URL;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -45,6 +45,8 @@ constexpr UnitBezier DEFAULT_TRANSITION_EASE = { 0, 0, 0.25, 1 };
|
||||
|
||||
constexpr int DEFAULT_RATE_LIMIT_TIMEOUT = 5;
|
||||
|
||||
constexpr const char* API_BASE_URL = "https://api.mapbox.com";
|
||||
|
||||
} // namespace util
|
||||
|
||||
namespace debug {
|
||||
|
||||
@@ -56,7 +56,7 @@ class HTTPRequest implements Callback {
|
||||
|
||||
HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
|
||||
final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
|
||||
if (host.equals("mapbox.com") || host.endsWith(".mapbox.com")) {
|
||||
if (host.equals("mapbox.com") || host.endsWith(".mapbox.com") || host.equals("mapbox.cn") || host.endsWith(".mapbox.cn")) {
|
||||
if (httpUrl.querySize() == 0) {
|
||||
resourceUrl = resourceUrl + "?";
|
||||
} else {
|
||||
|
||||
@@ -260,6 +260,12 @@ public class MapView extends FrameLayout {
|
||||
mMyLocationView.setTilt(position.tilt);
|
||||
}
|
||||
|
||||
// api base url
|
||||
String apiBaseUrl = options.getApiBaseUrl();
|
||||
if (!TextUtils.isEmpty(apiBaseUrl)) {
|
||||
setApiBaseUrl(apiBaseUrl);
|
||||
}
|
||||
|
||||
// access token
|
||||
String accessToken = options.getAccessToken();
|
||||
if (!TextUtils.isEmpty(accessToken)) {
|
||||
@@ -877,6 +883,15 @@ public class MapView extends FrameLayout {
|
||||
return mStyleUrl;
|
||||
}
|
||||
|
||||
//
|
||||
// API Base URL
|
||||
//
|
||||
|
||||
@UiThread
|
||||
void setApiBaseUrl(@NonNull String baseUrl) {
|
||||
mNativeMapView.setApiBaseUrl(baseUrl);
|
||||
}
|
||||
|
||||
//
|
||||
// Access token
|
||||
//
|
||||
|
||||
@@ -7,15 +7,12 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.VectorDrawable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
@@ -79,6 +76,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
private int myLocationAccuracyTintColor;
|
||||
private int myLocationAccuracyAlpha;
|
||||
|
||||
private String apiBaseUrl;
|
||||
private String style;
|
||||
@Deprecated
|
||||
private String accessToken;
|
||||
@@ -123,12 +121,12 @@ public class MapboxMapOptions implements Parcelable {
|
||||
}
|
||||
|
||||
Bitmap foregroundBearingBitmap = in.readParcelable(getClass().getClassLoader());
|
||||
if(foregroundBearingBitmap!=null) {
|
||||
if (foregroundBearingBitmap != null) {
|
||||
myLocationForegroundBearingDrawable = new BitmapDrawable(foregroundBearingBitmap);
|
||||
}
|
||||
|
||||
Bitmap backgroundBitmap = in.readParcelable(getClass().getClassLoader());
|
||||
if(backgroundBitmap!=null){
|
||||
if (backgroundBitmap != null) {
|
||||
myLocationBackgroundDrawable = new BitmapDrawable(backgroundBitmap);
|
||||
}
|
||||
|
||||
@@ -140,6 +138,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
|
||||
style = in.readString();
|
||||
accessToken = in.readString();
|
||||
apiBaseUrl = in.readString();
|
||||
}
|
||||
|
||||
public static Bitmap getBitmapFromDrawable(Drawable drawable) {
|
||||
@@ -172,6 +171,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
|
||||
mapboxMapOptions.accessToken(typedArray.getString(R.styleable.MapView_access_token));
|
||||
mapboxMapOptions.styleUrl(typedArray.getString(R.styleable.MapView_style_url));
|
||||
mapboxMapOptions.apiBaseUrl(typedArray.getString(R.styleable.MapView_api_base_url));
|
||||
|
||||
mapboxMapOptions.zoomGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_enabled, true));
|
||||
mapboxMapOptions.scrollGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_scroll_enabled, true));
|
||||
@@ -237,6 +237,17 @@ public class MapboxMapOptions implements Parcelable {
|
||||
return mapboxMapOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the URL used for API endpoint.
|
||||
*
|
||||
* @param apiBaseUrl The base of our API endpoint
|
||||
* @return This
|
||||
*/
|
||||
public MapboxMapOptions apiBaseUrl(String apiBaseUrl) {
|
||||
this.apiBaseUrl = apiBaseUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a the initial camera position for the map view.
|
||||
*
|
||||
@@ -583,6 +594,15 @@ public class MapboxMapOptions implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current configured API endpoint base URL.
|
||||
*
|
||||
* @return Base URL to be used API endpoint.
|
||||
*/
|
||||
public String getApiBaseUrl() {
|
||||
return apiBaseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current configured initial camera position for a map view.
|
||||
*
|
||||
@@ -914,6 +934,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
|
||||
dest.writeString(style);
|
||||
dest.writeString(accessToken);
|
||||
dest.writeString(apiBaseUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -957,6 +978,8 @@ public class MapboxMapOptions implements Parcelable {
|
||||
if (!Arrays.equals(myLocationBackgroundPadding, options.myLocationBackgroundPadding))
|
||||
return false;
|
||||
if (style != null ? !style.equals(options.style) : options.style != null) return false;
|
||||
if (apiBaseUrl != null ? !apiBaseUrl.equals(options.apiBaseUrl) : options.apiBaseUrl != null)
|
||||
return false;
|
||||
return accessToken != null ? accessToken.equals(options.accessToken) : options.accessToken == null;
|
||||
|
||||
}
|
||||
@@ -993,6 +1016,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
result = 31 * result + myLocationAccuracyAlpha;
|
||||
result = 31 * result + (style != null ? style.hashCode() : 0);
|
||||
result = 31 * result + (accessToken != null ? accessToken.hashCode() : 0);
|
||||
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -526,6 +526,10 @@ final class NativeMapView {
|
||||
nativeScheduleTakeSnapshot(mNativeMapViewPtr);
|
||||
}
|
||||
|
||||
public void setApiBaseUrl(String baseUrl) {
|
||||
nativeSetAPIBaseURL(mNativeMapViewPtr, baseUrl);
|
||||
}
|
||||
|
||||
//
|
||||
// Callbacks
|
||||
//
|
||||
@@ -721,4 +725,6 @@ final class NativeMapView {
|
||||
private native Feature[] nativeQueryRenderedFeaturesForPoint(long nativeMapViewPtr, float x, float y, String[] layerIds);
|
||||
|
||||
private native Feature[] nativeQueryRenderedFeaturesForBox(long mNativeMapViewPtr, float left, float top, float right, float bottom, String[] layerIds);
|
||||
|
||||
private native void nativeSetAPIBaseURL(long nativeMapViewPtr, String baseUrl);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<!--Configuration-->
|
||||
<attr name="access_token" format="string" />
|
||||
<attr name="style_url" format="string" />
|
||||
<attr name="api_base_url" format="string" />
|
||||
|
||||
<!--Camera-->
|
||||
<attr name="center_longitude" format="float" />
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
|
||||
@@ -424,6 +424,13 @@ jni::jobject* nativeGetClasses(JNIEnv *env, jni::jobject* obj, jlong nativeMapVi
|
||||
return std_vector_string_to_jobject(env, nativeMapView->getMap().getClasses());
|
||||
}
|
||||
|
||||
void nativeSetAPIBaseURL(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* url) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetAPIBaseURL");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
nativeMapView->getFileSource().setAPIBaseURL(std_string_from_jstring(env, url));
|
||||
}
|
||||
|
||||
void nativeSetStyleUrl(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* url) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetStyleURL");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
@@ -1836,7 +1843,8 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
MAKE_NATIVE_METHOD(nativeSetContentPadding, "(JDDDD)V"),
|
||||
MAKE_NATIVE_METHOD(nativeScheduleTakeSnapshot, "(J)V"),
|
||||
MAKE_NATIVE_METHOD(nativeQueryRenderedFeaturesForPoint, "(JFF[Ljava/lang/String;)[Lcom/mapbox/services/commons/geojson/Feature;"),
|
||||
MAKE_NATIVE_METHOD(nativeQueryRenderedFeaturesForBox, "(JFFFF[Ljava/lang/String;)[Lcom/mapbox/services/commons/geojson/Feature;")
|
||||
MAKE_NATIVE_METHOD(nativeQueryRenderedFeaturesForBox, "(JFFFF[Ljava/lang/String;)[Lcom/mapbox/services/commons/geojson/Feature;"),
|
||||
MAKE_NATIVE_METHOD(nativeSetAPIBaseURL, "(JLjava/lang/String;)V")
|
||||
);
|
||||
|
||||
// Offline begin
|
||||
|
||||
@@ -28,6 +28,14 @@ public:
|
||||
Impl(const std::string& cachePath, uint64_t maximumCacheSize)
|
||||
: offlineDatabase(cachePath, maximumCacheSize) {
|
||||
}
|
||||
|
||||
void setAPIBaseURL(const std::string& url) {
|
||||
onlineFileSource.setAPIBaseURL(url);
|
||||
}
|
||||
|
||||
std::string getAPIBaseURL() const{
|
||||
return onlineFileSource.getAPIBaseURL();
|
||||
}
|
||||
|
||||
void setAccessToken(const std::string& accessToken) {
|
||||
onlineFileSource.setAccessToken(accessToken);
|
||||
@@ -151,6 +159,14 @@ DefaultFileSource::DefaultFileSource(const std::string& cachePath,
|
||||
|
||||
DefaultFileSource::~DefaultFileSource() = default;
|
||||
|
||||
void DefaultFileSource::setAPIBaseURL(const std::string& baseURL) {
|
||||
thread->invokeSync(&Impl::setAPIBaseURL, baseURL);
|
||||
}
|
||||
|
||||
std::string DefaultFileSource::getAPIBaseURL() const {
|
||||
return thread->invokeSync(&Impl::getAPIBaseURL);
|
||||
}
|
||||
|
||||
void DefaultFileSource::setAccessToken(const std::string& accessToken) {
|
||||
thread->invokeSync(&Impl::setAccessToken, accessToken);
|
||||
}
|
||||
|
||||
@@ -160,24 +160,24 @@ std::unique_ptr<AsyncRequest> OnlineFileSource::request(const Resource& resource
|
||||
break;
|
||||
|
||||
case Resource::Kind::Style:
|
||||
res.url = mbgl::util::mapbox::normalizeStyleURL(resource.url, accessToken);
|
||||
res.url = mbgl::util::mapbox::normalizeStyleURL(apiBaseURL, resource.url, accessToken);
|
||||
break;
|
||||
|
||||
case Resource::Kind::Source:
|
||||
res.url = util::mapbox::normalizeSourceURL(resource.url, accessToken);
|
||||
res.url = util::mapbox::normalizeSourceURL(apiBaseURL, resource.url, accessToken);
|
||||
break;
|
||||
|
||||
case Resource::Kind::Glyphs:
|
||||
res.url = util::mapbox::normalizeGlyphsURL(resource.url, accessToken);
|
||||
res.url = util::mapbox::normalizeGlyphsURL(apiBaseURL, resource.url, accessToken);
|
||||
break;
|
||||
|
||||
case Resource::Kind::SpriteImage:
|
||||
case Resource::Kind::SpriteJSON:
|
||||
res.url = util::mapbox::normalizeSpriteURL(resource.url, accessToken);
|
||||
res.url = util::mapbox::normalizeSpriteURL(apiBaseURL, resource.url, accessToken);
|
||||
break;
|
||||
|
||||
case Resource::Kind::Tile:
|
||||
res.url = util::mapbox::normalizeTileURL(resource.url, accessToken);
|
||||
res.url = util::mapbox::normalizeTileURL(apiBaseURL, resource.url, accessToken);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,7 @@ namespace util {
|
||||
namespace mapbox {
|
||||
|
||||
const std::string protocol = "mapbox://";
|
||||
const std::string baseURL = "https://api.mapbox.com/";
|
||||
|
||||
|
||||
bool isMapboxURL(const std::string& url) {
|
||||
return std::equal(protocol.begin(), protocol.end(), url.begin());
|
||||
}
|
||||
@@ -35,7 +34,7 @@ std::vector<std::string> getMapboxURLPathname(const std::string& url) {
|
||||
return pathname;
|
||||
}
|
||||
|
||||
std::string normalizeSourceURL(const std::string& url, const std::string& accessToken) {
|
||||
std::string normalizeSourceURL(const std::string& baseURL, const std::string& url, const std::string& accessToken) {
|
||||
if (!isMapboxURL(url)) {
|
||||
return url;
|
||||
}
|
||||
@@ -43,11 +42,10 @@ std::string normalizeSourceURL(const std::string& url, const std::string& access
|
||||
if (accessToken.empty()) {
|
||||
throw std::runtime_error("You must provide a Mapbox API access token for Mapbox tile sources");
|
||||
}
|
||||
|
||||
return baseURL + "v4/" + url.substr(protocol.length()) + ".json?access_token=" + accessToken + "&secure";
|
||||
return baseURL + "/v4/" + url.substr(protocol.length()) + ".json?access_token=" + accessToken + "&secure";
|
||||
}
|
||||
|
||||
std::string normalizeStyleURL(const std::string& url, const std::string& accessToken) {
|
||||
std::string normalizeStyleURL(const std::string& baseURL, const std::string& url, const std::string& accessToken) {
|
||||
if (!isMapboxURL(url)) {
|
||||
return url;
|
||||
}
|
||||
@@ -61,10 +59,10 @@ std::string normalizeStyleURL(const std::string& url, const std::string& accessT
|
||||
const auto& user = pathname[1];
|
||||
const auto& id = pathname[2];
|
||||
const bool isDraft = pathname.size() > 3;
|
||||
return baseURL + "styles/v1/" + user + "/" + id + (isDraft ? "/draft" : "") + "?access_token=" + accessToken;
|
||||
return baseURL + "/styles/v1/" + user + "/" + id + (isDraft ? "/draft" : "") + "?access_token=" + accessToken;
|
||||
}
|
||||
|
||||
std::string normalizeSpriteURL(const std::string& url, const std::string& accessToken) {
|
||||
std::string normalizeSpriteURL(const std::string& baseURL, const std::string& url, const std::string& accessToken) {
|
||||
if (!isMapboxURL(url)) {
|
||||
return url;
|
||||
}
|
||||
@@ -88,17 +86,17 @@ std::string normalizeSpriteURL(const std::string& url, const std::string& access
|
||||
|
||||
if (isDraft) {
|
||||
const auto& id = pathname[2];
|
||||
return baseURL + "styles/v1/" + user + "/" + id + "/draft/sprite" + extension +
|
||||
return baseURL + "/styles/v1/" + user + "/" + id + "/draft/sprite" + extension +
|
||||
"?access_token=" + accessToken;
|
||||
|
||||
} else {
|
||||
const auto& id = pathname[2].substr(0, index);
|
||||
return baseURL + "styles/v1/" + user + "/" + id + "/sprite" + extension + "?access_token=" +
|
||||
return baseURL + "/styles/v1/" + user + "/" + id + "/sprite" + extension + "?access_token=" +
|
||||
accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
std::string normalizeGlyphsURL(const std::string& url, const std::string& accessToken) {
|
||||
std::string normalizeGlyphsURL(const std::string& baseURL, const std::string& url, const std::string& accessToken) {
|
||||
if (!isMapboxURL(url)) {
|
||||
return url;
|
||||
}
|
||||
@@ -113,15 +111,15 @@ std::string normalizeGlyphsURL(const std::string& url, const std::string& access
|
||||
const auto& fontstack = pathname[2];
|
||||
const auto& range = pathname[3];
|
||||
|
||||
return baseURL + "fonts/v1/" + user + "/" + fontstack + "/" + range + "?access_token=" + accessToken;
|
||||
return baseURL + "/fonts/v1/" + user + "/" + fontstack + "/" + range + "?access_token=" + accessToken;
|
||||
}
|
||||
|
||||
std::string normalizeTileURL(const std::string& url, const std::string& accessToken) {
|
||||
std::string normalizeTileURL(const std::string& baseURL, const std::string& url, const std::string& accessToken) {
|
||||
if (!isMapboxURL(url)) {
|
||||
return url;
|
||||
}
|
||||
|
||||
return baseURL + "v4/" + url.substr(sizeof("mapbox://tiles/") - 1) + "?access_token=" + accessToken;
|
||||
return baseURL + "/v4/" + url.substr(sizeof("mapbox://tiles/") - 1) + "?access_token=" + accessToken;
|
||||
}
|
||||
|
||||
std::string canonicalizeTileURL(const std::string& url, SourceType type, uint16_t tileSize) {
|
||||
|
||||
@@ -9,11 +9,11 @@ namespace mapbox {
|
||||
|
||||
bool isMapboxURL(const std::string& url);
|
||||
|
||||
std::string normalizeSourceURL(const std::string& url, const std::string& accessToken);
|
||||
std::string normalizeStyleURL(const std::string& url, const std::string& accessToken);
|
||||
std::string normalizeSpriteURL(const std::string& url, const std::string& accessToken);
|
||||
std::string normalizeGlyphsURL(const std::string& url, const std::string& accessToken);
|
||||
std::string normalizeTileURL(const std::string& url, const std::string& accessToken);
|
||||
std::string normalizeSourceURL(const std::string& baseURL, const std::string& url, const std::string& accessToken);
|
||||
std::string normalizeStyleURL(const std::string& baseURL, const std::string& url, const std::string& accessToken);
|
||||
std::string normalizeSpriteURL(const std::string& baseURL, const std::string& url, const std::string& accessToken);
|
||||
std::string normalizeGlyphsURL(const std::string& baseURL, const std::string& url, const std::string& accessToken);
|
||||
std::string normalizeTileURL(const std::string& baseURL, const std::string& url, const std::string& accessToken);
|
||||
|
||||
// Return a "mapbox://tiles/..." URL (suitable for normalizeTileURL) for the given Mapbox tile URL.
|
||||
std::string canonicalizeTileURL(const std::string& url, SourceType, uint16_t tileSize);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/timer.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -403,3 +404,13 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(RateLimitDefault)) {
|
||||
|
||||
loop.run();
|
||||
}
|
||||
|
||||
TEST(OnlineFileSource, ChangeAPIBaseURL){
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs;
|
||||
|
||||
EXPECT_EQ(mbgl::util::API_BASE_URL, fs.getAPIBaseURL());
|
||||
const std::string customURL = "test.domain";
|
||||
fs.setAPIBaseURL(customURL);
|
||||
EXPECT_EQ(customURL, fs.getAPIBaseURL());
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/util/mapbox.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <regex>
|
||||
#include <iostream>
|
||||
|
||||
@@ -10,85 +11,100 @@ using namespace mbgl;
|
||||
TEST(Mapbox, SourceURL) {
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/v4/user.map.json?access_token=key&secure",
|
||||
mbgl::util::mapbox::normalizeSourceURL("mapbox://user.map", "key"));
|
||||
mbgl::util::mapbox::normalizeSourceURL(util::API_BASE_URL, "mapbox://user.map", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.example.com/v4/user.map.json?access_token=key&secure",
|
||||
mbgl::util::mapbox::normalizeSourceURL("https://api.example.com", "mapbox://user.map", "key"));
|
||||
EXPECT_EQ(
|
||||
"http://path",
|
||||
mbgl::util::mapbox::normalizeSourceURL("http://path", "key"));
|
||||
mbgl::util::mapbox::normalizeSourceURL(util::API_BASE_URL, "http://path", "key"));
|
||||
EXPECT_THROW(
|
||||
mbgl::util::mapbox::normalizeSourceURL("mapbox://user.map", ""),
|
||||
mbgl::util::mapbox::normalizeSourceURL(util::API_BASE_URL, "mapbox://user.map", ""),
|
||||
std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(Mapbox, GlyphsURL) {
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/fonts/v1/boxmap/Comic%20Sans/0-255.pbf?access_token=key",
|
||||
mbgl::util::mapbox::normalizeGlyphsURL("mapbox://fonts/boxmap/Comic%20Sans/0-255.pbf", "key"));
|
||||
mbgl::util::mapbox::normalizeGlyphsURL(util::API_BASE_URL, "mapbox://fonts/boxmap/Comic%20Sans/0-255.pbf", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.example.com/fonts/v1/boxmap/Comic%20Sans/0-255.pbf?access_token=key",
|
||||
mbgl::util::mapbox::normalizeGlyphsURL("https://api.example.com", "mapbox://fonts/boxmap/Comic%20Sans/0-255.pbf", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/fonts/v1/boxmap/{fontstack}/{range}.pbf?access_token=key",
|
||||
mbgl::util::mapbox::normalizeGlyphsURL("mapbox://fonts/boxmap/{fontstack}/{range}.pbf", "key"));
|
||||
mbgl::util::mapbox::normalizeGlyphsURL(util::API_BASE_URL, "mapbox://fonts/boxmap/{fontstack}/{range}.pbf", "key"));
|
||||
EXPECT_EQ(
|
||||
"http://path",
|
||||
mbgl::util::mapbox::normalizeGlyphsURL("http://path", "key"));
|
||||
mbgl::util::mapbox::normalizeGlyphsURL(util::API_BASE_URL, "http://path", "key"));
|
||||
EXPECT_EQ(
|
||||
"mapbox://path",
|
||||
mbgl::util::mapbox::normalizeGlyphsURL("mapbox://path", "key"));
|
||||
mbgl::util::mapbox::normalizeGlyphsURL(util::API_BASE_URL, "mapbox://path", "key"));
|
||||
}
|
||||
|
||||
TEST(Mapbox, StyleURL) {
|
||||
EXPECT_EQ(
|
||||
"mapbox://foo",
|
||||
mbgl::util::mapbox::normalizeStyleURL("mapbox://foo", "key"));
|
||||
mbgl::util::mapbox::normalizeStyleURL(util::API_BASE_URL, "mapbox://foo", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/styles/v1/user/style?access_token=key",
|
||||
mbgl::util::mapbox::normalizeStyleURL("mapbox://styles/user/style", "key"));
|
||||
mbgl::util::mapbox::normalizeStyleURL(util::API_BASE_URL, "mapbox://styles/user/style", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.example.com/styles/v1/user/style?access_token=key",
|
||||
mbgl::util::mapbox::normalizeStyleURL("https://api.example.com", "mapbox://styles/user/style", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/styles/v1/user/style/draft?access_token=key",
|
||||
mbgl::util::mapbox::normalizeStyleURL("mapbox://styles/user/style/draft", "key"));
|
||||
mbgl::util::mapbox::normalizeStyleURL(util::API_BASE_URL, "mapbox://styles/user/style/draft", "key"));
|
||||
EXPECT_EQ(
|
||||
"http://path",
|
||||
mbgl::util::mapbox::normalizeStyleURL("http://path", "key"));
|
||||
mbgl::util::mapbox::normalizeStyleURL(util::API_BASE_URL, "http://path", "key"));
|
||||
}
|
||||
|
||||
TEST(Mapbox, SpriteURL) {
|
||||
EXPECT_EQ(
|
||||
"map/box/sprites@2x.json",
|
||||
mbgl::util::mapbox::normalizeSpriteURL("map/box/sprites@2x.json", "key"));
|
||||
mbgl::util::mapbox::normalizeSpriteURL(util::API_BASE_URL, "map/box/sprites@2x.json", "key"));
|
||||
EXPECT_EQ(
|
||||
"mapbox://foo",
|
||||
mbgl::util::mapbox::normalizeSpriteURL("mapbox://foo", "key"));
|
||||
mbgl::util::mapbox::normalizeSpriteURL(util::API_BASE_URL, "mapbox://foo", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/styles/v1/mapbox/streets-v8/sprite.json?access_token=key",
|
||||
mbgl::util::mapbox::normalizeSpriteURL("mapbox://sprites/mapbox/streets-v8.json", "key"));
|
||||
mbgl::util::mapbox::normalizeSpriteURL(util::API_BASE_URL, "mapbox://sprites/mapbox/streets-v8.json", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.example.com/styles/v1/mapbox/streets-v8/sprite.json?access_token=key",
|
||||
mbgl::util::mapbox::normalizeSpriteURL("https://api.example.com", "mapbox://sprites/mapbox/streets-v8.json", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/styles/v1/mapbox/streets-v8/sprite@2x.png?access_token=key",
|
||||
mbgl::util::mapbox::normalizeSpriteURL("mapbox://sprites/mapbox/streets-v8@2x.png", "key"));
|
||||
mbgl::util::mapbox::normalizeSpriteURL(util::API_BASE_URL, "mapbox://sprites/mapbox/streets-v8@2x.png", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/styles/v1/mapbox/streets-v8/draft/sprite@2x.png?access_token=key",
|
||||
mbgl::util::mapbox::normalizeSpriteURL("mapbox://sprites/mapbox/streets-v8/draft@2x.png", "key"));
|
||||
mbgl::util::mapbox::normalizeSpriteURL(util::API_BASE_URL, "mapbox://sprites/mapbox/streets-v8/draft@2x.png", "key"));
|
||||
EXPECT_EQ(
|
||||
"mapbox://sprites/mapbox/streets-v9?fresh=true.png",
|
||||
mbgl::util::mapbox::normalizeSpriteURL(
|
||||
mbgl::util::mapbox::normalizeSpriteURL(util::API_BASE_URL,
|
||||
"mapbox://sprites/mapbox/streets-v9?fresh=true.png",
|
||||
"key"));
|
||||
EXPECT_EQ("mapbox://////", mbgl::util::mapbox::normalizeSpriteURL("mapbox://////", "key"));
|
||||
EXPECT_EQ("mapbox://////", mbgl::util::mapbox::normalizeSpriteURL(util::API_BASE_URL, "mapbox://////", "key"));
|
||||
}
|
||||
|
||||
TEST(Mapbox, TileURL) {
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/v4/a.b/0/0/0.pbf?access_token=key",
|
||||
mbgl::util::mapbox::normalizeTileURL("mapbox://tiles/a.b/0/0/0.pbf", "key"));
|
||||
mbgl::util::mapbox::normalizeTileURL(util::API_BASE_URL, "mapbox://tiles/a.b/0/0/0.pbf", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/v4/a.b/0/0/0.png?access_token=key",
|
||||
mbgl::util::mapbox::normalizeTileURL("mapbox://tiles/a.b/0/0/0.png", "key"));
|
||||
mbgl::util::mapbox::normalizeTileURL(util::API_BASE_URL, "mapbox://tiles/a.b/0/0/0.png", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.example.com/v4/a.b/0/0/0.png?access_token=key",
|
||||
mbgl::util::mapbox::normalizeTileURL("https://api.example.com", "mapbox://tiles/a.b/0/0/0.png", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/v4/a.b/0/0/0@2x.webp?access_token=key",
|
||||
mbgl::util::mapbox::normalizeTileURL("mapbox://tiles/a.b/0/0/0@2x.webp", "key"));
|
||||
mbgl::util::mapbox::normalizeTileURL(util::API_BASE_URL, "mapbox://tiles/a.b/0/0/0@2x.webp", "key"));
|
||||
EXPECT_EQ(
|
||||
"https://api.mapbox.com/v4/a.b,c.d/0/0/0.pbf?access_token=key",
|
||||
mbgl::util::mapbox::normalizeTileURL("mapbox://tiles/a.b,c.d/0/0/0.pbf", "key"));
|
||||
mbgl::util::mapbox::normalizeTileURL(util::API_BASE_URL, "mapbox://tiles/a.b,c.d/0/0/0.pbf", "key"));
|
||||
EXPECT_EQ(
|
||||
"http://path",
|
||||
mbgl::util::mapbox::normalizeSpriteURL("http://path", "key"));
|
||||
mbgl::util::mapbox::normalizeSpriteURL(util::API_BASE_URL, "http://path", "key"));
|
||||
}
|
||||
|
||||
TEST(Mapbox, CanonicalURL) {
|
||||
|
||||
Reference in New Issue
Block a user