[android] insert layer above

This commit is contained in:
Ivo van Dongen
2017-02-24 17:18:26 +02:00
committed by Ivo van Dongen
parent 3040d40772
commit dc21396d71
9 changed files with 118 additions and 15 deletions

View File

@@ -11,6 +11,7 @@ import android.view.View;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
import com.mapbox.mapboxsdk.style.layers.FillLayer;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.Property;
@@ -37,10 +38,11 @@ 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.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Basic smoke tests for Layer and Source
@@ -85,6 +87,41 @@ public class RuntimeStyleTests {
onView(withId(R.id.mapView)).perform(new AddRemoveLayerAction());
}
@Test
public void testAddLayerAbove() {
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();
Source source = mapboxMap.getSources().get(0);
// Test inserting with invalid above-id
try {
mapboxMap.addLayerAbove(new CircleLayer("invalid-id-layer-test", source.getId()), "no-such-layer-here-man");
fail("Should have thrown exception");
} catch (CannotAddLayerException ex) {
// Yeah
assertNotNull(ex.getMessage());
}
// Insert as last
CircleLayer last = new CircleLayer("this is the last one", source.getId());
mapboxMap.addLayerAbove(last, layers.get(layers.size() - 1).getId());
layers = mapboxMap.getLayers();
assertEquals(last.getId(), layers.get(layers.size() - 1).getId());
// Insert
CircleLayer second = new CircleLayer("this is the second one", source.getId());
mapboxMap.addLayerAbove(second, layers.get(0).getId());
layers = mapboxMap.getLayers();
assertEquals(second.getId(), layers.get(1).getId());
}
});
}
@Test
public void testListSources() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
@@ -97,7 +134,7 @@ public class RuntimeStyleTests {
List<Source> sources = mapboxMap.getSources();
assertNotNull(sources);
assertTrue(sources.size() > 0);
for (Source source: sources) {
for (Source source : sources) {
assertNotNull(source);
}
}

View File

@@ -70,7 +70,7 @@ public class CustomLayerActivity extends AppCompatActivity {
ExampleCustomLayer.InitializeFunction,
ExampleCustomLayer.RenderFunction,
ExampleCustomLayer.DeinitializeFunction);
mapboxMap.addLayer(customLayer, "building");
mapboxMap.addLayerBelow(customLayer, "building");
fab.setImageResource(R.drawable.ic_layers_clear);
}
}

View File

@@ -91,7 +91,7 @@ public class CircleLayerActivity extends AppCompatActivity {
Timber.e("That's not an url... ", malformedUrlException);
}
LineLayer lineLayer = new LineLayer("route_layer", "bus_route");
mapboxMap.addLayer(lineLayer, "stops_layer");
mapboxMap.addLayerBelow(lineLayer, "stops_layer");
// move camera to start route
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(

View File

@@ -77,7 +77,7 @@ public class CustomSpriteActivity extends AppCompatActivity {
);
// lets add a circle below labels!
mapboxMap.addLayer(layer, "waterway-label");
mapboxMap.addLayerBelow(layer, "waterway-label");
fab.setImageResource(R.drawable.ic_directions_car_black);
} else {

View File

@@ -40,7 +40,6 @@ 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;
@@ -302,7 +301,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
// Only show me parks (except westerpark with stroke-width == 3)
layer.setFilter(all(eq("type", "park"), eq("stroke-width", 2)));
mapboxMap.addLayer(layer, "building");
mapboxMap.addLayerBelow(layer, "building");
// layer.setPaintProperty(fillColor(Color.RED)); // XXX But not after the object is attached
// Or get the object later and set it. It's all good.