com.mapbox.mapboxsdk.style.layers.PropertyFactory Java Examples

The following examples show how to use com.mapbox.mapboxsdk.style.layers.PropertyFactory. 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: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 6 votes vote down vote up
private LineLayer createArrowShaftLayer() {
  LineLayer shaftLayer = (LineLayer) mapboxMap.getLayer(ARROW_SHAFT_LINE_LAYER_ID);
  if (shaftLayer != null) {
    return shaftLayer;
  }
  return new LineLayer(ARROW_SHAFT_LINE_LAYER_ID, ARROW_SHAFT_SOURCE_ID).withProperties(
    PropertyFactory.lineColor(color(arrowColor)),
    PropertyFactory.lineWidth(
      interpolate(linear(), zoom(),
        stop(MIN_ARROW_ZOOM, MIN_ZOOM_ARROW_SHAFT_SCALE),
        stop(MAX_ARROW_ZOOM, MAX_ZOOM_ARROW_SHAFT_SCALE)
      )
    ),
    PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
    PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
    PropertyFactory.visibility(NONE),
    PropertyFactory.lineOpacity(
      step(zoom(), OPAQUE,
        stop(
          ARROW_HIDDEN_ZOOM_LEVEL, TRANSPARENT
        )
      )
    )
  );
}
 
Example #3
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 6 votes vote down vote up
private LineLayer createArrowShaftCasingLayer() {
  LineLayer shaftCasingLayer = (LineLayer) mapboxMap.getLayer(ARROW_SHAFT_CASING_LINE_LAYER_ID);
  if (shaftCasingLayer != null) {
    return shaftCasingLayer;
  }
  return new LineLayer(ARROW_SHAFT_CASING_LINE_LAYER_ID, ARROW_SHAFT_SOURCE_ID).withProperties(
    PropertyFactory.lineColor(color(arrowBorderColor)),
    PropertyFactory.lineWidth(
      interpolate(linear(), zoom(),
        stop(MIN_ARROW_ZOOM, MIN_ZOOM_ARROW_SHAFT_CASING_SCALE),
        stop(MAX_ARROW_ZOOM, MAX_ZOOM_ARROW_SHAFT_CASING_SCALE)
      )
    ),
    PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
    PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
    PropertyFactory.visibility(NONE),
    PropertyFactory.lineOpacity(
      step(zoom(), OPAQUE,
        stop(
          ARROW_HIDDEN_ZOOM_LEVEL, TRANSPARENT
        )
      )
    )
  );
}
 
Example #4
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 6 votes vote down vote up
/**
 * When the user switches an alternative route to a primary route, this method alters the
 * appearance.
 */
private void updatePrimaryRoute(String layerId, int index) {
  Layer layer = mapboxMap.getLayer(layerId);
  if (layer != null) {
    layer.setProperties(
      PropertyFactory.lineColor(match(
        Expression.toString(get(CONGESTION_KEY)),
        color(index == primaryRouteIndex ? routeDefaultColor : alternativeRouteDefaultColor),
        stop("moderate", color(index == primaryRouteIndex ? routeModerateColor : alternativeRouteModerateColor)),
        stop("heavy", color(index == primaryRouteIndex ? routeSevereColor : alternativeRouteSevereColor)),
        stop("severe", color(index == primaryRouteIndex ? routeSevereColor : alternativeRouteSevereColor))
        )
      )
    );
    if (index == primaryRouteIndex) {
      mapboxMap.removeLayer(layer);
      mapboxMap.addLayerBelow(layer, WAYPOINT_LAYER_ID);
    }
  }
}
 
Example #5
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 6 votes vote down vote up
/**
 * Add the route shield layer to the map either using the custom style values or the default.
 */
private void addRouteShieldLayer(String layerId, String sourceId, int index) {
  float scale = index == primaryRouteIndex ? routeScale : alternativeRouteScale;
  Layer routeLayer = new LineLayer(layerId, sourceId).withProperties(
    PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
    PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
    PropertyFactory.lineWidth(interpolate(
      exponential(1.5f), zoom(),
      stop(10f, 7f),
      stop(14f, 10.5f * scale),
      stop(16.5f, 15.5f * scale),
      stop(19f, 24f * scale),
      stop(22f, 29f * scale)
      )
    ),
    PropertyFactory.lineColor(
      index == primaryRouteIndex ? routeShieldColor : alternativeRouteShieldColor)
  );
  MapUtils.addLayerToMap(mapboxMap, routeLayer, belowLayer);
}
 
Example #6
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 #7
Source Project: AirMapSDK-Android   Author: airmap   File: PolygonContainer.java    License: Apache License 2.0 6 votes vote down vote up
public boolean checkForIntersections() {
    List<LatLng> points = PointMath.findIntersections(path);
    if (points.isEmpty()) {
        return false;
    }

    List<Point> intersections = latLngsToPositions(points);
    if (map.getStyle().getLayer(INTERSECTION_LAYER) == null) {
        Source intersectionSource = new GeoJsonSource(INTERSECTION_SOURCE, Feature.fromGeometry(MultiPoint.fromLngLats(intersections)));
        map.getStyle().addSource(intersectionSource);
        Layer intersectionLayer = new SymbolLayer(INTERSECTION_LAYER, INTERSECTION_SOURCE)
                .withProperties(PropertyFactory.iconImage(INTERSECTION_IMAGE));
        map.getStyle().addLayer(intersectionLayer);
    } else {
        GeoJsonSource intersectionsSource = map.getStyle().getSourceAs(INTERSECTION_SOURCE);
        intersectionsSource.setGeoJson(Feature.fromGeometry(MultiPoint.fromLngLats(intersections)));
    }

    return true;
}
 
Example #8
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 #9
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
private SymbolLayer createArrowHeadLayer() {
  SymbolLayer headLayer = (SymbolLayer) mapboxMap.getLayer(ARROW_HEAD_LAYER_ID);
  if (headLayer != null) {
    return headLayer;
  }
  return new SymbolLayer(ARROW_HEAD_LAYER_ID, ARROW_HEAD_SOURCE_ID)
    .withProperties(
      PropertyFactory.iconImage(ARROW_HEAD_ICON),
      iconAllowOverlap(true),
      iconIgnorePlacement(true),
      PropertyFactory.iconSize(interpolate(linear(), zoom(),
        stop(MIN_ARROW_ZOOM, MIN_ZOOM_ARROW_HEAD_SCALE),
        stop(MAX_ARROW_ZOOM, MAX_ZOOM_ARROW_HEAD_SCALE)
        )
      ),
      PropertyFactory.iconOffset(ARROW_HEAD_OFFSET),
      PropertyFactory.iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP),
      PropertyFactory.iconRotate(get(ARROW_BEARING)),
      PropertyFactory.visibility(NONE),
      PropertyFactory.iconOpacity(
        step(zoom(), OPAQUE,
          stop(
            ARROW_HIDDEN_ZOOM_LEVEL, TRANSPARENT
          )
        )
      )
    );
}
 
Example #10
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
private SymbolLayer createArrowHeadCasingLayer() {
  SymbolLayer headCasingLayer = (SymbolLayer) mapboxMap.getLayer(ARROW_HEAD_CASING_LAYER_ID);
  if (headCasingLayer != null) {
    return headCasingLayer;
  }
  return new SymbolLayer(ARROW_HEAD_CASING_LAYER_ID, ARROW_HEAD_SOURCE_ID).withProperties(
    PropertyFactory.iconImage(ARROW_HEAD_ICON_CASING),
    iconAllowOverlap(true),
    iconIgnorePlacement(true),
    PropertyFactory.iconSize(interpolate(
      linear(), zoom(),
      stop(MIN_ARROW_ZOOM, MIN_ZOOM_ARROW_HEAD_CASING_SCALE),
      stop(MAX_ARROW_ZOOM, MAX_ZOOM_ARROW_HEAD_CASING_SCALE)
    )),
    PropertyFactory.iconOffset(ARROW_HEAD_CASING_OFFSET),
    PropertyFactory.iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP),
    PropertyFactory.iconRotate(get(ARROW_BEARING)),
    PropertyFactory.visibility(NONE),
    PropertyFactory.iconOpacity(
      step(zoom(), OPAQUE,
        stop(
          ARROW_HIDDEN_ZOOM_LEVEL, TRANSPARENT
        )
      )
    )
  );
}
 
Example #11
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
private void updatePrimaryShieldRoute(String layerId, int index) {
  Layer layer = mapboxMap.getLayer(layerId);
  if (layer != null) {
    layer.setProperties(
      PropertyFactory.lineColor(index == primaryRouteIndex ? routeShieldColor : alternativeRouteShieldColor)
    );
    if (index == primaryRouteIndex) {
      mapboxMap.removeLayer(layer);
      mapboxMap.addLayerBelow(layer, WAYPOINT_LAYER_ID);
    }
  }
}
 
Example #12
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
/**
 * Add the route layer to the map either using the custom style values or the default.
 */
private void addRouteLayer(String layerId, String sourceId, int index) {
  float scale = index == primaryRouteIndex ? routeScale : alternativeRouteScale;
  Layer routeLayer = new LineLayer(layerId, sourceId).withProperties(
    PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
    PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
    PropertyFactory.lineWidth(interpolate(
      exponential(1.5f), zoom(),
      stop(4f, 3f * scale),
      stop(10f, 4f * scale),
      stop(13f, 6f * scale),
      stop(16f, 10f * scale),
      stop(19f, 14f * scale),
      stop(22f, 18f * scale)
      )
    ),
    PropertyFactory.lineColor(match(
      Expression.toString(get(CONGESTION_KEY)),
      color(index == primaryRouteIndex ? routeDefaultColor : alternativeRouteDefaultColor),
      stop("moderate", color(index == primaryRouteIndex ? routeModerateColor : alternativeRouteModerateColor)),
      stop("heavy", color(index == primaryRouteIndex ? routeSevereColor : alternativeRouteSevereColor)),
      stop("severe", color(index == primaryRouteIndex ? routeSevereColor : alternativeRouteSevereColor))
      )
    )
  );
  MapUtils.addLayerToMap(mapboxMap, routeLayer, belowLayer);
}
 
Example #13
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
private void drawWaypointMarkers(@NonNull MapboxMap mapboxMap, @Nullable Drawable originMarker,
                                 @Nullable Drawable destinationMarker) {
  if (originMarker == null || destinationMarker == null) {
    return;
  }

  SymbolLayer waypointLayer = mapboxMap.getLayerAs(WAYPOINT_LAYER_ID);
  if (waypointLayer == null) {
    Bitmap bitmap = MapImageUtils.getBitmapFromDrawable(originMarker);
    mapboxMap.addImage("originMarker", bitmap);
    bitmap = MapImageUtils.getBitmapFromDrawable(destinationMarker);
    mapboxMap.addImage("destinationMarker", bitmap);

    waypointLayer = new SymbolLayer(WAYPOINT_LAYER_ID, WAYPOINT_SOURCE_ID).withProperties(
      PropertyFactory.iconImage(match(
        Expression.toString(get("waypoint")), literal("originMarker"),
        stop("origin", literal("originMarker")),
        stop("destination", literal("destinationMarker"))
        )
      ),
      PropertyFactory.iconSize(interpolate(
        exponential(1.5f), zoom(),
        stop(22f, 2.8f),
        stop(12f, 1.3f),
        stop(10f, 0.8f),
        stop(0f, 0.6f)
      )),
      PropertyFactory.iconPitchAlignment(Property.ANCHOR_MAP),
      PropertyFactory.iconAllowOverlap(true),
      PropertyFactory.iconIgnorePlacement(true)
    );
    layerIds.add(WAYPOINT_LAYER_ID);
    MapUtils.addLayerToMap(mapboxMap, waypointLayer, belowLayer);
  }
}
 
Example #14
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getSymbolPlacement(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.symbolPlacement(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.symbolPlacement((String) pv.getValue());
    }
    return null;
}
 
Example #15
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getSymbolSpacing(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.symbolSpacing(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.symbolSpacing((Float) pv.getValue());
    }
    return null;
}
 
Example #16
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getIconAllowOverlap(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.iconAllowOverlap(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.iconAllowOverlap((Boolean) pv.getValue());
    }
    return null;
}
 
Example #17
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getIconKeepUpright(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.iconKeepUpright(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.iconKeepUpright((Boolean) pv.getValue());
    }
    return null;
}
 
Example #18
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getIconImage(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.iconImage(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.iconImage((String) pv.getValue());
    }
    return null;
}
 
Example #19
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getAvoidEdges(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.symbolAvoidEdges(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.symbolAvoidEdges((Boolean) pv.getValue());
    }
    return null;
}
 
Example #20
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getIconPadding(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.iconPadding(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.iconPadding((Float) pv.getValue());
    }
    return null;
}
 
Example #21
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getIconSize(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.iconSize(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.iconSize((Float) pv.getValue());
    }
    return null;
}
 
Example #22
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getIconOpacity(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.iconOpacity(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.iconOpacity((Float) pv.getValue());
    }
    return null;
}
 
Example #23
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getIconOffset(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.iconOffset(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.iconOffset((Float[]) pv.getValue());
    }
    return null;
}
 
Example #24
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getTextField(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.textField(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.textField((String) pv.getValue());
    }
    return null;
}
 
Example #25
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getTextFont(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.textFont(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.textFont((String[]) pv.getValue());
    }
    return null;
}
 
Example #26
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getTextOffset(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.textOffset(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.textOffset((Float[]) pv.getValue());
    }
    return null;
}
 
Example #27
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getTextColor(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.textColor(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.textColor(pv.getColorInt());
    }
    return null;
}
 
Example #28
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getTextPadding(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.textPadding(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.textPadding((Float) pv.getValue());
    }
    return null;
}
 
Example #29
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapSymbolLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getTextOpacity(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.textOpacity(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.textOpacity((Float) pv.getValue());
    }
    return null;
}
 
Example #30
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapFillLayerStyle.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyValue getFillColor(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.fillColor(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.fillColor(pv.getColorInt());
    }
    return null;
}