Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] url getter on sources
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed May 11, 2017
1 parent 625c2ea commit 489f76d
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ public void setUrl(String url) {
nativeSetUrl(url);
}

/**
* @return The url or null
*/
@Nullable
public String getUrl() {
return nativeGetUrl();
}

/**
* Queries the source for features.
*
Expand All @@ -243,6 +251,8 @@ public List<Feature> querySourceFeatures(@Nullable Filter.Statement filter) {

protected native void nativeSetUrl(String url);

protected native String nativeGetUrl();

private native void nativeSetGeoJsonString(String geoJson);

private native void nativeSetFeatureCollection(FeatureCollection geoJson);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mapbox.mapboxsdk.style.sources;

import android.support.annotation.Nullable;

import java.net.URL;

/**
Expand Down Expand Up @@ -72,8 +74,19 @@ public RasterSource(String id, TileSet tileSet, int tileSize) {
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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,21 @@ public List<Feature> querySourceFeatures(@Size(min = 1) String[] sourceLayerIds,
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
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;
Expand All @@ -28,6 +30,8 @@
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;
Expand Down Expand Up @@ -190,6 +194,35 @@ public void testAddRemoveSource() {
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
*/
Expand Down
6 changes: 6 additions & 0 deletions platform/android/src/style/sources/geojson_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
);
}
Expand Down
2 changes: 2 additions & 0 deletions platform/android/src/style/sources/geojson_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class GeoJSONSource : public Source {
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
Expand Down
8 changes: 7 additions & 1 deletion platform/android/src/style/sources/raster_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
);
}

Expand Down
2 changes: 2 additions & 0 deletions platform/android/src/style/sources/raster_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class RasterSource : public Source {

~RasterSource();

jni::String getURL(jni::JNIEnv&);

jni::jobject* createJavaPeer(jni::JNIEnv&);

}; // class RasterSource
Expand Down
8 changes: 7 additions & 1 deletion platform/android/src/style/sources/vector_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
);
}

Expand Down
2 changes: 2 additions & 0 deletions platform/android/src/style/sources/vector_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class VectorSource : public Source {
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
Expand Down

0 comments on commit 489f76d

Please sign in to comment.