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 ea8e39275fb..be711336106 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 @@ -26,8 +26,8 @@ public class CustomLayerActivity extends AppCompatActivity { private MapboxMap mapboxMap; private MapView mapView; + private CustomLayer customLayer; - private boolean isShowingCustomLayer = false; private FloatingActionButton fab; @Override @@ -43,7 +43,6 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onMapReady(MapboxMap map) { mapboxMap = map; - mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.91448, -243.60947), 10)); } @@ -62,30 +61,28 @@ public void onClick(View view) { } private void swapCustomLayer() { - - if (isShowingCustomLayer) { + if (customLayer != null) { try { - mapboxMap.removeLayer("custom"); + mapboxMap.removeLayer(customLayer.getId()); + customLayer = null; } catch (NoSuchLayerException noSuchLayerException) { Log.e(TAG, "No custom layer to remove"); } fab.setImageResource(R.drawable.ic_layers_24dp); } else { - mapboxMap.addLayer(new CustomLayer("custom", + customLayer = new CustomLayer("custom", ExampleCustomLayer.createContext(), ExampleCustomLayer.InitializeFunction, ExampleCustomLayer.RenderFunction, - ExampleCustomLayer.DeinitializeFunction), "building"); + ExampleCustomLayer.DeinitializeFunction); + mapboxMap.addLayer(customLayer, "building"); fab.setImageResource(R.drawable.ic_layers_clear_24dp); } - - isShowingCustomLayer = !isShowingCustomLayer; } private void updateLayer() { - CustomLayer custom = mapboxMap.getLayerAs("custom"); - if (custom != null) { - custom.update(); + if (customLayer != null) { + customLayer.update(); } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.java index e7b00e2a7c6..d279a78a474 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.java @@ -84,7 +84,6 @@ public void onClick(View view) { mapboxMap.addLayer(circleLayer, "waterway-label"); } else { // change size and color - circleLayer = mapboxMap.getLayer("circleLayer"); circleLayer.setProperties( circleRadius(mapView.getTag() == null ? getResources().getDimension(R.dimen.activity_horizontal_margin) diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.java index bdd3963e857..ebeaeafcf4f 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.java @@ -38,6 +38,7 @@ public class CustomSpriteActivity extends AppCompatActivity { private MapboxMap mapboxMap; private MapView mapView; private Layer layer; + private GeoJsonSource source; @Override @@ -74,7 +75,8 @@ public void onClick(View view) { //Add a source with a geojson point point = Point.fromCoordinates(Position.fromCoordinates(13.400972d, 52.519003d)); - mapboxMap.addSource(new GeoJsonSource("point", FeatureCollection.fromFeatures(new Feature[]{Feature.fromGeometry(point)}))); + source = new GeoJsonSource("point", FeatureCollection.fromFeatures(new Feature[]{Feature.fromGeometry(point)})); + mapboxMap.addSource(source); //Add a symbol layer that references that point source layer = new SymbolLayer("layer", "point"); @@ -90,7 +92,6 @@ public void onClick(View view) { } else { //Update point point = Point.fromCoordinates(Position.fromCoordinates(point.getCoordinates().getLongitude() + 0.001, point.getCoordinates().getLatitude() + 0.001)); - GeoJsonSource source = mapboxMap.getSourceAs("point"); source.setGeoJson(FeatureCollection.fromFeatures(new Feature[]{Feature.fromGeometry(point)})); //Move the camera as well