Java Code Examples for com.mapbox.mapboxsdk.style.layers.LineLayer#setProperties()

The following examples show how to use com.mapbox.mapboxsdk.style.layers.LineLayer#setProperties() . 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
Source File: TrafficPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
static LineLayer getLineLayer(String lineLayerId, float minZoom, Expression filter,
                              Expression lineColorExpression, Expression lineWidthExpression,
                              Expression lineOffsetExpression, Expression lineOpacityExpression) {
  LineLayer lineLayer = new LineLayer(lineLayerId, TrafficData.SOURCE_ID);
  lineLayer.setSourceLayer(TrafficData.SOURCE_LAYER);
  lineLayer.setProperties(
    lineCap(Property.LINE_CAP_ROUND),
    lineJoin(Property.LINE_JOIN_ROUND),
    lineColor(lineColorExpression),
    lineWidth(lineWidthExpression),
    lineOffset(lineOffsetExpression)
  );
  if (lineOpacityExpression != null) {
    lineLayer.setProperties(lineOpacity(lineOpacityExpression));
  }

  lineLayer.setFilter(filter);
  lineLayer.setMinZoom(minZoom);
  return lineLayer;
}
 
Example 2
Source File: AirMapLineLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 4 votes vote down vote up
@Override
public LineLayer toMapboxLayer(Layer layerToClone, String sourceId) {
    LineLayer lineLayer = new LineLayer(id + "|" + sourceId + "|new", sourceId);
    lineLayer.setSourceLayer(sourceId + "_" + sourceLayer);

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

    PropertyValue lineColor = getLineColor(layer.getLineColor());
    if (lineColor != null) {
        properties.add(lineColor);
    }

    PropertyValue lineOpacity = getLineOpacity(layer.getLineOpacity());
    if (lineOpacity != null) {
        properties.add(lineOpacity);
    }

    PropertyValue lineWidth = getLineWidth(layer.getLineWidth());
    if (lineWidth != null) {
        properties.add(lineWidth);
    }

    PropertyValue lineGapWidth = getLineGapWidth(layer.getLineGapWidth());
    if (lineGapWidth != null) {
        properties.add(lineGapWidth);
    }

    PropertyValue lineTranslate = getLineTranslate(layer.getLineTranslate());
    if (lineTranslate != null) {
        properties.add(lineTranslate);
    }

    PropertyValue lineTranslateAnchor = getLineTranslateAnchor(layer.getLineTranslateAnchor());
    if (lineTranslateAnchor != null) {
        properties.add(lineTranslateAnchor);
    }

    PropertyValue lineDashArray = getLineDashArray(layer.getLineDasharray());
    if (lineDashArray != null) {
        properties.add(lineDashArray);
    }

    PropertyValue linePattern = getLinePattern(layer.getLinePattern());
    if (linePattern != null) {
        properties.add(linePattern);
    }

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

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

    return lineLayer;
}
 
Example 3
Source File: MapStyleController.java    From AirMapSDK-Android with Apache License 2.0 4 votes vote down vote up
public void addMapLayers(AirMapRuleset ruleset, boolean useSIMeasurements) {
    String sourceId = ruleset.getId();
    List<String> layers = ruleset.getLayers();
    // check if source is already added to map
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    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;
        }
    }

    if (map.getMap().getStyle().getSource(sourceId) != null) {
        Timber.e("Source already added for: %s", sourceId);
    } else {
        String urlTemplates;
        if(temporalFilter == null){
            urlTemplates = AirMap.getRulesetTileUrlTemplate(sourceId, layers, useSIMeasurements);
        } else {
            urlTemplates = AirMap.getRulesetTileUrlTemplate(sourceId, layers, useSIMeasurements, cal1.getTime(), cal2.getTime());
        }
        TileSet tileSet = new TileSet(tileJsonSpecVersion, urlTemplates);
        tileSet.setMaxZoom(12f);
        tileSet.setMinZoom(8f);
        VectorSource tileSource = new VectorSource(sourceId, tileSet);
        map.getMap().getStyle().addSource(tileSource);
    }

    for (String sourceLayer : layers) {
        for (AirMapLayerStyle layerStyle : mapStyle.getLayerStyles(sourceLayer)) {
            // check if layer is already added to map
            if (map.getMap().getStyle().getLayer(layerStyle.id + "|" + sourceId + "|new") != null) {
                continue;
            }

            // use layer from styles as a template
            Layer layerToClone = map.getMap().getStyle().getLayer(layerStyle.id);

            Layer layer = layerStyle.toMapboxLayer(layerToClone, sourceId);

            // add temporal filter if applicable
            if (layer.getId().contains("airmap|tfr") || layer.getId().contains("notam")) {
                addTemporalFilter(layer);
            }

            if (airspaceTypeListener != null) {
                String typeKey = layerStyle.id.split("\\|")[1];
                AirMapAirspaceType airspaceType = MappingService.AirMapAirspaceType.fromString(typeKey);
                airspaceTypeListener.onAirspaceTypeAdded(ruleset, airspaceType, layer);
            }
            map.getMap().getStyle().addLayerAbove(layer, layerStyle.id);
        }
    }

    // add highlight layer
    if (map.getMap().getStyle().getLayer("airmap|highlight|line|" + sourceId) == null) {
        LineLayer highlightLayer = new LineLayer("airmap|highlight|line|" + sourceId, sourceId);
        highlightLayer.setProperties(PropertyFactory.lineColor("#f9e547"));
        highlightLayer.setProperties(PropertyFactory.lineWidth(4f));
        highlightLayer.setProperties(PropertyFactory.lineOpacity(0.9f));
        Expression filter = Expression.eq(Expression.get("id"), "x");

        try {
            highlightLayer.setFilter(filter);
            map.getMap().getStyle().addLayer(highlightLayer);
        } catch (Throwable t) {
            // https://github.com/mapbox/mapbox-gl-native/issues/10947
            // https://github.com/mapbox/mapbox-gl-native/issues/11264
            // A layer is associated with a style, not the mapView/mapbox
            Analytics.report(new Exception(t));
            t.printStackTrace();
        }
    }
}
 
Example 4
Source File: MapDataManager.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
private void showLineLayer(MapSource source) {
    LineLayer lineLayer = (LineLayer) mapboxStyle.getLayer(source.getLineLayer());
    if (lineLayer != null) {
        lineLayer.setProperties(visibility(showTraces ? VISIBLE : NONE));
    }
}