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
Source File: ProgramEventDetailActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 File: NavigationMapRoute.java    From graphhopper-navigation-android with 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 File: NavigationMapRoute.java    From graphhopper-navigation-android with 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 File: PolygonContainer.java    From AirMapSDK-Android with 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 #5
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with 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 #6
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with 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 #7
Source File: CircleContainer.java    From AirMapSDK-Android with 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 #8
Source File: AirMapFillLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getFillPattern(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.fillPattern(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.fillPattern((String) pv.getValue());
    }
    return null;
}
 
Example #9
Source File: AirMapSymbolLayerStyle.java    From AirMapSDK-Android with 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 #10
Source File: AirMapFillLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getFillTranslateAnchor(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.fillTranslateAnchor(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.fillTranslateAnchor((String) pv.getValue());
    }
    return null;
}
 
Example #11
Source File: AirMapFillLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getFillTranslate(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.fillTranslate(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.fillTranslate((Float[]) pv.getValue());
    }
    return null;
}
 
Example #12
Source File: AirMapFillLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getFillOutlineColor(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.fillOutlineColor(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.fillOutlineColor(pv.getColorInt());
    }
    return null;
}
 
Example #13
Source File: AirMapFillLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getFillAntialias(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.fillAntialias(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.fillAntialias((Boolean) pv.getValue());
    }
    return null;
}
 
Example #14
Source File: AirMapFillLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getFillOpacity(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.fillOpacity(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.fillOpacity((Float) pv.getValue());
    }
    return null;
}
 
Example #15
Source File: AirMapFillLayerStyle.java    From AirMapSDK-Android with 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;
}
 
Example #16
Source File: AirMapSymbolLayerStyle.java    From AirMapSDK-Android with 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 #17
Source File: SearchTEActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #18
Source File: AirMapLineLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getLineColor(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.lineColor(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.lineColor(pv.getColorInt());
    }
    return null;
}
 
Example #19
Source File: AirMapLineLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getLineOpacity(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.lineOpacity(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.lineOpacity((Float) pv.getValue());
    }
    return null;
}
 
Example #20
Source File: AirMapLineLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getLineWidth(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.lineWidth(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.lineWidth((Float) pv.getValue());
    }
    return null;
}
 
Example #21
Source File: AirMapLineLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getLineGapWidth(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.lineGapWidth(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.lineGapWidth((Float) pv.getValue());
    }
    return null;
}
 
Example #22
Source File: AirMapLineLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getLineTranslate(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.lineTranslate(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.lineTranslate((Float[]) pv.getValue());
    }
    return null;
}
 
Example #23
Source File: AirMapLineLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getLineTranslateAnchor(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.lineTranslateAnchor(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.lineTranslateAnchor((String) pv.getValue());
    }
    return null;
}
 
Example #24
Source File: AirMapLineLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getLineDashArray(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.lineDasharray(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.lineDasharray((Float[]) pv.getValue());
    }
    return null;
}
 
Example #25
Source File: AirMapLineLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private PropertyValue getLinePattern(PropertyValue pv) {
    if (pv.isExpression()) {
        return PropertyFactory.linePattern(pv.getExpression());
    } else if (pv.isValue()) {
        return PropertyFactory.linePattern((String) pv.getValue());
    }
    return null;
}
 
Example #26
Source File: MapStyleController.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onDidFinishLoadingStyle() {
    // Adjust the background overlay opacity to improve map visually on Android
    BackgroundLayer backgroundLayer = map.getMap().getStyle().getLayerAs("background-overlay");
    if (backgroundLayer != null) {
        if (currentTheme == MappingService.AirMapMapTheme.Light || currentTheme == MappingService.AirMapMapTheme.Standard) {
            backgroundLayer.setProperties(PropertyFactory.backgroundOpacity(0.95f));
        } else if (currentTheme == MappingService.AirMapMapTheme.Dark) {
            backgroundLayer.setProperties(PropertyFactory.backgroundOpacity(0.9f));
        }
    }

    try {
        mapStyle = new MapStyle(map.getMap().getStyle().getJson());
    } catch (JSONException e) {
        Timber.e(e, "Failed to parse style json");
    }

    // change labels to local if device is not in english
    if (!Locale.ENGLISH.getLanguage().equals(Locale.getDefault().getLanguage())) {
        for (Layer layer : map.getMap().getStyle().getLayers()) {
            if (layer instanceof SymbolLayer && (layer.getId().contains("label") || layer.getId().contains("place") || layer.getId().contains("poi"))) {
                //layer.setProperties(PropertyFactory.textField("{name}"));
                // TODO: 2020-01-15 Need to do more investigation as to why removing this line fixes map labelling issue. 
            }
        }
    }

    callback.onMapStyleLoaded();
}
 
Example #27
Source File: AirMapSymbolLayerStyle.java    From AirMapSDK-Android with 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 #28
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with 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 #29
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with 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 #30
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with 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);
    }
  }
}