[android] remove nonexistent layer or source handling

This commit is contained in:
Ivo van Dongen
2017-02-21 15:33:59 +02:00
committed by Jesse Bounds
parent 59820fb63d
commit d1f444d63e
9 changed files with 31 additions and 108 deletions

View File

@@ -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",

View File

@@ -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(

View File

@@ -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() {