diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-05-11 15:01:33 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-05-11 18:59:11 +0300 |
commit | 489f76d3a218ac07188947e4e219801745d15318 (patch) | |
tree | 7bd07b0a6f291585e24098e6e479cf25681fd381 /platform | |
parent | 625c2ea52777f53c1f23ca71e2aa5094dc4630c5 (diff) | |
download | qtlocation-mapboxgl-489f76d3a218ac07188947e4e219801745d15318.tar.gz |
[android] url getter on sources
Diffstat (limited to 'platform')
10 files changed, 92 insertions, 2 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java index ec80186761..10ecb945ad 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java @@ -228,6 +228,14 @@ public class GeoJsonSource extends Source { } /** + * @return The url or null + */ + @Nullable + public String getUrl() { + return nativeGetUrl(); + } + + /** * Queries the source for features. * * @param filter an optional filter statement to filter the returned Features @@ -243,6 +251,8 @@ public class GeoJsonSource extends Source { protected native void nativeSetUrl(String url); + protected native String nativeGetUrl(); + private native void nativeSetGeoJsonString(String geoJson); private native void nativeSetFeatureCollection(FeatureCollection geoJson); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java index 98b74afcff..38ed208618 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java @@ -1,5 +1,7 @@ package com.mapbox.mapboxsdk.style.sources; +import android.support.annotation.Nullable; + import java.net.URL; /** @@ -72,8 +74,19 @@ public class RasterSource extends Source { initialize(id, tileSet.toValueObject(), tileSize); } + /** + * @return The url or null + */ + @Nullable + public String getUrl() { + return nativeGetUrl(); + } + protected native void initialize(String layerId, Object payload, int tileSize); @Override protected native void finalize() throws Throwable; + + protected native String nativeGetUrl(); + } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java index 7230492d0e..9b59cf8967 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java @@ -76,11 +76,21 @@ public class VectorSource extends Source { return features != null ? Arrays.asList(features) : new ArrayList<Feature>(); } + /** + * @return The url or null + */ + @Nullable + public String getUrl() { + return nativeGetUrl(); + } + protected native void initialize(String layerId, Object payload); @Override protected native void finalize() throws Throwable; + protected native String nativeGetUrl(); + private native Feature[] querySourceFeatures(String[] sourceLayerId, Object[] filter); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java index 354f5def6f..a1c46903bf 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java @@ -15,6 +15,8 @@ import com.mapbox.mapboxsdk.style.layers.Layer; import com.mapbox.mapboxsdk.style.layers.Property; import com.mapbox.mapboxsdk.style.layers.PropertyFactory; import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; +import com.mapbox.mapboxsdk.style.sources.RasterSource; import com.mapbox.mapboxsdk.style.sources.Source; import com.mapbox.mapboxsdk.style.sources.VectorSource; import com.mapbox.mapboxsdk.testapp.R; @@ -28,6 +30,8 @@ import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; +import java.net.MalformedURLException; +import java.net.URL; import java.util.List; import timber.log.Timber; @@ -190,6 +194,35 @@ public class RuntimeStyleTests extends BaseActivityTest { onView(withId(R.id.mapView)).perform(new AddRemoveSourceAction()); } + @Test + public void testVectorSourceUrlGetter() { + validateTestSetup(); + + VectorSource source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"); + mapboxMap.addSource(source); + assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUrl()); + } + + @Test + public void testRasterSourceUrlGetter() { + validateTestSetup(); + + RasterSource source = new RasterSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"); + mapboxMap.addSource(source); + assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUrl()); + } + + @Test + public void testGeoJsonSourceUrlGetter() throws MalformedURLException { + validateTestSetup(); + + GeoJsonSource source = new GeoJsonSource("my-source"); + mapboxMap.addSource(source); + assertNull(source.getUrl()); + source.setUrl(new URL("http://mapbox.com/my-file.json")); + assertEquals("http://mapbox.com/my-file.json", source.getUrl()); + } + /** * https://github.com/mapbox/mapbox-gl-native/issues/7973 */ diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp index 9b56446e31..780cc4b6f6 100644 --- a/platform/android/src/style/sources/geojson_source.cpp +++ b/platform/android/src/style/sources/geojson_source.cpp @@ -97,6 +97,11 @@ namespace android { source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setURL(jni::Make<std::string>(env, url)); } + jni::String GeoJSONSource::getURL(jni::JNIEnv& env) { + optional<std::string> url = source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::getURL(); + return url ? jni::Make<jni::String>(env, *url) : jni::String(); + } + jni::Array<jni::Object<geojson::Feature>> GeoJSONSource::querySourceFeatures(jni::JNIEnv& env, jni::Array<jni::Object<>> jfilter) { using namespace mbgl::android::conversion; @@ -133,6 +138,7 @@ namespace android { METHOD(&GeoJSONSource::setFeature, "nativeSetFeature"), METHOD(&GeoJSONSource::setGeometry, "nativeSetGeometry"), METHOD(&GeoJSONSource::setURL, "nativeSetUrl"), + METHOD(&GeoJSONSource::getURL, "nativeGetUrl"), METHOD(&GeoJSONSource::querySourceFeatures, "querySourceFeatures") ); } diff --git a/platform/android/src/style/sources/geojson_source.hpp b/platform/android/src/style/sources/geojson_source.hpp index 51ea452fb2..938a20612c 100644 --- a/platform/android/src/style/sources/geojson_source.hpp +++ b/platform/android/src/style/sources/geojson_source.hpp @@ -38,6 +38,8 @@ public: jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::Object<>> jfilter); + jni::String getURL(jni::JNIEnv&); + jni::jobject* createJavaPeer(jni::JNIEnv&); }; // class GeoJSONSource diff --git a/platform/android/src/style/sources/raster_source.cpp b/platform/android/src/style/sources/raster_source.cpp index 0234901a77..32fdb163b0 100644 --- a/platform/android/src/style/sources/raster_source.cpp +++ b/platform/android/src/style/sources/raster_source.cpp @@ -28,6 +28,11 @@ namespace android { RasterSource::~RasterSource() = default; + jni::String RasterSource::getURL(jni::JNIEnv& env) { + optional<std::string> url = source.as<mbgl::style::RasterSource>()->RasterSource::getURL(); + return url ? jni::Make<jni::String>(env, *url) : jni::String(); + } + jni::Class<RasterSource> RasterSource::javaClass; jni::jobject* RasterSource::createJavaPeer(jni::JNIEnv& env) { @@ -46,7 +51,8 @@ namespace android { env, RasterSource::javaClass, "nativePtr", std::make_unique<RasterSource, JNIEnv&, jni::String, jni::Object<>, jni::jint>, "initialize", - "finalize" + "finalize", + METHOD(&RasterSource::getURL, "nativeGetUrl") ); } diff --git a/platform/android/src/style/sources/raster_source.hpp b/platform/android/src/style/sources/raster_source.hpp index 6600096f6d..a79ccc10a4 100644 --- a/platform/android/src/style/sources/raster_source.hpp +++ b/platform/android/src/style/sources/raster_source.hpp @@ -22,6 +22,8 @@ public: ~RasterSource(); + jni::String getURL(jni::JNIEnv&); + jni::jobject* createJavaPeer(jni::JNIEnv&); }; // class RasterSource diff --git a/platform/android/src/style/sources/vector_source.cpp b/platform/android/src/style/sources/vector_source.cpp index a8f74df142..e2d9f60dec 100644 --- a/platform/android/src/style/sources/vector_source.cpp +++ b/platform/android/src/style/sources/vector_source.cpp @@ -34,6 +34,11 @@ namespace android { VectorSource::~VectorSource() = default; + jni::String VectorSource::getURL(jni::JNIEnv& env) { + optional<std::string> url = source.as<mbgl::style::VectorSource>()->VectorSource::getURL(); + return url ? jni::Make<jni::String>(env, *url) : jni::String(); + } + jni::Array<jni::Object<geojson::Feature>> VectorSource::querySourceFeatures(jni::JNIEnv& env, jni::Array<jni::String> jSourceLayerIds, jni::Array<jni::Object<>> jfilter) { @@ -66,7 +71,8 @@ namespace android { std::make_unique<VectorSource, JNIEnv&, jni::String, jni::Object<>>, "initialize", "finalize", - METHOD(&VectorSource::querySourceFeatures, "querySourceFeatures") + METHOD(&VectorSource::querySourceFeatures, "querySourceFeatures"), + METHOD(&VectorSource::getURL, "nativeGetUrl") ); } diff --git a/platform/android/src/style/sources/vector_source.hpp b/platform/android/src/style/sources/vector_source.hpp index cac687bb6f..643b468338 100644 --- a/platform/android/src/style/sources/vector_source.hpp +++ b/platform/android/src/style/sources/vector_source.hpp @@ -26,6 +26,8 @@ public: jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::String>, jni::Array<jni::Object<>> jfilter); + jni::String getURL(jni::JNIEnv&); + jni::jobject* createJavaPeer(jni::JNIEnv&); }; // class VectorSource |