[android] url getter on sources
This commit is contained in:
committed by
Ivo van Dongen
parent
625c2ea527
commit
489f76d3a2
@@ -227,6 +227,14 @@ public class GeoJsonSource extends Source {
|
||||
nativeSetUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The url or null
|
||||
*/
|
||||
@Nullable
|
||||
public String getUrl() {
|
||||
return nativeGetUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the source for 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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ public:
|
||||
|
||||
~RasterSource();
|
||||
|
||||
jni::String getURL(jni::JNIEnv&);
|
||||
|
||||
jni::jobject* createJavaPeer(jni::JNIEnv&);
|
||||
|
||||
}; // class RasterSource
|
||||
|
||||
@@ -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")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user