[android] layer list accessor + example
This commit is contained in:
committed by
Ivo van Dongen
parent
62e85c1224
commit
ec1dc2622b
@@ -12,6 +12,7 @@ import android.view.View;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Property;
|
||||
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
|
||||
import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException;
|
||||
@@ -31,9 +32,12 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
@@ -55,6 +59,26 @@ public class RuntimeStyleTests {
|
||||
Espresso.registerIdlingResources(idlingResource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListLayers() {
|
||||
ViewUtils.checkViewIsDisplayed(R.id.mapView);
|
||||
onView(withId(R.id.mapView)).perform(new BaseViewAction() {
|
||||
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
MapboxMap mapboxMap = rule.getActivity().getMapboxMap();
|
||||
|
||||
List<Layer> layers = mapboxMap.getLayers();
|
||||
assertNotNull(layers);
|
||||
assertTrue(layers.size() > 0);
|
||||
for (Layer layer : layers) {
|
||||
assertNotNull(layer);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAddRemoveLayer() {
|
||||
ViewUtils.checkViewIsDisplayed(R.id.mapView);
|
||||
|
||||
@@ -40,6 +40,7 @@ import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
@@ -150,6 +151,9 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_list_layers:
|
||||
listLayers();
|
||||
return true;
|
||||
case R.id.action_water_color:
|
||||
setWaterColor();
|
||||
return true;
|
||||
@@ -197,6 +201,16 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void listLayers() {
|
||||
List<Layer> layers = mapboxMap.getLayers();
|
||||
StringBuilder builder = new StringBuilder("Layers:");
|
||||
for (Layer layer : layers) {
|
||||
builder.append("\n");
|
||||
builder.append(layer.getId());
|
||||
}
|
||||
Toast.makeText(this, builder.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void setLayerInvisible() {
|
||||
String[] roadLayers = new String[] {"water"};
|
||||
for (String roadLayer : roadLayers) {
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:mapbox="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_list_layers"
|
||||
android:title="List all layers in the style"
|
||||
mapbox:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_water_color"
|
||||
android:title="Color the water"
|
||||
|
||||
Reference in New Issue
Block a user