diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2016-11-10 13:19:18 +0100 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2016-11-11 13:46:10 +0100 |
commit | 1beb28e75bc70dba9c4a79d87da79cbb51ed19db (patch) | |
tree | 411d3cb8816fce1f4e7fd617cb4e8d913e286453 | |
parent | 185983f2f7be3d1624e057c04ef5310e84b6d27a (diff) | |
download | qtlocation-mapboxgl-1beb28e75bc70dba9c4a79d87da79cbb51ed19db.tar.gz |
[android] updated test activities for refactored layer/source ownership
3 files changed, 12 insertions, 15 deletions
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 ea8e39275f..be71133610 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 @@ public class CustomLayerActivity extends AppCompatActivity { @Override public void onMapReady(MapboxMap map) { mapboxMap = map; - mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.91448, -243.60947), 10)); } @@ -62,30 +61,28 @@ public class CustomLayerActivity extends AppCompatActivity { } 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 e7b00e2a7c..d279a78a47 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 class CircleLayerActivity extends AppCompatActivity { 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 bdd3963e85..ebeaeafcf4 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 class CustomSpriteActivity extends AppCompatActivity { //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 class CustomSpriteActivity extends AppCompatActivity { } 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 |