[android] remove source returns reference
This commit is contained in:
committed by
Ivo van Dongen
parent
fedb21e35b
commit
3040d40772
@@ -350,20 +350,24 @@ public final class MapboxMap {
|
||||
* Removes the source. Any references to the source become invalid and should not be used anymore
|
||||
*
|
||||
* @param sourceId the source to remove
|
||||
* @return the source handle or null if the source was not present
|
||||
*/
|
||||
@UiThread
|
||||
public void removeSource(@NonNull String sourceId) {
|
||||
nativeMapView.removeSource(sourceId);
|
||||
@Nullable
|
||||
public Source removeSource(@NonNull String sourceId) {
|
||||
return nativeMapView.removeSource(sourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the source, preserving the reverence for re-use
|
||||
*
|
||||
* @param source the source to remove
|
||||
* @return the source
|
||||
*/
|
||||
@UiThread
|
||||
public void removeSource(@NonNull Source source) {
|
||||
nativeMapView.removeSource(source);
|
||||
@Nullable
|
||||
public Source removeSource(@NonNull Source source) {
|
||||
return nativeMapView.removeSource(source);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -806,18 +806,20 @@ final class NativeMapView {
|
||||
nativeAddSource(source.getNativePtr());
|
||||
}
|
||||
|
||||
public void removeSource(@NonNull String sourceId) {
|
||||
@Nullable
|
||||
public Source removeSource(@NonNull String sourceId) {
|
||||
if (isDestroyedOn("removeSource")) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
nativeRemoveSourceById(sourceId);
|
||||
return nativeRemoveSourceById(sourceId);
|
||||
}
|
||||
|
||||
public void removeSource(@NonNull Source source) {
|
||||
public Source removeSource(@NonNull Source source) {
|
||||
if (isDestroyedOn("removeSource")) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
nativeRemoveSource(source.getNativePtr());
|
||||
return source;
|
||||
}
|
||||
|
||||
public void addImage(@NonNull String name, @NonNull Bitmap image) {
|
||||
@@ -1087,7 +1089,7 @@ final class NativeMapView {
|
||||
|
||||
private native void nativeAddSource(long nativeSourcePtr) throws CannotAddSourceException;
|
||||
|
||||
private native void nativeRemoveSourceById(String sourceId);
|
||||
private native Source nativeRemoveSourceById(String sourceId);
|
||||
|
||||
private native void nativeRemoveSource(long sourcePtr);
|
||||
|
||||
|
||||
@@ -192,7 +192,8 @@ public class RuntimeStyleTests {
|
||||
mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
|
||||
|
||||
// Remove
|
||||
mapboxMap.removeSource("my-source");
|
||||
Source mySource = mapboxMap.removeSource("my-source");
|
||||
assertNotNull(mySource);
|
||||
assertNull(mapboxMap.getLayer("my-source"));
|
||||
|
||||
// Add
|
||||
|
||||
@@ -844,8 +844,13 @@ void NativeMapView::addSource(JNIEnv& env, jni::jlong sourcePtr) {
|
||||
}
|
||||
}
|
||||
|
||||
void NativeMapView::removeSourceById(JNIEnv& env, jni::String id) {
|
||||
map->removeSource(jni::Make<std::string>(env, id));
|
||||
jni::Object<Source> NativeMapView::removeSourceById(JNIEnv& env, jni::String id) {
|
||||
std::unique_ptr<mbgl::style::Source> coreSource = map->removeSource(jni::Make<std::string>(env, id));
|
||||
if (coreSource) {
|
||||
return jni::Object<Source>(createJavaSourcePeer(env, *map, *coreSource));
|
||||
} else {
|
||||
return jni::Object<Source>();
|
||||
}
|
||||
}
|
||||
|
||||
void NativeMapView::removeSource(JNIEnv&, jlong sourcePtr) {
|
||||
|
||||
@@ -217,7 +217,7 @@ public:
|
||||
|
||||
void addSource(JNIEnv&, jni::jlong);
|
||||
|
||||
void removeSourceById(JNIEnv&, jni::String);
|
||||
jni::Object<Source> removeSourceById(JNIEnv&, jni::String);
|
||||
|
||||
void removeSource(JNIEnv&, jlong);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user