summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2016-09-15 22:01:09 -0700
committerGitHub <noreply@github.com>2016-09-15 22:01:09 -0700
commit9ef65440b6bfd2c8da17d2613f8c967682cc0ef9 (patch)
tree52b5508cae9fe76548b9efee15268d2da1543080 /platform
parent217c43d1255f36c7ef2b588a90b6c19ca176dce2 (diff)
downloadqtlocation-mapboxgl-9ef65440b6bfd2c8da17d2613f8c967682cc0ef9.tar.gz
[core] [android] - public api configurable base endpoint (#6309)
add runloop to test
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java15
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java34
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java6
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/DynamicMarkerChangeActivity.java1
-rwxr-xr-xplatform/android/src/jni.cpp10
-rw-r--r--platform/default/default_file_source.cpp16
-rw-r--r--platform/default/online_file_source.cpp10
9 files changed, 83 insertions, 12 deletions
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 7655d2fbb0..a573f7d870 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 @@ 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 {
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 1708a21dba..9b7c691c3d 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 @@ 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)) {
@@ -878,6 +884,15 @@ public class MapView extends FrameLayout {
}
//
+ // 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 14c3a4da79..6203d013ae 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.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));
@@ -238,6 +238,17 @@ public class MapboxMapOptions implements Parcelable {
}
/**
+ * 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.
*
* @param cameraPosition Inital camera position
@@ -584,6 +595,15 @@ public class MapboxMapOptions implements Parcelable {
}
/**
+ * 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.
*
* @return CameraPosition to be initially used.
@@ -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;
}
}
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 28e82770eb..1a5731b51f 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 @@ 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);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
index 66ddd251a5..1d40879d27 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 @@
<!--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" />
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 431908017f..7842542ef1 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.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;
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index 5f136595a8..6752c1bbdb 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<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
diff --git a/platform/default/default_file_source.cpp b/platform/default/default_file_source.cpp
index 9465728509..83674cea03 100644
--- a/platform/default/default_file_source.cpp
+++ b/platform/default/default_file_source.cpp
@@ -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);
}
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp
index 44245b9c13..049cbf5f8d 100644
--- a/platform/default/online_file_source.cpp
+++ b/platform/default/online_file_source.cpp
@@ -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;
}