Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Polygon hole layer below null check #1145

Merged
merged 1 commit into from
Jul 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.graphics.Color;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.mapbox.geojson.Feature;
import com.mapbox.geojson.LineString;
Expand All @@ -19,23 +17,25 @@
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.style.layers.FillLayer;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import static com.mapbox.mapboxandroiddemo.examples.dds.PolygonHolesActivity.Config.BLUE_COLOR;
import static com.mapbox.mapboxandroiddemo.examples.dds.PolygonHolesActivity.Config.HOLE_COORDINATES;
import static com.mapbox.mapboxandroiddemo.examples.dds.PolygonHolesActivity.Config.POLYGON_COORDINATES;
import static com.mapbox.mapboxandroiddemo.examples.dds.PolygonHolesActivity.Config.RED_COLOR;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor;

/**
* Add holes to a polygon drawn on top of the map.
*/
public class PolygonHolesActivity extends AppCompatActivity implements OnMapReadyCallback {
private MapView mapView;
private MapboxMap mapboxMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -48,7 +48,9 @@ protected void onCreate(Bundle savedInstanceState) {
// Configure initial map state
MapboxMapOptions mapboxMapOptions = MapboxMapOptions.createFromAttributes(this, null);
mapboxMapOptions
.camera(new CameraPosition.Builder().zoom(13).target(new LatLng(25.255377, 55.3089185))
.camera(new CameraPosition.Builder()
.zoom(13)
.target(new LatLng(25.255377, 55.3089185))
.build())
.attributionTintColor(RED_COLOR)
.compassFadesWhenFacingNorth(true);
Expand All @@ -62,7 +64,6 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
public void onMapReady(final MapboxMap map) {
this.mapboxMap = map;
map.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
Expand All @@ -78,9 +79,14 @@ public void onStyleLoaded(@NonNull Style style) {
style.addSource(new GeoJsonSource("source-id",
Feature.fromGeometry(Polygon.fromOuterInner(outerLineString, innerList))));

style.addLayerBelow(new FillLayer("layer-id", "source-id").withProperties(
PropertyFactory.fillColor(BLUE_COLOR)
), "road-number-shield");
FillLayer polygonFillLayer = new FillLayer("layer-id", "source-id")
.withProperties(fillColor(BLUE_COLOR));

if (style.getLayer("road-number-shield") != null) {
style.addLayerBelow(polygonFillLayer, "road-number-shield");
} else {
style.addLayer(polygonFillLayer);
}
}
});
}
Expand Down