[android] updated test activities for refactored layer/source ownership
This commit is contained in:
committed by
Ivo van Dongen
parent
185983f2f7
commit
1beb28e75b
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user