[android] - move all layer, source, image, light and transition configurations to style.java

This commit is contained in:
Tobrun
2018-11-08 13:39:26 +01:00
committed by Tobrun
parent 1374535e63
commit d68dfe0551
53 changed files with 536 additions and 538 deletions

View File

@@ -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() {

View File

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

View File

@@ -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))
);

View File

@@ -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

View File

@@ -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 -> {

View File

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

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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 {

View File

@@ -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)),

View File

@@ -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))

View File

@@ -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),

View File

@@ -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

View File

@@ -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(),

View File

@@ -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

View File

@@ -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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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 {

View File

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

View File

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