[ios, android] Add methods to remove a custom layer

This commit is contained in:
John Firebaugh
2015-12-17 14:39:19 -08:00
parent d3c92a8b5c
commit 110f1ec796
11 changed files with 68 additions and 3 deletions

View File

@@ -3792,6 +3792,11 @@ public final class MapView extends FrameLayout {
mNativeMapView.addCustomLayer(customLayer, before);
}
@UiThread
public void removeCustomLayer(String id) {
mNativeMapView.removeCustomLayer(id);
}
@UiThread
public void invalidateCustomLayers() {
mNativeMapView.update();

View File

@@ -454,6 +454,10 @@ final class NativeMapView {
nativeAddCustomLayer(mNativeMapViewPtr, customLayer, before);
}
public void removeCustomLayer(String id) {
nativeRemoveCustomLayer(mNativeMapViewPtr, id);
}
//
// Callbacks
//
@@ -636,4 +640,6 @@ final class NativeMapView {
private native double nativeGetTopOffsetPixelsForAnnotationSymbol(long nativeMapViewPtr, String symbolName);
private native void nativeAddCustomLayer(long nativeMapViewPtr, CustomLayer customLayer, String before);
private native void nativeRemoveCustomLayer(long nativeMapViewPtr, String id);
}

View File

@@ -76,6 +76,7 @@ public class MainActivity extends AppCompatActivity {
private int mSelectedStyle = R.id.actionStyleMapboxStreets;
private NavigationView mNavigationView;
private CoordinatorLayout mCoordinatorLayout;
private boolean mIsShowingCustomLayer;
// Used for GPS
private FloatingActionButton mLocationFAB;
@@ -397,7 +398,11 @@ public class MainActivity extends AppCompatActivity {
return true;
case R.id.action_custom_layer:
addCustomLayer();
if (mIsShowingCustomLayer) {
removeCustomLayer();
} else {
addCustomLayer();
}
return true;
default:
@@ -576,6 +581,7 @@ public class MainActivity extends AppCompatActivity {
}
private void addCustomLayer() {
mIsShowingCustomLayer = true;
mMapView.addCustomLayer(
new CustomLayer("custom",
ExampleCustomLayer.createContext(),
@@ -585,6 +591,11 @@ public class MainActivity extends AppCompatActivity {
null);
}
private void removeCustomLayer() {
mIsShowingCustomLayer = false;
mMapView.removeCustomLayer("custom");
}
// Called when FPS changes
private class MyOnFpsChangedListener implements MapView.OnFpsChangedListener {

View File

@@ -1492,6 +1492,12 @@ void JNICALL nativeAddCustomLayer(JNIEnv *env, jobject obj, jlong nativeMapViewP
before ? std_string_from_jstring(env, before).c_str() : nullptr);
}
void JNICALL nativeRemoveCustomLayer(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring id) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeRemoveCustomLayer");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().removeCustomLayer(std_string_from_jstring(env, id));
}
}
@@ -2018,6 +2024,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
reinterpret_cast<void *>(&nativeGetTopOffsetPixelsForAnnotationSymbol)},
{"nativeAddCustomLayer", "(JLcom/mapbox/mapboxsdk/layers/CustomLayer;Ljava/lang/String;)V",
reinterpret_cast<void *>(&nativeAddCustomLayer)},
{"nativeRemoveCustomLayer", "(JLjava/lang/String;)V",
reinterpret_cast<void *>(&nativeRemoveCustomLayer)},
};
if (env->RegisterNatives(nativeMapViewClass, methods.data(), methods.size()) < 0) {