Java Code Examples for com.mapbox.mapboxsdk.style.layers.FillLayer

The following examples show how to use com.mapbox.mapboxsdk.style.layers.FillLayer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
private void setLayer(Style style) {
    SymbolLayer symbolLayer = new SymbolLayer("POINT_LAYER", "events").withProperties(
            PropertyFactory.iconImage("ICON_ID"),
            iconAllowOverlap(true),
            iconOffset(new Float[]{0f, -9f})
    );
    symbolLayer.setMinZoom(0);
    style.addLayer(symbolLayer);

    if (featureType != FeatureType.POINT)
        style.addLayerBelow(new FillLayer("POLYGON_LAYER", "events").withProperties(
                fillColor(
                        ColorUtils.getPrimaryColorWithAlpha(this, ColorUtils.ColorType.PRIMARY_LIGHT, 150f)
                )
                ), "settlement-label"
        );
}
 
Example #2
Source Project: AirMapSDK-Android   Author: airmap   File: CircleContainer.java    License: Apache License 2.0 6 votes vote down vote up
public void move(LatLng center) {
    this.center = center;
    this.points = calculateCirclePoints(center, radius);

    List<Point> positions = latLngsToPositions(points);
    List<List<Point>> coordinates = new ArrayList<>();
    coordinates.add(positions);

    List<Point> lineString = new ArrayList<>(positions);
    lineString.add(positions.get(0));

    GeoJsonSource pointSource = map.getStyle().getSourceAs(POINT_SOURCE);
    pointSource.setGeoJson(Feature.fromGeometry(Point.fromLngLat(center.getLongitude(), center.getLatitude())));

    GeoJsonSource polygonSource = map.getStyle().getSourceAs(POLYGON_SOURCE);
    polygonSource.setGeoJson(Feature.fromGeometry(Polygon.fromLngLats(coordinates)));

    FillLayer polygonFill = map.getStyle().getLayerAs(Container.POLYGON_LAYER);
    polygonFill.setProperties(PropertyFactory.fillColor(ContextCompat.getColor(context, R.color.colorAccent)));

    GeoJsonSource polylineSource = map.getStyle().getSourceAs(POLYLINE_SOURCE);
    polylineSource.setGeoJson(Feature.fromGeometry(LineString.fromLngLats(lineString)));
}
 
Example #3
private void setLayer(Style style) {

        SymbolLayer symbolLayer = new SymbolLayer("POINT_LAYER", "teis").withProperties(
                PropertyFactory.iconImage(get("teiImage")),
                iconOffset(new Float[]{0f, -25f}),
                iconAllowOverlap(true),
                textAllowOverlap(true)
        );

        symbolLayer.setFilter(eq(literal("$type"), literal("Point")));

        style.addLayer(symbolLayer);

        if (featureType != FeatureType.POINT) {
            style.addLayerBelow(new FillLayer("POLYGON_LAYER", "teis")
                            .withProperties(
                                    fillColor(
                                            ColorUtils.getPrimaryColorWithAlpha(this, ColorUtils.ColorType.PRIMARY_LIGHT, 150f)
                                    ))
                            .withFilter(eq(literal("$type"), literal("Polygon"))),
                    "POINT_LAYER"
            );
            style.addLayerAbove(new LineLayer("POLYGON_BORDER_LAYER", "teis")
                            .withProperties(
                                    lineColor(
                                            ColorUtils.getPrimaryColor(this, ColorUtils.ColorType.PRIMARY_DARK)
                                    ),
                                    lineWidth(2f))
                            .withFilter(eq(literal("$type"), literal("Polygon"))),
                    "POLYGON_LAYER"

            );
        }
    }
 
Example #4
Source Project: AirMapSDK-Android   Author: airmap   File: MapStyleController.java    License: Apache License 2.0 5 votes vote down vote up
private void setupJurisdictionsForEnterprise() {
    // Reload the style after setup is complete
    if (map == null || map.getMap() == null || map.getMap().getStyle() == null) {
        return;
    }

    OfflineManager.getInstance(map.getContext()).clearAmbientCache(null);

    Style style = map.getMap().getStyle();
    String jurisdictionsId = "jurisdictions";

    if (style.getLayer(jurisdictionsId) != null) {
        style.removeLayer(jurisdictionsId);
    }

    if (style.getSource(jurisdictionsId) != null) {
        style.removeSource(jurisdictionsId);
    }

    TileSet tileSet = new TileSet(tileJsonSpecVersion, AirMap.getBaseJurisdictionsUrlTemplate());
    tileSet.setMaxZoom(12f);
    tileSet.setMinZoom(8f);
    Source source = new VectorSource(jurisdictionsId, tileSet);
    style.addSource(source);
    Layer layer = new FillLayer(jurisdictionsId, jurisdictionsId)
            .withSourceLayer(jurisdictionsId)
            .withProperties(fillColor(TRANSPARENT), fillOpacity(1f));
    style.addLayerAt(layer, 0);
}
 
Example #5
Source Project: AirMapSDK-Android   Author: airmap   File: MapStyleController.java    License: Apache License 2.0 5 votes vote down vote up
public void hideInactiveAirspace(){
    Expression hasActive = Expression.has("active");
    Expression activeIsTrue = Expression.eq(Expression.get("active"), true);
    Expression active = Expression.all(hasActive, activeIsTrue);
    map.getMap().getStyle(style -> {
        for(Layer layer : Objects.requireNonNull(style.getLayers())){
            if(layer.getId().contains("airmap")){
                if(layer instanceof FillLayer){
                    if(((FillLayer) layer).getFilter() != null){
                        ((FillLayer) layer).setFilter(Expression.any(((FillLayer) layer).getFilter(), active));
                    } else {
                        ((FillLayer) layer).setFilter(active);
                    }

                } else if (layer instanceof  LineLayer){
                    if(((LineLayer) layer).getFilter() != null){
                        ((LineLayer) layer).setFilter(Expression.any(((LineLayer) layer).getFilter(), active));
                    } else {
                        ((LineLayer) layer).setFilter(active);
                    }

                } else if(layer instanceof  SymbolLayer){
                    if(((SymbolLayer) layer).getFilter() != null){
                        ((SymbolLayer) layer).setFilter(Expression.any(((SymbolLayer) layer).getFilter(), active));
                    } else {
                        ((SymbolLayer) layer).setFilter(active);
                    }

                } else {
                    Timber.e("Unknown layer");

                }
            }
        }
    });
}
 
Example #6
Source Project: mapbox-plugins-android   Author: mapbox   File: FillManager.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
FillManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @NonNull CoreElementProvider<FillLayer> coreElementProvider, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions, DraggableAnnotationController<Fill, OnFillDragListener> draggableAnnotationController) {
  super(mapView, mapboxMap, style, coreElementProvider, draggableAnnotationController, belowLayerId, geoJsonOptions);
}
 
Example #7
Source Project: mapbox-plugins-android   Author: mapbox   File: FillElementProvider.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public FillLayer getLayer() {
  return new FillLayer(layerId, sourceId);
}
 
Example #8
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapFillLayerStyle.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public FillLayer toMapboxLayer(Layer layerToClone, String sourceId) {
    FillLayer fillLayer = new FillLayer(id + "|" + sourceId + "|new", sourceId);
    fillLayer.setSourceLayer(sourceId + "_" + sourceLayer);

    FillLayer layer = (FillLayer) layerToClone;
    List<PropertyValue> properties = new ArrayList<>();

    PropertyValue fillColor = getFillColor(layer.getFillColor());
    if (fillColor != null) {
        properties.add(fillColor);
    }

    PropertyValue fillOpacity = getFillOpacity(layer.getFillOpacity());
    if (fillOpacity != null) {
        properties.add(fillOpacity);
    }

    PropertyValue fillAntialias = getFillAntialias(layer.getFillAntialias());
    if (fillAntialias != null) {
        properties.add(fillAntialias);
    }

    PropertyValue fillOutlineColor = getFillOutlineColor(layer.getFillOutlineColor());
    if (fillOutlineColor != null) {
        properties.add(fillOutlineColor);
    }

    PropertyValue fillTranslate = getFillTranslate(layer.getFillTranslate());
    if (fillTranslate != null) {
        properties.add(fillTranslate);
    }

    PropertyValue fillTranslateAnchor = getFillTranslateAnchor(layer.getFillTranslateAnchor());
    if (fillTranslateAnchor != null) {
        properties.add(fillTranslateAnchor);
    }

    PropertyValue fillPattern = getFillPattern(layer.getFillPattern());
    if (fillPattern != null) {
        properties.add(fillPattern);
    }

    // set all properties
    fillLayer.setProperties(properties.toArray(new PropertyValue[properties.size()]));

    if (layer.getFilter() != null) {
        fillLayer.setFilter(layer.getFilter());
    }

    return fillLayer;
}
 
Example #9
Source Project: AirMapSDK-Android   Author: airmap   File: MapStyleController.java    License: Apache License 2.0 4 votes vote down vote up
private void addTemporalFilter(Layer layer) {
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();

    long start = System.currentTimeMillis() / 1000;
    long end = start + (4 * 60 * 60);

    if(temporalFilter != null){
        switch (temporalFilter.getType()){
            case NOW:
                switch (temporalFilter.getRange()){

                    case ONE_HOUR:
                        cal2.roll(Calendar.HOUR_OF_DAY, 1);
                        break;
                    case FOUR_HOUR:
                        cal2.roll(Calendar.HOUR_OF_DAY, 4);
                        break;
                    case EIGHT_HOUR:
                        cal2.roll(Calendar.HOUR_OF_DAY, 8);
                        break;
                    case TWELVE_HOUR:
                        cal2.roll(Calendar.HOUR_OF_DAY, 12);
                        break;
                }
                break;
            case CUSTOM:
                cal1.setTime(temporalFilter.getFutureDate());
                cal2.setTime(temporalFilter.getFutureDate());

                cal1.set(Calendar.HOUR_OF_DAY, temporalFilter.getStartHour());
                cal1.set(Calendar.MINUTE, temporalFilter.getStartMinute());

                cal2.set(Calendar.HOUR_OF_DAY, temporalFilter.getEndHour());
                cal2.set(Calendar.MINUTE, temporalFilter.getEndMinute());
                break;
        }

        start = cal1.getTime().getTime() / 1000;
        end = cal2.getTime().getTime() / 1000;
    }

    Expression validNowFilter = Expression.all(Expression.lt(Expression.get("start"), start), Expression.gt(Expression.get("end"), start));
    Expression startsSoonFilter = Expression.all(Expression.gt(Expression.get("start"), start), Expression.lt(Expression.get("start"), end));
    Expression permanent = Expression.all(Expression.has("permanent"), Expression.eq(Expression.get("permanent"), "true"));
    Expression hasNoEnd = Expression.all(Expression.not(Expression.has("end")), Expression.not(Expression.has("base")));
    Expression filter = Expression.any(permanent, hasNoEnd, validNowFilter, startsSoonFilter);

    if (layer instanceof FillLayer) {
        ((FillLayer) layer).setFilter(filter);
    } else if (layer instanceof LineLayer) {
        ((LineLayer) layer).setFilter(filter);
    }
}