Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] updated test activities for refactored layer/source ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Nov 10, 2016
1 parent 993f1db commit 825099a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));

}
Expand All @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class CustomSpriteActivity extends AppCompatActivity {
private MapboxMap mapboxMap;
private MapView mapView;
private Layer layer;
private GeoJsonSource source;


@Override
Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand Down

0 comments on commit 825099a

Please sign in to comment.