[android] - move all layer, source, image, light and transition configurations to style.java
This commit is contained in:
@@ -79,7 +79,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
|
||||
assertThat(mapboxMap.getSource(LOCATION_SOURCE), notNullValue())
|
||||
assertThat(mapboxMap.getStyle().getSource(LOCATION_SOURCE), notNullValue())
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -220,7 +220,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
assertThat(component.renderMode, `is`(equalTo(RenderMode.NORMAL)))
|
||||
|
||||
// Check that the Source has been re-added to the new map style
|
||||
val source: GeoJsonSource? = mapboxMap.getSourceAs(LOCATION_SOURCE)
|
||||
val source: GeoJsonSource? = mapboxMap.getStyle().getSourceAs(LOCATION_SOURCE)
|
||||
assertThat(source, notNullValue())
|
||||
|
||||
// Check that all layers visibilities are set to visible
|
||||
|
||||
@@ -99,7 +99,7 @@ class MapboxTestingUtils {
|
||||
|
||||
fun MapboxMap.addImageFromDrawable(string: String, drawable: Drawable) {
|
||||
val bitmapFromDrawable = getBitmapFromDrawable(drawable)
|
||||
this.addImage(string, bitmapFromDrawable)
|
||||
this.style.addImage(string, bitmapFromDrawable)
|
||||
}
|
||||
|
||||
private fun getBitmapFromDrawable(drawable: Drawable): Bitmap {
|
||||
|
||||
@@ -30,12 +30,12 @@ public class GeoJsonConversionTest extends BaseActivityTest {
|
||||
public void testEmptyFeatureCollection() {
|
||||
validateTestSetup();
|
||||
onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
|
||||
mapboxMap.addSource(
|
||||
mapboxMap.getStyle().addSource(
|
||||
new CustomGeometrySource("test-id",
|
||||
new CustomProvider(fromFeatures(singletonList(fromGeometry(fromGeometries(emptyList())))))
|
||||
)
|
||||
);
|
||||
mapboxMap.addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -43,12 +43,12 @@ public class GeoJsonConversionTest extends BaseActivityTest {
|
||||
public void testPointFeatureCollection() {
|
||||
validateTestSetup();
|
||||
onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
|
||||
mapboxMap.addSource(
|
||||
mapboxMap.getStyle().addSource(
|
||||
new CustomGeometrySource("test-id",
|
||||
new CustomProvider(fromFeatures(singletonList(fromGeometry(Point.fromLngLat(0.0,0.0)))))
|
||||
)
|
||||
);
|
||||
mapboxMap.addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -56,12 +56,12 @@ public class GeoJsonConversionTest extends BaseActivityTest {
|
||||
public void testMultiPointFeatureCollection() {
|
||||
validateTestSetup();
|
||||
onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
|
||||
mapboxMap.addSource(
|
||||
mapboxMap.getStyle().addSource(
|
||||
new CustomGeometrySource("test-id",
|
||||
new CustomProvider(fromFeatures(singletonList(fromGeometry(fromLngLats(emptyList())))))
|
||||
)
|
||||
);
|
||||
mapboxMap.addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -70,12 +70,12 @@ public class GeoJsonConversionTest extends BaseActivityTest {
|
||||
public void testPolygonFeatureCollection() {
|
||||
validateTestSetup();
|
||||
onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
|
||||
mapboxMap.addSource(
|
||||
mapboxMap.getStyle().addSource(
|
||||
new CustomGeometrySource("test-id",
|
||||
new CustomProvider(fromFeatures(singletonList(fromGeometry(Polygon.fromLngLats(emptyList())))))
|
||||
)
|
||||
);
|
||||
mapboxMap.addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -83,12 +83,12 @@ public class GeoJsonConversionTest extends BaseActivityTest {
|
||||
public void testMultiPolygonFeatureCollection() {
|
||||
validateTestSetup();
|
||||
onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
|
||||
mapboxMap.addSource(
|
||||
mapboxMap.getStyle().addSource(
|
||||
new CustomGeometrySource("test-id",
|
||||
new CustomProvider(fromFeatures(singletonList(fromGeometry(fromPolygon(Polygon.fromLngLats(emptyList()))))))
|
||||
)
|
||||
);
|
||||
mapboxMap.addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -96,12 +96,12 @@ public class GeoJsonConversionTest extends BaseActivityTest {
|
||||
public void testLineStringFeatureCollection() {
|
||||
validateTestSetup();
|
||||
onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
|
||||
mapboxMap.addSource(
|
||||
mapboxMap.getStyle().addSource(
|
||||
new CustomGeometrySource("test-id",
|
||||
new CustomProvider(fromFeatures(singletonList(fromGeometry(fromLngLats(emptyList())))))
|
||||
)
|
||||
);
|
||||
mapboxMap.addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -109,12 +109,12 @@ public class GeoJsonConversionTest extends BaseActivityTest {
|
||||
public void testMultiLineStringFeatureCollection() {
|
||||
validateTestSetup();
|
||||
onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
|
||||
mapboxMap.addSource(
|
||||
mapboxMap.getStyle().addSource(
|
||||
new CustomGeometrySource("test-id",
|
||||
new CustomProvider(fromFeatures(singletonList(fromGeometry(fromLineString(fromLngLats(emptyList()))))))
|
||||
)
|
||||
);
|
||||
mapboxMap.addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
mapboxMap.getStyle().addLayer(new SymbolLayer("test-id", "test-id"));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ public class AttributionTest extends BaseActivityTest {
|
||||
|
||||
private void buildUrlSpans() {
|
||||
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
|
||||
for (Source source : mapboxMap.getSources()) {
|
||||
for (Source source : mapboxMap.getStyle().getSources()) {
|
||||
String attributionSource = source.getAttribution();
|
||||
if (!TextUtils.isEmpty(attributionSource)) {
|
||||
SpannableStringBuilder htmlBuilder = (SpannableStringBuilder) Html.fromHtml(attributionSource);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class BackgroundLayerTest extends BaseActivityTest {
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
layer = mapboxMap.getLayerAs("background");
|
||||
layer = mapboxMap.getStyle().getLayerAs("background");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -39,13 +39,13 @@ public class CircleLayerTest extends BaseActivityTest {
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
if ((layer = mapboxMap.getStyle().getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new CircleLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
layer = mapboxMap.getStyle().getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@ class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
fun threadsShutdownWhenSourceRemovedTest() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController, mapboxMap ->
|
||||
mapboxMap.removeLayer(ID_GRID_LAYER)
|
||||
mapboxMap.getStyle().removeLayer(ID_GRID_LAYER)
|
||||
uiController.loopMainThreadForAtLeast(3000)
|
||||
mapboxMap.removeSource(ID_GRID_SOURCE)
|
||||
mapboxMap.getStyle().removeSource(ID_GRID_SOURCE)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
Assert.assertTrue("There should be no threads running when the source is removed.",
|
||||
Thread.getAllStackTraces().keys.filter {
|
||||
@@ -55,12 +55,12 @@ class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
fun threadsRestartedWhenSourceReAddedTest() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController, mapboxMap ->
|
||||
mapboxMap.removeLayer((rule.activity as GridSourceActivity).layer)
|
||||
mapboxMap.getStyle().removeLayer((rule.activity as GridSourceActivity).layer)
|
||||
uiController.loopMainThreadForAtLeast(3000)
|
||||
mapboxMap.removeSource(ID_GRID_SOURCE)
|
||||
mapboxMap.getStyle().removeSource(ID_GRID_SOURCE)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
mapboxMap.addSource((rule.activity as GridSourceActivity).source)
|
||||
mapboxMap.addLayer((rule.activity as GridSourceActivity).layer)
|
||||
mapboxMap.getStyle().addSource((rule.activity as GridSourceActivity).source)
|
||||
mapboxMap.getStyle().addLayer((rule.activity as GridSourceActivity).layer)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
Assert.assertTrue("Threads should be restarted when the source is re-added to the map.",
|
||||
Thread.getAllStackTraces().keys.filter {
|
||||
|
||||
@@ -242,7 +242,7 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
Expression expression3 = eq(literal("Łukasz"), literal("lukasz"), collator(literal(false), eq(literal(2),
|
||||
literal(1))));
|
||||
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
Layer layer = new CircleLayer("layer", "source")
|
||||
.withProperties(circleColor(
|
||||
switchCase(
|
||||
@@ -250,7 +250,7 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
literal(ColorUtils.colorToRgbaString(Color.RED))
|
||||
)
|
||||
));
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
uiController.loopMainThreadForAtLeast(1000);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
@@ -282,9 +282,9 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry("test")
|
||||
@@ -304,9 +304,9 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry("test", formatFontScale(1.75))
|
||||
@@ -326,9 +326,9 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
@@ -355,9 +355,9 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
@@ -386,9 +386,9 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
@@ -421,9 +421,9 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
Feature feature = Feature.fromGeometry(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
|
||||
feature.addStringProperty("test_property", "test");
|
||||
feature.addNumberProperty("test_property_number", 1.5);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", feature));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", feature));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
@@ -450,9 +450,9 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
Feature feature = Feature.fromGeometry(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
|
||||
feature.addStringProperty("test_property", "test");
|
||||
feature.addNumberProperty("test_property_number", 1.5);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", feature));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", feature));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
@@ -477,9 +477,9 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
layer.setProperties(textField("test"));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
@@ -534,13 +534,13 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
try {
|
||||
source = new GeoJsonSource("amsterdam-parks-source",
|
||||
ResourceUtils.readRawResource(rule.getActivity(), R.raw.amsterdam));
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
} catch (IOException ioException) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add a fill layer
|
||||
mapboxMap.addLayer(layer = new FillLayer("amsterdam-parks-layer", source.getId())
|
||||
mapboxMap.getStyle().addLayer(layer = new FillLayer("amsterdam-parks-layer", source.getId())
|
||||
.withProperties(
|
||||
fillColor(rgba(0.0f, 0.0f, 0.0f, 0.5f)),
|
||||
fillOutlineColor(rgb(0, 0, 255)),
|
||||
|
||||
@@ -39,13 +39,13 @@ public class FillExtrusionLayerTest extends BaseActivityTest {
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
if ((layer = mapboxMap.getStyle().getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new FillExtrusionLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
layer = mapboxMap.getStyle().getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,13 +39,13 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
if ((layer = mapboxMap.getStyle().getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new FillLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
layer = mapboxMap.getStyle().getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ public class GeoJsonSourceTests extends BaseActivityTest {
|
||||
} catch (IOException exception) {
|
||||
Timber.e(exception);
|
||||
}
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.addLayer(new CircleLayer("layer", source.getId()));
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
mapboxMap.getStyle().addLayer(new CircleLayer("layer", source.getId()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ public class GeoJsonSourceTests extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
GeoJsonSource source = new GeoJsonSource("source", Point.fromLngLat(0d, 0d));
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.addLayer(new CircleLayer("layer", source.getId()));
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
mapboxMap.getStyle().addLayer(new CircleLayer("layer", source.getId()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -77,8 +77,8 @@ public class GeoJsonSourceTests extends BaseActivityTest {
|
||||
} catch (IOException exception) {
|
||||
Timber.e(exception);
|
||||
}
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.addLayer(new CircleLayer("layer", source.getId()));
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
mapboxMap.getStyle().addLayer(new CircleLayer("layer", source.getId()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ public class GeoJsonSourceTests extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
GeoJsonSource source = new GeoJsonSource("source");
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.addLayer(new CircleLayer("layer", source.getId()));
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
mapboxMap.getStyle().addLayer(new CircleLayer("layer", source.getId()));
|
||||
|
||||
source.setGeoJson(Point.fromLngLat(0, 0));
|
||||
source.setGeoJson(Point.fromLngLat(-25, -25));
|
||||
@@ -146,9 +146,9 @@ public class GeoJsonSourceTests extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
GeoJsonSource source = new GeoJsonSource("source");
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
Layer layer = new CircleLayer("layer", source.getId());
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
try {
|
||||
source.setGeoJson(Feature.fromJson(ResourceUtils.readRawResource(rule.getActivity(), resource)));
|
||||
@@ -156,8 +156,8 @@ public class GeoJsonSourceTests extends BaseActivityTest {
|
||||
Timber.e(exception);
|
||||
}
|
||||
|
||||
mapboxMap.removeLayer(layer);
|
||||
mapboxMap.removeSource(source);
|
||||
mapboxMap.getStyle().removeLayer(layer);
|
||||
mapboxMap.getStyle().removeSource(source);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -39,13 +39,13 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
if ((layer = mapboxMap.getStyle().getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new HeatmapLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
layer = mapboxMap.getStyle().getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,13 +39,13 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
if ((layer = mapboxMap.getStyle().getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new HillshadeLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
layer = mapboxMap.getStyle().getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ImageTest extends BaseActivityTest {
|
||||
assertTrue(drawable instanceof BitmapDrawable);
|
||||
|
||||
Bitmap bitmapSet = ((BitmapDrawable) drawable).getBitmap();
|
||||
mapboxMap.addImage(IMAGE_ID, bitmapSet);
|
||||
mapboxMap.getStyle().addImage(IMAGE_ID, bitmapSet);
|
||||
|
||||
Bitmap bitmapGet = mapboxMap.getImage(IMAGE_ID);
|
||||
assertTrue(bitmapGet.sameAs(bitmapSet));
|
||||
|
||||
@@ -160,7 +160,7 @@ public class LightTest extends BaseActivityTest {
|
||||
fillExtrusionBase(Expression.get("min_height")),
|
||||
fillExtrusionOpacity(0.6f)
|
||||
);
|
||||
mapboxMap.addLayer(fillExtrusionLayer);
|
||||
mapboxMap.getStyle().addLayer(fillExtrusionLayer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,13 +39,13 @@ public class LineLayerTest extends BaseActivityTest {
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
if ((layer = mapboxMap.getStyle().getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new LineLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
layer = mapboxMap.getStyle().getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,13 +39,13 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
if ((layer = mapboxMap.getStyle().getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new RasterLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
layer = mapboxMap.getStyle().getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
List<Layer> layers = mapboxMap.getLayers();
|
||||
List<Layer> layers = mapboxMap.getStyle().getLayers();
|
||||
assertNotNull(layers);
|
||||
assertTrue(layers.size() > 0);
|
||||
for (Layer layer : layers) {
|
||||
@@ -89,12 +89,12 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
onView(withId(R.id.mapView)).perform(new BaseViewAction() {
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
List<Layer> layers = mapboxMap.getLayers();
|
||||
Source source = mapboxMap.getSources().get(0);
|
||||
List<Layer> layers = mapboxMap.getStyle().getLayers();
|
||||
Source source = mapboxMap.getStyle().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");
|
||||
mapboxMap.getStyle().addLayerAbove(new CircleLayer("invalid-id-layer-test", source.getId()), "no-such-layer-here-man");
|
||||
fail("Should have thrown exception");
|
||||
} catch (CannotAddLayerException ex) {
|
||||
// Yeah
|
||||
@@ -103,14 +103,14 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
|
||||
// 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();
|
||||
mapboxMap.getStyle().addLayerAbove(last, layers.get(layers.size() - 1).getId());
|
||||
layers = mapboxMap.getStyle().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();
|
||||
mapboxMap.getStyle().addLayerAbove(second, layers.get(0).getId());
|
||||
layers = mapboxMap.getStyle().getLayers();
|
||||
assertEquals(second.getId(), layers.get(1).getId());
|
||||
}
|
||||
});
|
||||
@@ -124,14 +124,14 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
// Remove by index
|
||||
Layer firstLayer = mapboxMap.getLayers().get(0);
|
||||
boolean removed = mapboxMap.removeLayerAt(0);
|
||||
Layer firstLayer = mapboxMap.getStyle().getLayers().get(0);
|
||||
boolean removed = mapboxMap.getStyle().removeLayerAt(0);
|
||||
assertTrue(removed);
|
||||
assertNotNull(firstLayer);
|
||||
|
||||
// Test remove by index bounds checks
|
||||
Timber.i("Remove layer at index > size");
|
||||
assertFalse(mapboxMap.removeLayerAt(Integer.MAX_VALUE));
|
||||
assertNull(mapboxMap.getStyle().removeLayerAt(Integer.MAX_VALUE));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -141,12 +141,12 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
onView(withId(R.id.mapView)).perform(new BaseViewAction() {
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
List<Layer> layers = mapboxMap.getLayers();
|
||||
Source source = mapboxMap.getSources().get(0);
|
||||
List<Layer> layers = mapboxMap.getStyle().getLayers();
|
||||
Source source = mapboxMap.getStyle().getSources().get(0);
|
||||
|
||||
// Test inserting out of range
|
||||
try {
|
||||
mapboxMap.addLayerAt(new CircleLayer("invalid-id-layer-test", source.getId()), layers.size());
|
||||
mapboxMap.getStyle().addLayerAt(new CircleLayer("invalid-id-layer-test", source.getId()), layers.size());
|
||||
fail("Should have thrown exception");
|
||||
} catch (CannotAddLayerException ex) {
|
||||
// Yeah
|
||||
@@ -155,14 +155,14 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
|
||||
// Insert at current last position
|
||||
CircleLayer last = new CircleLayer("this is the last one", source.getId());
|
||||
mapboxMap.addLayerAt(last, layers.size() - 1);
|
||||
layers = mapboxMap.getLayers();
|
||||
mapboxMap.getStyle().addLayerAt(last, layers.size() - 1);
|
||||
layers = mapboxMap.getStyle().getLayers();
|
||||
assertEquals(last.getId(), layers.get(layers.size() - 2).getId());
|
||||
|
||||
// Insert at start
|
||||
CircleLayer second = new CircleLayer("this is the first one", source.getId());
|
||||
mapboxMap.addLayerAt(second, 0);
|
||||
layers = mapboxMap.getLayers();
|
||||
mapboxMap.getStyle().addLayerAt(second, 0);
|
||||
layers = mapboxMap.getStyle().getLayers();
|
||||
assertEquals(second.getId(), layers.get(0).getId());
|
||||
}
|
||||
});
|
||||
@@ -176,7 +176,7 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
List<Source> sources = mapboxMap.getSources();
|
||||
List<Source> sources = mapboxMap.getStyle().getSources();
|
||||
assertNotNull(sources);
|
||||
assertTrue(sources.size() > 0);
|
||||
for (Source source : sources) {
|
||||
@@ -191,34 +191,34 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
public void testAddRemoveSource() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
|
||||
mapboxMap.removeSource("my-source");
|
||||
mapboxMap.getStyle().addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
|
||||
mapboxMap.getStyle().removeSource("my-source");
|
||||
|
||||
// Add initial source
|
||||
mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
|
||||
mapboxMap.getStyle().addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
|
||||
|
||||
// Remove
|
||||
boolean removeOk = mapboxMap.removeSource("my-source");
|
||||
boolean removeOk = mapboxMap.getStyle().removeSource("my-source");
|
||||
assertTrue(removeOk);
|
||||
assertNull(mapboxMap.getLayer("my-source"));
|
||||
assertNull(mapboxMap.getStyle().getLayer("my-source"));
|
||||
|
||||
// Add
|
||||
Source source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
// Remove, preserving the reference
|
||||
mapboxMap.removeSource(source);
|
||||
mapboxMap.getStyle().removeSource(source);
|
||||
|
||||
// Re-add the reference...
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
// Ensure it's there
|
||||
Assert.assertNotNull(mapboxMap.getSource(source.getId()));
|
||||
Assert.assertNotNull(mapboxMap.getStyle().getSource(source.getId()));
|
||||
|
||||
// Test adding a duplicate source
|
||||
try {
|
||||
Source source2 = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
|
||||
mapboxMap.addSource(source2);
|
||||
mapboxMap.getStyle().addSource(source2);
|
||||
fail("Should not have been allowed to add a source with a duplicate id");
|
||||
} catch (CannotAddSourceException cannotAddSourceException) {
|
||||
// OK
|
||||
@@ -232,7 +232,7 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
VectorSource source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUrl());
|
||||
});
|
||||
}
|
||||
@@ -242,7 +242,7 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
RasterSource source = new RasterSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUrl());
|
||||
});
|
||||
}
|
||||
@@ -252,7 +252,7 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
GeoJsonSource source = new GeoJsonSource("my-source");
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
assertNull(source.getUrl());
|
||||
try {
|
||||
source.setUrl(new URL("http://mapbox.com/my-file.json"));
|
||||
@@ -271,10 +271,10 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
|
||||
mapboxMap.addLayer(new LineLayer("my-layer", "my-source"));
|
||||
mapboxMap.removeSource("my-source");
|
||||
assertNotNull(mapboxMap.getSource("my-source"));
|
||||
mapboxMap.getStyle().addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
|
||||
mapboxMap.getStyle().addLayer(new LineLayer("my-layer", "my-source"));
|
||||
mapboxMap.getStyle().removeSource("my-source");
|
||||
assertNotNull(mapboxMap.getStyle().getSource("my-source"));
|
||||
}
|
||||
|
||||
});
|
||||
@@ -282,28 +282,28 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
|
||||
@Test
|
||||
public void testRemoveNonExistingSource() {
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> mapboxMap.removeSource("source"));
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> mapboxMap.getStyle().removeSource("source"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveNonExistingLayer() {
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertFalse(mapboxMap.removeLayer("layer"));
|
||||
assertFalse(mapboxMap.removeLayerAt(mapboxMap.getLayers().size() + 1));
|
||||
assertFalse(mapboxMap.removeLayerAt(-1));
|
||||
assertFalse(mapboxMap.getStyle().removeLayer("layer"));
|
||||
assertFalse(mapboxMap.getStyle().removeLayerAt(mapboxMap.getStyle().getLayers().size() + 1));
|
||||
assertFalse(mapboxMap.getStyle().removeLayerAt(-1));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveExistingLayer() {
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
Layer firstLayer = mapboxMap.getLayers().get(0);
|
||||
assertTrue(mapboxMap.removeLayer(firstLayer));
|
||||
Layer firstLayer = mapboxMap.getStyle().getLayers().get(0);
|
||||
assertTrue(mapboxMap.getStyle().removeLayer(firstLayer));
|
||||
|
||||
firstLayer = mapboxMap.getLayers().get(0);
|
||||
assertTrue(mapboxMap.removeLayer(firstLayer.getId()));
|
||||
firstLayer = mapboxMap.getStyle().getLayers().get(0);
|
||||
assertTrue(mapboxMap.getStyle().removeLayer(firstLayer.getId()));
|
||||
|
||||
assertTrue(mapboxMap.removeLayerAt(0));
|
||||
assertTrue(mapboxMap.getStyle().removeLayerAt(0));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -332,37 +332,37 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
// Get initial
|
||||
assertNotNull(mapboxMap.getLayer("building"));
|
||||
assertNotNull(mapboxMap.getStyle().getLayer("building"));
|
||||
|
||||
// Remove
|
||||
boolean removed = mapboxMap.removeLayer("building");
|
||||
boolean removed = mapboxMap.getStyle().removeLayer("building");
|
||||
assertTrue(removed);
|
||||
assertNull(mapboxMap.getLayer("building"));
|
||||
assertNull(mapboxMap.getStyle().getLayer("building"));
|
||||
|
||||
// Add
|
||||
FillLayer layer = new FillLayer("building", "composite");
|
||||
layer.setSourceLayer("building");
|
||||
mapboxMap.addLayer(layer);
|
||||
assertNotNull(mapboxMap.getLayer("building"));
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
assertNotNull(mapboxMap.getStyle().getLayer("building"));
|
||||
|
||||
// Assure the reference still works
|
||||
layer.setProperties(PropertyFactory.visibility(Property.VISIBLE));
|
||||
|
||||
// Remove, preserving the reference
|
||||
mapboxMap.removeLayer(layer);
|
||||
mapboxMap.getStyle().removeLayer(layer);
|
||||
|
||||
// Property setters should still work
|
||||
layer.setProperties(PropertyFactory.fillColor(Color.RED));
|
||||
|
||||
// Re-add the reference...
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
// Ensure it's there
|
||||
Assert.assertNotNull(mapboxMap.getLayer(layer.getId()));
|
||||
Assert.assertNotNull(mapboxMap.getStyle().getLayer(layer.getId()));
|
||||
|
||||
// Test adding a duplicate layer
|
||||
try {
|
||||
mapboxMap.addLayer(new FillLayer("building", "composite"));
|
||||
mapboxMap.getStyle().addLayer(new FillLayer("building", "composite"));
|
||||
fail("Should not have been allowed to add a layer with a duplicate id");
|
||||
} catch (CannotAddLayerException cannotAddLayerException) {
|
||||
// OK
|
||||
|
||||
@@ -41,13 +41,13 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
if ((layer = mapboxMap.getStyle().getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new SymbolLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
layer = mapboxMap.getStyle().getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,18 +48,18 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
<% if (type === 'background') { -%>
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
layer = mapboxMap.getLayerAs("background");
|
||||
layer = mapboxMap.getStyle().getLayerAs("background");
|
||||
});
|
||||
<% } else { -%>
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
if ((layer = mapboxMap.getStyle().getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new <%- camelize(type) %>Layer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
layer = mapboxMap.getStyle().getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
<% } -%>
|
||||
|
||||
@@ -120,7 +120,7 @@ public class LightTest extends BaseActivityTest {
|
||||
fillExtrusionBase(Expression.get("min_height")),
|
||||
fillExtrusionOpacity(0.6f)
|
||||
);
|
||||
mapboxMap.addLayer(fillExtrusionLayer);
|
||||
mapboxMap.getStyle().addLayer(fillExtrusionLayer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -56,6 +57,7 @@ public class AnimatedSymbolLayerActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private Style style;
|
||||
|
||||
private List<Car> randomCars = new ArrayList<>();
|
||||
private GeoJsonSource randomCarSource;
|
||||
@@ -72,8 +74,9 @@ public class AnimatedSymbolLayerActivity extends AppCompatActivity {
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
AnimatedSymbolLayerActivity.this.mapboxMap = mapboxMap;
|
||||
mapView.getMapAsync(map -> {
|
||||
this.mapboxMap = map;
|
||||
this.style = mapboxMap.getStyle();
|
||||
setupCars();
|
||||
animateRandomRoutes();
|
||||
animateTaxi();
|
||||
@@ -180,7 +183,7 @@ public class AnimatedSymbolLayerActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void updatePassengerSource() {
|
||||
GeoJsonSource source = mapboxMap.getSourceAs(PASSENGER_SOURCE);
|
||||
GeoJsonSource source = mapboxMap.getStyle().getSourceAs(PASSENGER_SOURCE);
|
||||
FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[] {
|
||||
Feature.fromGeometry(
|
||||
Point.fromLngLat(
|
||||
@@ -256,8 +259,8 @@ public class AnimatedSymbolLayerActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
randomCarSource = new GeoJsonSource(RANDOM_CAR_SOURCE, featuresFromRoutes());
|
||||
mapboxMap.addSource(randomCarSource);
|
||||
mapboxMap.addImage(RANDOM_CAR_IMAGE_ID,
|
||||
style.addSource(randomCarSource);
|
||||
mapboxMap.getStyle().addImage(RANDOM_CAR_IMAGE_ID,
|
||||
((BitmapDrawable) getResources().getDrawable(R.drawable.ic_car_top)).getBitmap());
|
||||
|
||||
SymbolLayer symbolLayer = new SymbolLayer(RANDOM_CAR_LAYER, RANDOM_CAR_SOURCE);
|
||||
@@ -268,7 +271,7 @@ public class AnimatedSymbolLayerActivity extends AppCompatActivity {
|
||||
iconIgnorePlacement(true)
|
||||
);
|
||||
|
||||
mapboxMap.addLayerBelow(symbolLayer, WATERWAY_LAYER_ID);
|
||||
style.addLayerBelow(symbolLayer, WATERWAY_LAYER_ID);
|
||||
}
|
||||
|
||||
private void addPassenger() {
|
||||
@@ -282,11 +285,11 @@ public class AnimatedSymbolLayerActivity extends AppCompatActivity {
|
||||
)
|
||||
});
|
||||
|
||||
mapboxMap.addImage(PASSENGER,
|
||||
mapboxMap.getStyle().addImage(PASSENGER,
|
||||
((BitmapDrawable) getResources().getDrawable(R.drawable.icon_burned)).getBitmap());
|
||||
|
||||
GeoJsonSource geoJsonSource = new GeoJsonSource(PASSENGER_SOURCE, featureCollection);
|
||||
mapboxMap.addSource(geoJsonSource);
|
||||
style.addSource(geoJsonSource);
|
||||
|
||||
SymbolLayer symbolLayer = new SymbolLayer(PASSENGER_LAYER, PASSENGER_SOURCE);
|
||||
symbolLayer.withProperties(
|
||||
@@ -294,7 +297,7 @@ public class AnimatedSymbolLayerActivity extends AppCompatActivity {
|
||||
iconIgnorePlacement(true),
|
||||
iconAllowOverlap(true)
|
||||
);
|
||||
mapboxMap.addLayerBelow(symbolLayer, RANDOM_CAR_LAYER);
|
||||
style.addLayerBelow(symbolLayer, RANDOM_CAR_LAYER);
|
||||
}
|
||||
|
||||
private void addMainCar() {
|
||||
@@ -308,10 +311,10 @@ public class AnimatedSymbolLayerActivity extends AppCompatActivity {
|
||||
FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[] {feature});
|
||||
|
||||
taxi = new Car(feature, passenger, getDuration());
|
||||
mapboxMap.addImage(TAXI,
|
||||
mapboxMap.getStyle().addImage(TAXI,
|
||||
((BitmapDrawable) getResources().getDrawable(R.drawable.ic_taxi_top)).getBitmap());
|
||||
taxiSource = new GeoJsonSource(TAXI_SOURCE, featureCollection);
|
||||
mapboxMap.addSource(taxiSource);
|
||||
style.addSource(taxiSource);
|
||||
|
||||
SymbolLayer symbolLayer = new SymbolLayer(TAXI_LAYER, TAXI_SOURCE);
|
||||
symbolLayer.withProperties(
|
||||
@@ -321,7 +324,7 @@ public class AnimatedSymbolLayerActivity extends AppCompatActivity {
|
||||
iconIgnorePlacement(true)
|
||||
|
||||
);
|
||||
mapboxMap.addLayer(symbolLayer);
|
||||
style.addLayer(symbolLayer);
|
||||
}
|
||||
|
||||
private LatLng getLatLngInBounds() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.CustomLayer;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.model.customlayer.ExampleCustomLayer;
|
||||
@@ -52,14 +53,15 @@ public class CustomLayerActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void swapCustomLayer() {
|
||||
Style style = mapboxMap.getStyle();
|
||||
if (customLayer != null) {
|
||||
mapboxMap.removeLayer(customLayer);
|
||||
style.removeLayer(customLayer);
|
||||
customLayer = null;
|
||||
fab.setImageResource(R.drawable.ic_layers);
|
||||
} else {
|
||||
customLayer = new CustomLayer("custom",
|
||||
ExampleCustomLayer.createContext());
|
||||
mapboxMap.addLayerBelow(customLayer, "building");
|
||||
style.addLayerBelow(customLayer, "building");
|
||||
fab.setImageResource(R.drawable.ic_layers_clear);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -47,10 +48,12 @@ public class QueryRenderedFeaturesBoxHighlightActivity extends AppCompatActivity
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
QueryRenderedFeaturesBoxHighlightActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
Style style = mapboxMap.getStyle();
|
||||
|
||||
// Add layer / source
|
||||
final GeoJsonSource source = new GeoJsonSource("highlighted-shapes-source");
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.addLayer(
|
||||
style.addSource(source);
|
||||
style.addLayer(
|
||||
new FillLayer("highlighted-shapes-layer", "highlighted-shapes-source")
|
||||
.withProperties(fillColor(Color.RED))
|
||||
);
|
||||
|
||||
@@ -47,18 +47,18 @@ public class QueryRenderedFeaturesBoxSymbolCountActivity extends AppCompatActivi
|
||||
|
||||
// Add a symbol layer (also works with annotations)
|
||||
try {
|
||||
mapboxMap.addSource(new GeoJsonSource("symbols-source", ResourceUtils.readRawResource(
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("symbols-source", ResourceUtils.readRawResource(
|
||||
QueryRenderedFeaturesBoxSymbolCountActivity.this, R.raw.test_points_utrecht)));
|
||||
} catch (IOException ioException) {
|
||||
Timber.e(ioException, "Could not load geojson");
|
||||
return;
|
||||
}
|
||||
mapboxMap.addImage(
|
||||
mapboxMap.getStyle().addImage(
|
||||
"test-icon",
|
||||
BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.mapbox_marker_icon_default)
|
||||
);
|
||||
mapboxMap.addLayer(new SymbolLayer("symbols-layer", "symbols-source").withProperties(iconImage("test-icon")));
|
||||
mapboxMap.getStyle().addLayer(new SymbolLayer("symbols-layer", "symbols-source").withProperties(iconImage("test-icon")));
|
||||
|
||||
selectionBox.setOnClickListener(view -> {
|
||||
// Query
|
||||
|
||||
@@ -48,14 +48,14 @@ public class QuerySourceFeaturesActivity extends AppCompatActivity {
|
||||
Feature.fromGeometry(Point.fromLngLat(17.3, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.4, 51), properties),
|
||||
}));
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
Expression visible = eq(get("key1"), literal("value1"));
|
||||
Expression invisible = neq(get("key1"), literal("value1"));
|
||||
|
||||
CircleLayer layer = new CircleLayer("test-layer", source.getId())
|
||||
.withFilter(visible);
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
// Add a click listener
|
||||
mapboxMap.addOnMapClickListener(point -> {
|
||||
|
||||
@@ -85,7 +85,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
if (mapboxMap != null) {
|
||||
setupNavigationView(mapboxMap.getLayers());
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -99,9 +99,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
setupNavigationView(mapboxMap.getLayers());
|
||||
|
||||
setupNavigationView(mapboxMap.getLayers());
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
setupZoomView();
|
||||
setFpsView();
|
||||
}
|
||||
|
||||
@@ -58,11 +58,11 @@ public class AnimatedImageSourceActivity extends AppCompatActivity implements On
|
||||
new LatLng(46.437, -71.516),
|
||||
new LatLng(37.936, -71.516),
|
||||
new LatLng(37.936, -80.425));
|
||||
mapboxMap.addSource(new ImageSource(ID_IMAGE_SOURCE, quad, R.drawable.southeast_radar_0));
|
||||
mapboxMap.getStyle().addSource(new ImageSource(ID_IMAGE_SOURCE, quad, R.drawable.southeast_radar_0));
|
||||
|
||||
// add layer
|
||||
RasterLayer layer = new RasterLayer(ID_IMAGE_LAYER, ID_IMAGE_SOURCE);
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
// loop refresh geojson
|
||||
handler = new Handler();
|
||||
@@ -137,7 +137,7 @@ public class AnimatedImageSourceActivity extends AppCompatActivity implements On
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
((ImageSource) mapboxMap.getSource(ID_IMAGE_SOURCE)).setImage(drawables[drawableIndex++]);
|
||||
((ImageSource) mapboxMap.getStyle().getSource(ID_IMAGE_SOURCE)).setImage(drawables[drawableIndex++]);
|
||||
if (drawableIndex > 3) {
|
||||
drawableIndex = 0;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.view.MenuItem;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Property;
|
||||
@@ -46,12 +47,13 @@ public class BuildingFillExtrusionActivity extends AppCompatActivity {
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
setupBuildings();
|
||||
Style style = map.getStyle();
|
||||
setupBuildings(style);
|
||||
setupLight();
|
||||
});
|
||||
}
|
||||
|
||||
private void setupBuildings() {
|
||||
private void setupBuildings(Style style) {
|
||||
FillExtrusionLayer fillExtrusionLayer = new FillExtrusionLayer("3d-buildings", "composite");
|
||||
fillExtrusionLayer.setSourceLayer("building");
|
||||
fillExtrusionLayer.setFilter(eq(get("extrude"), literal("true")));
|
||||
@@ -62,11 +64,11 @@ public class BuildingFillExtrusionActivity extends AppCompatActivity {
|
||||
fillExtrusionBase(Expression.get("min_height")),
|
||||
fillExtrusionOpacity(0.9f)
|
||||
);
|
||||
mapboxMap.addLayer(fillExtrusionLayer);
|
||||
style.addLayer(fillExtrusionLayer);
|
||||
}
|
||||
|
||||
private void setupLight() {
|
||||
light = mapboxMap.getLight();
|
||||
light = mapboxMap.getStyle().getLight();
|
||||
|
||||
findViewById(R.id.fabLightPosition).setOnClickListener(v -> {
|
||||
isInitPosition = !isInitPosition;
|
||||
|
||||
@@ -87,7 +87,7 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
} catch (MalformedURLException exception) {
|
||||
Timber.e(exception, "That's not an url... ");
|
||||
}
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
}
|
||||
|
||||
private void addBusStopCircleLayer() {
|
||||
@@ -96,7 +96,7 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
circleColor(Color.parseColor("#FF9800")),
|
||||
circleRadius(2.0f)
|
||||
);
|
||||
mapboxMap.addLayerBelow(layer, "waterway-label");
|
||||
mapboxMap.getStyle().addLayerBelow(layer, "waterway-label");
|
||||
}
|
||||
|
||||
private void initFloatingActionButtons() {
|
||||
@@ -128,13 +128,13 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
}
|
||||
|
||||
private void removeOldSource() {
|
||||
mapboxMap.removeSource(SOURCE_ID);
|
||||
mapboxMap.removeLayer(LAYER_ID);
|
||||
mapboxMap.getStyle().removeSource(SOURCE_ID);
|
||||
mapboxMap.getStyle().removeLayer(LAYER_ID);
|
||||
}
|
||||
|
||||
private void addClusteredSource() {
|
||||
try {
|
||||
mapboxMap.addSource(
|
||||
mapboxMap.getStyle().addSource(
|
||||
new GeoJsonSource(SOURCE_ID_CLUSTER,
|
||||
new URL(URL_BUS_ROUTES),
|
||||
new GeoJsonOptions()
|
||||
@@ -159,7 +159,7 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
iconImage("bus-15")
|
||||
);
|
||||
|
||||
mapboxMap.addLayer(unclustered);
|
||||
mapboxMap.getStyle().addLayer(unclustered);
|
||||
|
||||
for (int i = 0; i < layers.length; i++) {
|
||||
// Add some nice circles
|
||||
@@ -179,7 +179,7 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
lt(pointCount, literal(layers[i - 1][0]))
|
||||
)
|
||||
);
|
||||
mapboxMap.addLayer(circles);
|
||||
mapboxMap.getStyle().addLayer(circles);
|
||||
}
|
||||
|
||||
// Add the count labels
|
||||
@@ -191,7 +191,7 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
textIgnorePlacement(true),
|
||||
textAllowOverlap(true)
|
||||
);
|
||||
mapboxMap.addLayer(count);
|
||||
mapboxMap.getStyle().addLayer(count);
|
||||
}
|
||||
|
||||
private void removeFabs() {
|
||||
@@ -206,8 +206,8 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
}
|
||||
|
||||
private void removeBusStop() {
|
||||
mapboxMap.removeLayer(layer);
|
||||
mapboxMap.removeSource(source);
|
||||
mapboxMap.getStyle().removeLayer(layer);
|
||||
mapboxMap.getStyle().removeSource(source);
|
||||
}
|
||||
|
||||
private void loadNewStyle() {
|
||||
@@ -218,8 +218,8 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
}
|
||||
|
||||
private void addBusStop() {
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
}
|
||||
|
||||
private String getNextStyle() {
|
||||
|
||||
@@ -58,7 +58,7 @@ public class CustomSpriteActivity extends AppCompatActivity {
|
||||
if (point == null) {
|
||||
Timber.i("First click -> Car");
|
||||
// Add an icon to reference later
|
||||
mapboxMap.addImage(CUSTOM_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_car_top));
|
||||
mapboxMap.getStyle().addImage(CUSTOM_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_car_top));
|
||||
|
||||
// Add a source with a geojson point
|
||||
point = Point.fromLngLat(13.400972d, 52.519003d);
|
||||
@@ -66,7 +66,7 @@ public class CustomSpriteActivity extends AppCompatActivity {
|
||||
"point",
|
||||
FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry(point)})
|
||||
);
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
// Add a symbol layer that references that point source
|
||||
layer = new SymbolLayer("layer", "point");
|
||||
@@ -78,7 +78,7 @@ public class CustomSpriteActivity extends AppCompatActivity {
|
||||
);
|
||||
|
||||
// lets add a circle below labels!
|
||||
mapboxMap.addLayerBelow(layer, "waterway-label");
|
||||
mapboxMap.getStyle().addLayerBelow(layer, "waterway-label");
|
||||
|
||||
fab.setImageResource(R.drawable.ic_directions_car_black);
|
||||
} else {
|
||||
|
||||
@@ -167,7 +167,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
|
||||
private void addExponentialZoomFunction() {
|
||||
Timber.i("Add exponential zoom function");
|
||||
FillLayer layer = mapboxMap.getLayerAs("water");
|
||||
FillLayer layer = mapboxMap.getStyle().getLayerAs("water");
|
||||
assert layer != null;
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
@@ -185,7 +185,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
|
||||
private void addIntervalZoomFunction() {
|
||||
Timber.i("Add interval zoom function");
|
||||
FillLayer layer = mapboxMap.getLayerAs("water");
|
||||
FillLayer layer = mapboxMap.getStyle().getLayerAs("water");
|
||||
assert layer != null;
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
@@ -203,7 +203,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
|
||||
private void addExponentialSourceFunction() {
|
||||
Timber.i("Add exponential source function");
|
||||
FillLayer layer = mapboxMap.getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
FillLayer layer = mapboxMap.getStyle().getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
assert layer != null;
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
@@ -222,7 +222,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
|
||||
private void addCategoricalSourceFunction() {
|
||||
Timber.i("Add categorical source function");
|
||||
FillLayer layer = mapboxMap.getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
FillLayer layer = mapboxMap.getStyle().getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
assert layer != null;
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
@@ -241,7 +241,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
|
||||
private void addIdentitySourceFunction() {
|
||||
Timber.i("Add identity source function");
|
||||
FillLayer layer = mapboxMap.getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
FillLayer layer = mapboxMap.getStyle().getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
assert layer != null;
|
||||
layer.setProperties(
|
||||
fillOpacity(
|
||||
@@ -254,7 +254,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
|
||||
private void addIntervalSourceFunction() {
|
||||
Timber.i("Add interval source function");
|
||||
FillLayer layer = mapboxMap.getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
FillLayer layer = mapboxMap.getStyle().getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
assert layer != null;
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
@@ -273,7 +273,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
|
||||
private void addCompositeExponentialFunction() {
|
||||
Timber.i("Add composite exponential function");
|
||||
FillLayer layer = mapboxMap.getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
FillLayer layer = mapboxMap.getStyle().getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
assert layer != null;
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
@@ -310,7 +310,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
|
||||
private void addCompositeIntervalFunction() {
|
||||
Timber.i("Add composite interval function");
|
||||
FillLayer layer = mapboxMap.getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
FillLayer layer = mapboxMap.getStyle().getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
assert layer != null;
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
@@ -347,7 +347,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
|
||||
private void addCompositeCategoricalFunction() {
|
||||
Timber.i("Add composite categorical function");
|
||||
FillLayer layer = mapboxMap.getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
FillLayer layer = mapboxMap.getStyle().getLayerAs(AMSTERDAM_PARKS_LAYER);
|
||||
assert layer != null;
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
@@ -448,7 +448,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
Source source;
|
||||
try {
|
||||
source = new GeoJsonSource("amsterdam-parks-source", ResourceUtils.readRawResource(this, R.raw.amsterdam));
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
} catch (IOException ioException) {
|
||||
Toast.makeText(
|
||||
DataDrivenStyleActivity.this,
|
||||
@@ -458,7 +458,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
// Add a fill layer
|
||||
mapboxMap.addLayer(new FillLayer(AMSTERDAM_PARKS_LAYER, source.getId())
|
||||
mapboxMap.getStyle().addLayer(new FillLayer(AMSTERDAM_PARKS_LAYER, source.getId())
|
||||
.withProperties(
|
||||
fillColor(color(Color.GREEN)),
|
||||
fillOutlineColor(rgb(0, 0, 255)),
|
||||
|
||||
@@ -67,10 +67,12 @@ class DraggableMarkerActivity : AppCompatActivity() {
|
||||
mapView.getMapAsync { mapboxMap ->
|
||||
this.mapboxMap = mapboxMap
|
||||
|
||||
val style = mapboxMap.style
|
||||
|
||||
// Setting up markers icon, source and layer
|
||||
mapboxMap.addImage(markerImageId, IconFactory.getInstance(this).defaultMarker().bitmap)
|
||||
mapboxMap.addSource(source)
|
||||
mapboxMap.addLayer(layer)
|
||||
mapboxMap.getStyle().addImage(markerImageId, IconFactory.getInstance(this).defaultMarker().bitmap)
|
||||
style.addSource(source)
|
||||
style.addLayer(layer)
|
||||
|
||||
// Add initial markers
|
||||
addMarker(LatLng(52.407210, 16.924324))
|
||||
|
||||
@@ -52,9 +52,9 @@ public class FillExtrusionActivity extends AppCompatActivity {
|
||||
Polygon domTower = Polygon.fromLngLats(lngLats);
|
||||
|
||||
GeoJsonSource source = new GeoJsonSource("extrusion-source", domTower);
|
||||
map.addSource(source);
|
||||
map.getStyle().addSource(source);
|
||||
|
||||
mapboxMap.addLayer(
|
||||
mapboxMap.getStyle().addLayer(
|
||||
new FillExtrusionLayer("extrusion-layer", source.getId())
|
||||
.withProperties(
|
||||
fillExtrusionHeight(40f),
|
||||
|
||||
@@ -59,14 +59,14 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_geojson_clustering);
|
||||
|
||||
// Initialize map as normal
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
// noinspection ConstantConditions
|
||||
mapView.onCreate(savedInstanceState);
|
||||
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.7749, 122.4194), 0));
|
||||
mapboxMap.addImage(
|
||||
mapboxMap.getStyle().addImage(
|
||||
"icon-id",
|
||||
BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.ic_hearing_black_24dp)),
|
||||
true
|
||||
@@ -132,7 +132,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
private void addClusteredGeoJsonSource() {
|
||||
// Add a clustered source
|
||||
try {
|
||||
mapboxMap.addSource(
|
||||
mapboxMap.getStyle().addSource(
|
||||
new GeoJsonSource("earthquakes",
|
||||
new URL("https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"),
|
||||
new GeoJsonOptions()
|
||||
@@ -169,7 +169,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
)
|
||||
);
|
||||
unclustered.setFilter(has("mag"));
|
||||
mapboxMap.addLayer(unclustered);
|
||||
mapboxMap.getStyle().addLayer(unclustered);
|
||||
|
||||
for (int i = 0; i < layers.length; i++) {
|
||||
// Add some nice circles
|
||||
@@ -189,7 +189,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
lt(pointCount, literal(layers[i - 1][0]))
|
||||
)
|
||||
);
|
||||
mapboxMap.addLayer(circles);
|
||||
mapboxMap.getStyle().addLayer(circles);
|
||||
}
|
||||
|
||||
// Add the count labels
|
||||
@@ -201,7 +201,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
textIgnorePlacement(true),
|
||||
textAllowOverlap(true)
|
||||
);
|
||||
mapboxMap.addLayer(count);
|
||||
mapboxMap.getStyle().addLayer(count);
|
||||
|
||||
|
||||
// Zoom out to start
|
||||
|
||||
@@ -54,8 +54,8 @@ public class GradientLineActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
try {
|
||||
String geoJson = ResourceUtils.readRawResource(GradientLineActivity.this, R.raw.test_line_gradient_feature);
|
||||
mapboxMap.addSource(new GeoJsonSource(LINE_SOURCE, geoJson, new GeoJsonOptions().withLineMetrics(true)));
|
||||
mapboxMap.addLayer(new LineLayer("gradient", LINE_SOURCE)
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource(LINE_SOURCE, geoJson, new GeoJsonOptions().withLineMetrics(true)));
|
||||
mapboxMap.getStyle().addLayer(new LineLayer("gradient", LINE_SOURCE)
|
||||
.withProperties(
|
||||
lineGradient(interpolate(
|
||||
linear(), lineProgress(),
|
||||
|
||||
@@ -106,7 +106,7 @@ public class GridSourceActivity extends AppCompatActivity implements OnMapReadyC
|
||||
|
||||
// add source
|
||||
source = new CustomGeometrySource(ID_GRID_SOURCE, new GridProvider());
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
// add layer
|
||||
layer = new LineLayer(ID_GRID_LAYER, ID_GRID_SOURCE);
|
||||
@@ -114,7 +114,7 @@ public class GridSourceActivity extends AppCompatActivity implements OnMapReadyC
|
||||
lineColor(Color.parseColor("#000000"))
|
||||
);
|
||||
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,7 +65,7 @@ public class HeatmapLayerActivity extends AppCompatActivity {
|
||||
|
||||
private void addEarthquakeSource() {
|
||||
try {
|
||||
mapboxMap.addSource(new GeoJsonSource(EARTHQUAKE_SOURCE_ID, new URL(EARTHQUAKE_SOURCE_URL)));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource(EARTHQUAKE_SOURCE_ID, new URL(EARTHQUAKE_SOURCE_URL)));
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
Timber.e(malformedUrlException, "That's not an url... ");
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class HeatmapLayerActivity extends AppCompatActivity {
|
||||
)
|
||||
);
|
||||
|
||||
mapboxMap.addLayerAbove(layer, "waterway-label");
|
||||
mapboxMap.getStyle().addLayerAbove(layer, "waterway-label");
|
||||
}
|
||||
|
||||
private void addCircleLayer() {
|
||||
@@ -179,7 +179,7 @@ public class HeatmapLayerActivity extends AppCompatActivity {
|
||||
circleStrokeWidth(1.0f)
|
||||
);
|
||||
|
||||
mapboxMap.addLayerBelow(circleLayer, HEATMAP_LAYER_ID);
|
||||
mapboxMap.getStyle().addLayerBelow(circleLayer, HEATMAP_LAYER_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,10 +33,10 @@ public class HillshadeLayerActivity extends AppCompatActivity {
|
||||
mapboxMap = map;
|
||||
|
||||
RasterDemSource rasterDemSource = new RasterDemSource(SOURCE_ID, SOURCE_URL);
|
||||
mapboxMap.addSource(rasterDemSource);
|
||||
mapboxMap.getStyle().addSource(rasterDemSource);
|
||||
|
||||
HillshadeLayer hillshadeLayer = new HillshadeLayer(LAYER_ID, SOURCE_ID);
|
||||
mapboxMap.addLayerBelow(hillshadeLayer, LAYER_BELOW_ID);
|
||||
mapboxMap.getStyle().addLayerBelow(hillshadeLayer, LAYER_BELOW_ID);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class RealTimeGeoJsonActivity extends AppCompatActivity implements OnMapR
|
||||
|
||||
// add source
|
||||
try {
|
||||
mapboxMap.addSource(new GeoJsonSource(ID_GEOJSON_SOURCE, new URL(URL_GEOJSON_SOURCE)));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource(ID_GEOJSON_SOURCE, new URL(URL_GEOJSON_SOURCE)));
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
Timber.e(malformedUrlException, "Invalid URL");
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class RealTimeGeoJsonActivity extends AppCompatActivity implements OnMapR
|
||||
// add layer
|
||||
SymbolLayer layer = new SymbolLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE);
|
||||
layer.setProperties(iconImage("rocket-15"));
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
// loop refresh geojson
|
||||
handler = new Handler();
|
||||
@@ -118,7 +118,7 @@ public class RealTimeGeoJsonActivity extends AppCompatActivity implements OnMapR
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
((GeoJsonSource) mapboxMap.getSource(ID_GEOJSON_SOURCE)).setUrl(URL_GEOJSON_SOURCE);
|
||||
((GeoJsonSource) mapboxMap.getStyle().getSource(ID_GEOJSON_SOURCE)).setUrl(URL_GEOJSON_SOURCE);
|
||||
handler.postDelayed(this, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void listLayers() {
|
||||
List<Layer> layers = mapboxMap.getLayers();
|
||||
List<Layer> layers = mapboxMap.getStyle().getLayers();
|
||||
StringBuilder builder = new StringBuilder("Layers:");
|
||||
for (Layer layer : layers) {
|
||||
builder.append("\n");
|
||||
@@ -216,7 +216,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void listSources() {
|
||||
List<Source> sources = mapboxMap.getSources();
|
||||
List<Source> sources = mapboxMap.getStyle().getSources();
|
||||
StringBuilder builder = new StringBuilder("Sources:");
|
||||
for (Source source : sources) {
|
||||
builder.append("\n");
|
||||
@@ -228,7 +228,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
private void setLayerInvisible() {
|
||||
String[] roadLayers = new String[] {"water"};
|
||||
for (String roadLayer : roadLayers) {
|
||||
Layer layer = mapboxMap.getLayer(roadLayer);
|
||||
Layer layer = mapboxMap.getStyle().getLayer(roadLayer);
|
||||
if (layer != null) {
|
||||
layer.setProperties(visibility(NONE));
|
||||
}
|
||||
@@ -242,7 +242,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
public void onFinish() {
|
||||
String[] roadLayers = new String[] {"road-label-small", "road-label-medium", "road-label-large"};
|
||||
for (String roadLayer : roadLayers) {
|
||||
Layer layer = mapboxMap.getLayer(roadLayer);
|
||||
Layer layer = mapboxMap.getStyle().getLayer(roadLayer);
|
||||
if (layer != null) {
|
||||
layer.setProperties(symbolPlacement(SYMBOL_PLACEMENT_POINT));
|
||||
}
|
||||
@@ -252,14 +252,14 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void setBackgroundOpacity() {
|
||||
Layer background = mapboxMap.getLayer("background");
|
||||
Layer background = mapboxMap.getStyle().getLayer("background");
|
||||
if (background != null) {
|
||||
background.setProperties(backgroundOpacity(0.2f));
|
||||
}
|
||||
}
|
||||
|
||||
private void setWaterColor() {
|
||||
FillLayer water = mapboxMap.getLayerAs("water");
|
||||
FillLayer water = mapboxMap.getStyle().getLayerAs("water");
|
||||
if (water != null) {
|
||||
water.setFillColorTransition(new TransitionOptions(7500, 1000));
|
||||
water.setProperties(
|
||||
@@ -273,7 +273,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
|
||||
private void removeBuildings() {
|
||||
// Zoom to see buildings first
|
||||
mapboxMap.removeLayer("building");
|
||||
mapboxMap.getStyle().removeLayer("building");
|
||||
}
|
||||
|
||||
private void addParksLayer() {
|
||||
@@ -289,7 +289,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
FillLayer layer = new FillLayer("parksLayer", "amsterdam-spots");
|
||||
layer.setProperties(
|
||||
@@ -302,14 +302,14 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
// Only show me parks (except westerpark with stroke-width == 3)
|
||||
layer.setFilter(all(eq(get("type"), literal("park")), eq(get("stroke-width"), literal(3))));
|
||||
|
||||
mapboxMap.addLayerBelow(layer, "building");
|
||||
mapboxMap.getStyle().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.
|
||||
mapboxMap.getLayer("parksLayer").setProperties(fillColor(Color.RED));
|
||||
mapboxMap.getStyle().getLayer("parksLayer").setProperties(fillColor(Color.RED));
|
||||
|
||||
// You can get a typed layer, if you're sure it's of that type. Use with care
|
||||
layer = mapboxMap.getLayerAs("parksLayer");
|
||||
layer = mapboxMap.getStyle().getLayerAs("parksLayer");
|
||||
// And get some properties
|
||||
PropertyValue<Boolean> fillAntialias = layer.getFillAntialias();
|
||||
Timber.d("Fill anti alias: %s", fillAntialias.getValue());
|
||||
@@ -339,7 +339,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
// Add an empty source
|
||||
mapboxMap.addSource(new GeoJsonSource("dynamic-park-source"));
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("dynamic-park-source"));
|
||||
|
||||
FillLayer layer = new FillLayer("dynamic-parks-layer", "dynamic-park-source");
|
||||
layer.setProperties(
|
||||
@@ -352,7 +352,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
// Only show me parks
|
||||
layer.setFilter(all(eq(get("type"), literal("park"))));
|
||||
|
||||
mapboxMap.addLayer(layer);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
// Get a good look at it all
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(12));
|
||||
@@ -372,7 +372,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
// change the source
|
||||
int park = counter < parks.features().size() - 1 ? counter : 0;
|
||||
|
||||
GeoJsonSource source = mapboxMap.getSourceAs("dynamic-park-source");
|
||||
GeoJsonSource source = mapboxMap.getStyle().getSourceAs("dynamic-park-source");
|
||||
|
||||
if (source == null) {
|
||||
Timber.e("Source not found");
|
||||
@@ -392,7 +392,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
private void addTerrainLayer() {
|
||||
// Add a source
|
||||
Source source = new VectorSource("my-terrain-source", "mapbox://mapbox.mapbox-terrain-v2");
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
LineLayer layer = new LineLayer("terrainLayer", "my-terrain-source");
|
||||
layer.setSourceLayer("contour");
|
||||
@@ -404,7 +404,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
);
|
||||
|
||||
// adding layers below "road" layers
|
||||
List<Layer> layers = mapboxMap.getLayers();
|
||||
List<Layer> layers = mapboxMap.getStyle().getLayers();
|
||||
Layer latestLayer = null;
|
||||
Collections.reverse(layers);
|
||||
for (Layer currentLayer : layers) {
|
||||
@@ -420,17 +420,17 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
if (latestLayer != null) {
|
||||
mapboxMap.addLayerBelow(layer, latestLayer.getId());
|
||||
mapboxMap.getStyle().addLayerBelow(layer, latestLayer.getId());
|
||||
}
|
||||
|
||||
// Need to get a fresh handle
|
||||
layer = mapboxMap.getLayerAs("terrainLayer");
|
||||
layer = mapboxMap.getStyle().getLayerAs("terrainLayer");
|
||||
|
||||
// Make sure it's also applied after the fact
|
||||
layer.setMinZoom(10);
|
||||
layer.setMaxZoom(15);
|
||||
|
||||
layer = (LineLayer) mapboxMap.getLayer("terrainLayer");
|
||||
layer = (LineLayer) mapboxMap.getStyle().getLayer("terrainLayer");
|
||||
Toast.makeText(this, String.format(
|
||||
"Set min/max zoom to %s - %s", layer.getMinZoom(), layer.getMaxZoom()), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@@ -438,14 +438,14 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
private void addSatelliteLayer() {
|
||||
// Add a source
|
||||
Source source = new RasterSource("my-raster-source", "mapbox://mapbox.satellite", 512);
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
// Add a layer
|
||||
mapboxMap.addLayer(new RasterLayer("satellite-layer", "my-raster-source"));
|
||||
mapboxMap.getStyle().addLayer(new RasterLayer("satellite-layer", "my-raster-source"));
|
||||
}
|
||||
|
||||
private void updateWaterColorOnZoom() {
|
||||
FillLayer layer = mapboxMap.getLayerAs("water");
|
||||
FillLayer layer = mapboxMap.getStyle().getLayerAs("water");
|
||||
if (layer == null) {
|
||||
return;
|
||||
}
|
||||
@@ -474,7 +474,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
tileSet.setMinZoom(0);
|
||||
tileSet.setMaxZoom(14);
|
||||
Source source = new VectorSource("custom-tile-source", tileSet);
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
// Add a layer
|
||||
LineLayer lineLayer = new LineLayer("custom-tile-layers", "custom-tile-source");
|
||||
@@ -486,7 +486,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
lineWidth(2.0f),
|
||||
lineColor(Color.GREEN)
|
||||
);
|
||||
mapboxMap.addLayer(lineLayer);
|
||||
mapboxMap.getStyle().addLayer(lineLayer);
|
||||
}
|
||||
|
||||
private void styleFillFilterLayer() {
|
||||
@@ -501,7 +501,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
|
||||
Timber.d("Styling filtered fill layer");
|
||||
|
||||
FillLayer states = (FillLayer) mapboxMap.getLayer("states");
|
||||
FillLayer states = (FillLayer) mapboxMap.getStyle().getLayer("states");
|
||||
|
||||
if (states != null) {
|
||||
states.setFilter(eq(get("name"), literal("Texas")));
|
||||
@@ -529,7 +529,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
|
||||
Timber.d("Styling filtered line layer");
|
||||
|
||||
LineLayer counties = (LineLayer) mapboxMap.getLayer("counties");
|
||||
LineLayer counties = (LineLayer) mapboxMap.getStyle().getLayer("counties");
|
||||
|
||||
if (counties != null) {
|
||||
counties.setFilter(eq(get("NAME10"), "Washington"));
|
||||
@@ -557,7 +557,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
|
||||
Timber.d("Styling numeric fill layer");
|
||||
|
||||
FillLayer regions = (FillLayer) mapboxMap.getLayer("regions");
|
||||
FillLayer regions = (FillLayer) mapboxMap.getStyle().getLayer("regions");
|
||||
|
||||
if (regions != null) {
|
||||
regions.setFilter(all(
|
||||
@@ -576,10 +576,10 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void bringWaterToFront() {
|
||||
Layer water = mapboxMap.getLayer("water");
|
||||
Layer water = mapboxMap.getStyle().getLayer("water");
|
||||
if (water != null) {
|
||||
mapboxMap.removeLayer(water);
|
||||
mapboxMap.addLayerAt(water, mapboxMap.getLayers().size() - 1);
|
||||
mapboxMap.getStyle().removeLayer(water);
|
||||
mapboxMap.getStyle().addLayerAt(water, mapboxMap.getStyle().getLayers().size() - 1);
|
||||
} else {
|
||||
Toast.makeText(this, "No water layer in this style", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class RuntimeStyleTimingTestActivity extends AppCompatActivity {
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
RuntimeStyleTimingTestActivity.this.mapboxMap = mapboxMap;
|
||||
VectorSource museums = new VectorSource("museums_source", "mapbox://mapbox.2opop9hr");
|
||||
mapboxMap.addSource(museums);
|
||||
mapboxMap.getStyle().addSource(museums);
|
||||
|
||||
CircleLayer museumsLayer = new CircleLayer("museums", "museums_source");
|
||||
museumsLayer.setSourceLayer("museum-cusco");
|
||||
@@ -44,7 +44,7 @@ public class RuntimeStyleTimingTestActivity extends AppCompatActivity {
|
||||
circleColor(Color.argb(1, 55, 148, 179))
|
||||
);
|
||||
|
||||
mapboxMap.addLayer(museumsLayer);
|
||||
mapboxMap.getStyle().addLayer(museumsLayer);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -119,11 +119,11 @@ public class SymbolGeneratorActivity extends AppCompatActivity implements OnMapR
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.menu_action_icon_overlap) {
|
||||
SymbolLayer layer = mapboxMap.getLayerAs(LAYER_ID);
|
||||
SymbolLayer layer = mapboxMap.getStyle().getLayerAs(LAYER_ID);
|
||||
layer.setProperties(iconAllowOverlap(!layer.getIconAllowOverlap().getValue()));
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.menu_action_filter) {
|
||||
SymbolLayer layer = mapboxMap.getLayerAs(LAYER_ID);
|
||||
SymbolLayer layer = mapboxMap.getStyle().getLayerAs(LAYER_ID);
|
||||
layer.setFilter(eq(get(FEATURE_RANK), literal(1)));
|
||||
Timber.e("Filter that was set: %s", layer.getFilter());
|
||||
return true;
|
||||
@@ -286,10 +286,10 @@ public class SymbolGeneratorActivity extends AppCompatActivity implements OnMapR
|
||||
|
||||
// add a geojson source to the map
|
||||
Source source = new GeoJsonSource(SOURCE_ID, featureCollection);
|
||||
mapboxMap.addSource(source);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
// add symbol layer
|
||||
mapboxMap.addLayer(symbolLayer);
|
||||
mapboxMap.getStyle().addLayer(symbolLayer);
|
||||
|
||||
// get expressions
|
||||
Expression iconImageExpressionResult = symbolLayer.getIconImage().getExpression();
|
||||
@@ -350,7 +350,7 @@ public class SymbolGeneratorActivity extends AppCompatActivity implements OnMapR
|
||||
@Override
|
||||
protected void onPostExecute(HashMap<String, Bitmap> bitmapHashMap) {
|
||||
super.onPostExecute(bitmapHashMap);
|
||||
mapboxMap.addImages(bitmapHashMap);
|
||||
mapboxMap.getStyle().addImages(bitmapHashMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
// Add a sdf image for the makers
|
||||
Drawable icLayersDrawable = getResources().getDrawable(R.drawable.ic_layers);
|
||||
Bitmap icLayersBitmap = BitmapUtils.getBitmapFromDrawable(icLayersDrawable);
|
||||
mapboxMap.addImage(
|
||||
mapboxMap.getStyle().addImage(
|
||||
MARKER_ICON,
|
||||
icLayersBitmap,
|
||||
true
|
||||
@@ -112,10 +112,10 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
Feature.fromGeometry(Point.fromLngLat(4.91638, 52.35673), featureProperties("Marker 1")),
|
||||
Feature.fromGeometry(Point.fromLngLat(4.91638, 52.34673), featureProperties("Marker 2"))
|
||||
});
|
||||
mapboxMap.addSource(geoJsonSource = new GeoJsonSource(MARKER_SOURCE, markerCollection));
|
||||
mapboxMap.getStyle().addSource(geoJsonSource = new GeoJsonSource(MARKER_SOURCE, markerCollection));
|
||||
|
||||
// Add the symbol-layer
|
||||
mapboxMap.addLayer(
|
||||
mapboxMap.getStyle().addLayer(
|
||||
new SymbolLayer(MARKER_LAYER, MARKER_SOURCE)
|
||||
.withProperties(
|
||||
iconImage(MARKER_ICON),
|
||||
@@ -167,17 +167,17 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
}
|
||||
|
||||
private void toggleTextSize() {
|
||||
SymbolLayer layer = mapboxMap.getLayerAs(MARKER_LAYER);
|
||||
SymbolLayer layer = mapboxMap.getStyle().getLayerAs(MARKER_LAYER);
|
||||
layer.setProperties(layer.getTextSize().getValue() > 10 ? textSize(10f) : textSize(20f));
|
||||
}
|
||||
|
||||
private void toggleTextField() {
|
||||
SymbolLayer layer = mapboxMap.getLayerAs(MARKER_LAYER);
|
||||
SymbolLayer layer = mapboxMap.getStyle().getLayerAs(MARKER_LAYER);
|
||||
layer.setProperties("{title}".equals(layer.getTextField().getValue()) ? textField("āA") : textField("{title}"));
|
||||
}
|
||||
|
||||
private void toggleTextFont() {
|
||||
SymbolLayer layer = mapboxMap.getLayerAs(MARKER_LAYER);
|
||||
SymbolLayer layer = mapboxMap.getStyle().getLayerAs(MARKER_LAYER);
|
||||
if (initialFont) {
|
||||
layer.setProperties(textFont(new String[] {"DIN Offc Pro Bold", "Arial Unicode MS Bold"}));
|
||||
} else {
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.Property;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -62,7 +63,7 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
|
||||
Feature feature = featureList.get(0);
|
||||
boolean selectedNow = feature.getBooleanProperty(KEY_PROPERTY_SELECTED);
|
||||
isSelected = !selectedNow;
|
||||
updateSource();
|
||||
updateSource(mapboxMap.getStyle());
|
||||
} else {
|
||||
Timber.e("No features found");
|
||||
}
|
||||
@@ -79,19 +80,20 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
updateSource();
|
||||
addLayer();
|
||||
Style style = map.getStyle();
|
||||
updateSource(style);
|
||||
addLayer(style);
|
||||
map.addOnMapClickListener(mapClickListener);
|
||||
});
|
||||
}
|
||||
|
||||
private void updateSource() {
|
||||
private void updateSource(Style style) {
|
||||
FeatureCollection featureCollection = createFeatureCollection();
|
||||
if (source != null) {
|
||||
source.setGeoJson(featureCollection);
|
||||
} else {
|
||||
source = new GeoJsonSource(SOURCE_ID, featureCollection);
|
||||
mapboxMap.addSource(source);
|
||||
style.addSource(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +115,7 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
|
||||
return FeatureCollection.fromFeatures(new Feature[] {feature});
|
||||
}
|
||||
|
||||
private void addLayer() {
|
||||
private void addLayer(Style style) {
|
||||
layer = new SymbolLayer(LAYER_ID, SOURCE_ID);
|
||||
layer.setProperties(
|
||||
iconImage(
|
||||
@@ -129,7 +131,7 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
|
||||
),
|
||||
iconAllowOverlap(true)
|
||||
);
|
||||
mapboxMap.addLayer(layer);
|
||||
style.addLayer(layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -143,7 +145,7 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
|
||||
if (mapboxMap != null) {
|
||||
if (item.getItemId() == R.id.menu_action_change_location) {
|
||||
isInitialPosition = !isInitialPosition;
|
||||
updateSource();
|
||||
updateSource(mapboxMap.getStyle());
|
||||
} else if (item.getItemId() == R.id.menu_action_toggle_source) {
|
||||
toggleSymbolLayerVisibility();
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
|
||||
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
if (mapboxMap != null) {
|
||||
setupNavigationView(mapboxMap.getLayers());
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -100,7 +100,7 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
setupNavigationView(mapboxMap.getLayers());
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
setupZoomView();
|
||||
setFpsView();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user