diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp index 235e738254e..ab9c2bc6a06 100644 --- a/include/mbgl/storage/default_file_source.hpp +++ b/include/mbgl/storage/default_file_source.hpp @@ -29,6 +29,9 @@ class DefaultFileSource : public FileSource { bool supportsOptionalRequests() const override { return true; } + + void setAPIBaseURL(const std::string&); + std::string getAPIBaseURL() const; void setAccessToken(const std::string&); std::string getAccessToken() const; diff --git a/include/mbgl/storage/online_file_source.hpp b/include/mbgl/storage/online_file_source.hpp index 081beeeabc9..9c7feceb47e 100644 --- a/include/mbgl/storage/online_file_source.hpp +++ b/include/mbgl/storage/online_file_source.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace mbgl { @@ -9,6 +10,9 @@ class OnlineFileSource : public FileSource { 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 @@ class OnlineFileSource : public FileSource { class Impl; const std::unique_ptr impl; std::string accessToken; + std::string apiBaseURL = mbgl::util::API_BASE_URL; }; } // namespace mbgl diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp index 75a1ace5c55..e6e9f6e67dc 100644 --- a/include/mbgl/util/constants.hpp +++ b/include/mbgl/util/constants.hpp @@ -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 { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java index 7655d2fbb09..a573f7d8707 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java @@ -56,7 +56,7 @@ private HTTPRequest(long nativePtr, String resourceUrl, String userAgent, String 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 { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 1708a21dbab..9b7c691c3d0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -260,6 +260,12 @@ private void setInitialState(MapboxMapOptions options) { 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 String getStyleUrl() { return mStyleUrl; } + // + // API Base URL + // + + @UiThread + void setApiBaseUrl(@NonNull String baseUrl) { + mNativeMapView.setApiBaseUrl(baseUrl); + } + // // Access token // diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index 14c3a4da799..6203d013ae2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -7,15 +7,12 @@ 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 @@ private MapboxMapOptions(Parcel in) { } 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 @@ private MapboxMapOptions(Parcel in) { style = in.readString(); accessToken = in.readString(); + apiBaseUrl = in.readString(); } public static Bitmap getBitmapFromDrawable(Drawable drawable) { @@ -172,6 +171,7 @@ public static MapboxMapOptions createFromAttributes(@NonNull Context context, @N 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 static MapboxMapOptions createFromAttributes(@NonNull Context context, @N 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 MapboxMapOptions myLocationAccuracyAlpha(@IntRange(from = 0, to = 255) in 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 void writeToParcel(Parcel dest, int flags) { dest.writeString(style); dest.writeString(accessToken); + dest.writeString(apiBaseUrl); } @Override @@ -957,6 +978,8 @@ public boolean equals(Object o) { 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 int hashCode() { 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; } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 28e82770eb3..1a5731b51fa 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -526,6 +526,10 @@ public void scheduleTakeSnapshot() { nativeScheduleTakeSnapshot(mNativeMapViewPtr); } + public void setApiBaseUrl(String baseUrl) { + nativeSetAPIBaseURL(mNativeMapViewPtr, baseUrl); + } + // // Callbacks // @@ -721,4 +725,6 @@ private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, Lat 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); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index 66ddd251a52..1d40879d272 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -5,6 +5,7 @@ + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/DynamicMarkerChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/DynamicMarkerChangeActivity.java index 431908017fb..7842542ef1d 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/DynamicMarkerChangeActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/DynamicMarkerChangeActivity.java @@ -14,6 +14,7 @@ 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; diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 5f136595a88..6752c1bbdbe 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -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(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 diff --git a/platform/default/default_file_source.cpp b/platform/default/default_file_source.cpp index 9465728509b..83674cea037 100644 --- a/platform/default/default_file_source.cpp +++ b/platform/default/default_file_source.cpp @@ -28,6 +28,14 @@ class DefaultFileSource::Impl { 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); } diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp index 44245b9c13b..049cbf5f8de 100644 --- a/platform/default/online_file_source.cpp +++ b/platform/default/online_file_source.cpp @@ -160,24 +160,24 @@ std::unique_ptr 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; } diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp index b60c04a3eda..70f2ba92307 100644 --- a/src/mbgl/util/mapbox.cpp +++ b/src/mbgl/util/mapbox.cpp @@ -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 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) { diff --git a/src/mbgl/util/mapbox.hpp b/src/mbgl/util/mapbox.hpp index 951cbc5a4ba..72f4e0a5676 100644 --- a/src/mbgl/util/mapbox.hpp +++ b/src/mbgl/util/mapbox.hpp @@ -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); diff --git a/test/storage/online_file_source.cpp b/test/storage/online_file_source.cpp index f67d96f257b..b832f9c339e 100644 --- a/test/storage/online_file_source.cpp +++ b/test/storage/online_file_source.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -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()); +} \ No newline at end of file diff --git a/test/util/mapbox.cpp b/test/util/mapbox.cpp index 9341b695f3f..f3fb42c59dd 100644 --- a/test/util/mapbox.cpp +++ b/test/util/mapbox.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -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) {