summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java14
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java18
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/NoSuchLayerException.java11
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/NoSuchSourceException.java11
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java32
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java11
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.java8
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java7
-rwxr-xr-xplatform/android/src/jni.cpp27
9 files changed, 31 insertions, 108 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
index 69a95457b8..697e62828a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
@@ -38,8 +38,6 @@ import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
import com.mapbox.mapboxsdk.style.layers.Layer;
-import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException;
-import com.mapbox.mapboxsdk.style.sources.NoSuchSourceException;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.services.commons.geojson.Feature;
@@ -262,10 +260,9 @@ public final class MapboxMap {
* Removes the layer. Any references to the layer become invalid and should not be used anymore
*
* @param layerId the layer to remove
- * @throws NoSuchLayerException the exception thrown when layer with layerId doesn't exist
*/
@UiThread
- public void removeLayer(@NonNull String layerId) throws NoSuchLayerException {
+ public void removeLayer(@NonNull String layerId) {
nativeMapView.removeLayer(layerId);
}
@@ -273,10 +270,9 @@ public final class MapboxMap {
* Removes the layer. The reference is re-usable after this and can be re-added
*
* @param layer the layer to remove
- * @throws NoSuchLayerException the exeption thrown when the layer doesn't exist
*/
@UiThread
- public void removeLayer(@NonNull Layer layer) throws NoSuchLayerException {
+ public void removeLayer(@NonNull Layer layer) {
nativeMapView.removeLayer(layer);
}
@@ -319,10 +315,9 @@ 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
- * @throws NoSuchSourceException the exception thrown when the source with sourceId doesn't exist
*/
@UiThread
- public void removeSource(@NonNull String sourceId) throws NoSuchSourceException {
+ public void removeSource(@NonNull String sourceId) {
nativeMapView.removeSource(sourceId);
}
@@ -330,10 +325,9 @@ public final class MapboxMap {
* Removes the source, preserving the reverence for re-use
*
* @param source the source to remove
- * @throws NoSuchSourceException the exception thrown when the source with sourceId doesn't exist
*/
@UiThread
- public void removeSource(@NonNull Source source) throws NoSuchSourceException {
+ public void removeSource(@NonNull Source source) {
nativeMapView.removeSource(source);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
index 3e5a79f4de..c17f538434 100755
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
@@ -21,8 +21,6 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.offline.OfflineManager;
import com.mapbox.mapboxsdk.style.layers.Layer;
-import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException;
-import com.mapbox.mapboxsdk.style.sources.NoSuchSourceException;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.services.commons.geojson.Feature;
@@ -804,14 +802,14 @@ final class NativeMapView {
nativeAddLayer(nativeMapViewPtr, layer.getNativePtr(), before);
}
- public void removeLayer(@NonNull String layerId) throws NoSuchLayerException {
+ public void removeLayer(@NonNull String layerId) {
if (isDestroyedOn("removeLayer")) {
return;
}
nativeRemoveLayerById(nativeMapViewPtr, layerId);
}
- public void removeLayer(@NonNull Layer layer) throws NoSuchLayerException {
+ public void removeLayer(@NonNull Layer layer) {
if (isDestroyedOn("removeLayer")) {
return;
}
@@ -832,14 +830,14 @@ final class NativeMapView {
nativeAddSource(nativeMapViewPtr, source.getNativePtr());
}
- public void removeSource(@NonNull String sourceId) throws NoSuchSourceException {
+ public void removeSource(@NonNull String sourceId) {
if (isDestroyedOn("removeSource")) {
return;
}
nativeRemoveSourceById(nativeMapViewPtr, sourceId);
}
- public void removeSource(@NonNull Source source) throws NoSuchSourceException {
+ public void removeSource(@NonNull Source source) {
if (isDestroyedOn("removeSource")) {
return;
}
@@ -1129,17 +1127,17 @@ final class NativeMapView {
private native void nativeAddLayer(long nativeMapViewPtr, long layerPtr, String before);
- private native void nativeRemoveLayerById(long nativeMapViewPtr, String layerId) throws NoSuchLayerException;
+ private native void nativeRemoveLayerById(long nativeMapViewPtr, String layerId);
- private native void nativeRemoveLayer(long nativeMapViewPtr, long layerId) throws NoSuchLayerException;
+ private native void nativeRemoveLayer(long nativeMapViewPtr, long layerId);
private native Source nativeGetSource(long nativeMapViewPtr, String sourceId);
private native void nativeAddSource(long nativeMapViewPtr, long nativeSourcePtr);
- private native void nativeRemoveSourceById(long nativeMapViewPtr, String sourceId) throws NoSuchSourceException;
+ private native void nativeRemoveSourceById(long nativeMapViewPtr, String sourceId);
- private native void nativeRemoveSource(long nativeMapViewPtr, long sourcePtr) throws NoSuchSourceException;
+ private native void nativeRemoveSource(long nativeMapViewPtr, long sourcePtr);
private native void nativeAddImage(long nativeMapViewPtr, String name, int width, int height, float pixelRatio,
byte[] array);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/NoSuchLayerException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/NoSuchLayerException.java
deleted file mode 100644
index 3b8777080d..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/NoSuchLayerException.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.mapbox.mapboxsdk.style.layers;
-
-/**
- * No such layer.
- */
-public class NoSuchLayerException extends Exception {
-
- public NoSuchLayerException(String message) {
- super(message);
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/NoSuchSourceException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/NoSuchSourceException.java
deleted file mode 100644
index 06d35b598b..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/NoSuchSourceException.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.mapbox.mapboxsdk.style.sources;
-
-/**
- * No such source.
- */
-public class NoSuchSourceException extends Exception {
-
- public NoSuchSourceException(String message) {
- super(message);
- }
-}
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 a07ad924d5..04c57636f2 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
@@ -12,11 +12,9 @@ import android.view.View;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
import com.mapbox.mapboxsdk.style.layers.FillLayer;
-import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException;
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.NoSuchSourceException;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.mapboxsdk.style.sources.VectorSource;
import com.mapbox.mapboxsdk.testapp.R;
@@ -69,11 +67,7 @@ public class RuntimeStyleTests {
MapboxMap mapboxMap = rule.getActivity().getMapboxMap();
mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
- try {
- mapboxMap.removeSource("my-source");
- } catch (NoSuchSourceException noSuchSourceException) {
- // it's ok..
- }
+ mapboxMap.removeSource("my-source");
onView(withId(R.id.mapView)).perform(new AddRemoveSourceAction());
}
@@ -109,11 +103,7 @@ public class RuntimeStyleTests {
assertNotNull(mapboxMap.getLayer("building"));
// Remove
- try {
- mapboxMap.removeLayer("building");
- } catch (NoSuchLayerException noSuchSourceException) {
- fail("Definitively exists: " + noSuchSourceException.getMessage());
- }
+ mapboxMap.removeLayer("building");
assertNull(mapboxMap.getLayer("building"));
// Add
@@ -126,11 +116,7 @@ public class RuntimeStyleTests {
layer.setProperties(PropertyFactory.visibility(Property.VISIBLE));
// Remove, preserving the reference
- try {
- mapboxMap.removeLayer(layer);
- } catch (NoSuchLayerException noSuchSourceException) {
- fail("Definitively exists: " + noSuchSourceException.getMessage());
- }
+ mapboxMap.removeLayer(layer);
// Property setters should still work
layer.setProperties(PropertyFactory.fillColor(Color.RED));
@@ -161,11 +147,7 @@ public class RuntimeStyleTests {
mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
// Remove
- try {
- mapboxMap.removeSource("my-source");
- } catch (NoSuchSourceException noSuchSourceException) {
- fail("Definitively exists: " + noSuchSourceException.getMessage());
- }
+ mapboxMap.removeSource("my-source");
assertNull(mapboxMap.getLayer("my-source"));
// Add
@@ -173,11 +155,7 @@ public class RuntimeStyleTests {
mapboxMap.addSource(source);
// Remove, preserving the reference
- try {
- mapboxMap.removeSource(source);
- } catch (NoSuchSourceException noSuchSourceException) {
- fail("Definitively exists: " + noSuchSourceException.getMessage());
- }
+ mapboxMap.removeSource(source);
// Re-add the reference...
mapboxMap.addSource(source);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java
index d410c349f0..50e6b75194 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java
@@ -14,12 +14,9 @@ import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.style.layers.CustomLayer;
-import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.model.customlayer.ExampleCustomLayer;
-import timber.log.Timber;
-
public class CustomLayerActivity extends AppCompatActivity {
private MapboxMap mapboxMap;
@@ -58,12 +55,8 @@ public class CustomLayerActivity extends AppCompatActivity {
private void swapCustomLayer() {
if (customLayer != null) {
- try {
- mapboxMap.removeLayer(customLayer.getId());
- customLayer = null;
- } catch (NoSuchLayerException noSuchLayerException) {
- Timber.e("No custom layer to remove");
- }
+ mapboxMap.removeLayer(customLayer);
+ customLayer = null;
fab.setImageResource(R.drawable.ic_layers);
} else {
customLayer = new CustomLayer("custom",
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.java
index 07b677a788..ca4fe4e4fd 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.java
@@ -62,12 +62,8 @@ public class QueryRenderedFeaturesBoxHighlightActivity extends AppCompatActivity
Toast.LENGTH_SHORT).show();
// remove layer / source if already added
- try {
- mapboxMap.removeSource("highlighted-shapes-source");
- mapboxMap.removeLayer("highlighted-shapes-layer");
- } catch (Exception exception) {
- // that's ok
- }
+ mapboxMap.removeSource("highlighted-shapes-source");
+ mapboxMap.removeLayer("highlighted-shapes-layer");
// Add layer / source
mapboxMap.addSource(
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java
index e6650e8300..58321718d6 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java
@@ -20,7 +20,6 @@ import com.mapbox.mapboxsdk.style.functions.stops.Stop;
import com.mapbox.mapboxsdk.style.layers.FillLayer;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.LineLayer;
-import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException;
import com.mapbox.mapboxsdk.style.layers.Property;
import com.mapbox.mapboxsdk.style.layers.PropertyValue;
import com.mapbox.mapboxsdk.style.layers.RasterLayer;
@@ -247,11 +246,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
private void removeBuildings() {
// Zoom to see buildings first
- try {
- mapboxMap.removeLayer("building");
- } catch (NoSuchLayerException noSuchLayerException) {
- Toast.makeText(RuntimeStyleActivity.this, noSuchLayerException.getMessage(), Toast.LENGTH_SHORT).show();
- }
+ mapboxMap.removeLayer("building");
}
private void addParksLayer() {
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index 3f5f48561b..59602c3299 100755
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -1188,11 +1188,8 @@ void nativeAddLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jlon
void nativeRemoveLayerById(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* id) {
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
- try {
- nativeMapView->getMap().removeLayer(std_string_from_jstring(env, id));
- } catch (const std::runtime_error& error) {
- jni::ThrowNew(*env, jni::FindClass(*env, "com/mapbox/mapboxsdk/style/layers/NoSuchLayerException"), error.what());
- }
+
+ nativeMapView->getMap().removeLayer(std_string_from_jstring(env, id));
}
/**
@@ -1202,11 +1199,10 @@ void nativeRemoveLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, j
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
mbgl::android::Layer *layer = reinterpret_cast<mbgl::android::Layer *>(layerPtr);
- try {
- std::unique_ptr<mbgl::style::Layer> coreLayer = nativeMapView->getMap().removeLayer(layer->get().getID());
+
+ std::unique_ptr<mbgl::style::Layer> coreLayer = nativeMapView->getMap().removeLayer(layer->get().getID());
+ if (coreLayer) {
layer->setLayer(std::move(coreLayer));
- } catch (const std::runtime_error& error) {
- jni::ThrowNew(*env, jni::FindClass(*env, "com/mapbox/mapboxsdk/style/layers/NoSuchLayerException"), error.what());
}
}
@@ -1246,22 +1242,17 @@ void nativeAddSource(JNIEnv *env, jni::jobject* obj, jni::jlong nativeMapViewPtr
void nativeRemoveSourceById(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* id) {
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
- try {
- nativeMapView->getMap().removeSource(std_string_from_jstring(env, id));
- } catch (const std::runtime_error& error) {
- jni::ThrowNew(*env, jni::FindClass(*env, "com/mapbox/mapboxsdk/style/sources/NoSuchSourceException"), error.what());
- }
+ nativeMapView->getMap().removeSource(std_string_from_jstring(env, id));
}
void nativeRemoveSource(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jlong sourcePtr) {
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
mbgl::android::Source *source = reinterpret_cast<mbgl::android::Source *>(sourcePtr);
- try {
- std::unique_ptr<mbgl::style::Source> coreSource = nativeMapView->getMap().removeSource(source->get().getID());
+
+ std::unique_ptr<mbgl::style::Source> coreSource = nativeMapView->getMap().removeSource(source->get().getID());
+ if (coreSource) {
source->setSource(std::move(coreSource));
- } catch (const std::runtime_error& error) {
- jni::ThrowNew(*env, jni::FindClass(*env, "com/mapbox/mapboxsdk/style/sources/NoSuchSourceException"), error.what());
}
}