com.mapbox.mapboxsdk.style.expressions.Expression Java Examples

The following examples show how to use com.mapbox.mapboxsdk.style.expressions.Expression. 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: 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 #2
Source File: MapDataManager.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
private void initLastPositionLayer() {
    GeoJsonSource lastPositionSource = new GeoJsonSource(LAST_POSITION_SOURCE);
    mapboxStyle.addSource(lastPositionSource);
    Expression markerSize =
            switchCase(toBool(get(MARKER_SELECTED)), literal(1.75f), literal(1.25f));
    mapboxStyle.addLayerBelow(new SymbolLayer(LAST_POSITION_LAYER, LAST_POSITION_SOURCE).withProperties(
            iconImage(get(LAST_POSITION_ICON)),
                 /* all info window and marker image to appear at the same time*/
            iconAllowOverlap(true),
            iconIgnorePlacement(true),
            iconSize(markerSize),
            textField(get(LAST_POSITION_LABEL)),
            textAnchor(TEXT_ANCHOR_TOP),
            textOffset(new Float[]{0.0f, 1.0f}),
            textAllowOverlap(true),
            textIgnorePlacement(true)
    ).withFilter(filterProvider.getTimeFilter()), INFO_WINDOW_LAYER);
}
 
Example #3
Source File: LocalizationPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void convertExpression(@NonNull MapLocale mapLocale, Layer layer,
                               PropertyValue<?> textFieldProperty, boolean isStreetsV7) {
  Expression textFieldExpression = textFieldProperty.getExpression();
  if (textFieldExpression != null) {
    MapLocale newMapLocale = mapLocale;
    String mapLanguage = mapLocale.getMapLanguage();
    if (mapLanguage.startsWith("name_zh")) {
      // need to re-get mapLocale, since the default is for street-v8
      newMapLocale = getChineseMapLocale(mapLocale, isStreetsV7);
      Timber.d("reset mapLocale to: %s", newMapLocale.getMapLanguage());
    }

    String text = textFieldExpression.toString().replaceAll(EXPRESSION_REGEX, newMapLocale.getMapLanguage());
    if (text.startsWith("[\"step") && textFieldExpression.toArray().length % 2 == 0) {
      // got an invalid step expression from core, we need to add an additional name_x into step
      text = text.replaceAll(STEP_REGEX, STEP_TEMPLATE);
    }
    layer.setProperties(textField(raw(text)));
  }
}
 
Example #4
Source File: LocalizationPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void convertExpressionV8(@NonNull MapLocale mapLocale, Layer layer, PropertyValue<?> textFieldProperty) {
  Expression textFieldExpression = textFieldProperty.getExpression();
  if (textFieldExpression != null) {
    String stringExpression =
      textFieldExpression.toString().replaceAll(EXPRESSION_V8_REGEX_LOCALIZED, EXPRESSION_V8_TEMPLATE_BASE);

    String mapLanguage = mapLocale.getMapLanguage();
    if (!mapLanguage.equals(MapLocale.ENGLISH)) {
      if (mapLanguage.equals("name_zh")) {
        mapLanguage = MapLocale.SIMPLIFIED_CHINESE;
      }
      stringExpression = stringExpression.replaceAll(EXPRESSION_V8_REGEX_BASE,
        String.format(Locale.US,
          EXPRESSION_V8_TEMPLATE_LOCALIZED,
          mapLanguage,
          mapLanguage));
    }
    layer.setProperties(textField(raw(stringExpression)));
  }
}
 
Example #5
Source File: MapStyleController.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
public void highlight(Feature feature) {
    String id = feature.getStringProperty("id");
    String type = feature.getStringProperty("category");

    // remove old highlight
    unhighlight();

    // add new highlight
    String sourceId = feature.getStringProperty("ruleset_id");
    highlightLayerId = "airmap|highlight|line|" + sourceId;
    LineLayer highlightLayer = map.getMap().getStyle().getLayerAs(highlightLayerId);
    highlightLayer.setSourceLayer(sourceId + "_" + type);

    // feature's airspace_id can be an int or string (tile server bug), so match on either
    Expression filter;
    try {
        int airspaceId = Integer.parseInt(id);
        filter = Expression.any(Expression.eq(Expression.get("id"), id), Expression.eq(Expression.get("id"), airspaceId));
    } catch (NumberFormatException e) {
        filter = Expression.any(Expression.eq(Expression.get("id"), id));
    }
    highlightLayer.setFilter(filter);
}
 
Example #6
Source File: MapStyleController.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
public void highlight(@NonNull Feature feature, AirMapAdvisory advisory) {
    // remove old highlight
    unhighlight();

    // add new highlight
    String sourceId = feature.getStringProperty("ruleset_id");
    highlightLayerId = "airmap|highlight|line|" + sourceId;
    LineLayer highlightLayer = map.getMap().getStyle().getLayerAs(highlightLayerId);
    highlightLayer.setSourceLayer(sourceId + "_" + advisory.getType().toString());

    // feature's airspace_id can be an int or string (tile server bug), so match on either
    Expression filter;
    try {
        int airspaceId = Integer.parseInt(advisory.getId());
        filter = Expression.any(Expression.eq(Expression.get("id"), advisory.getId()), Expression.eq(Expression.get("id"), airspaceId));
    } catch (NumberFormatException e) {
        filter = Expression.any(Expression.eq(Expression.get("id"), advisory.getId()));
    }
    highlightLayer.setFilter(filter);
}
 
Example #7
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 #8
Source File: SymbolManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testInitialization() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(style).addSource(geoJsonSource);
  verify(style).addLayer(symbolLayer);
  assertTrue(symbolManager.dataDrivenPropertyUsageMap.size() > 0);
  for (Boolean value : symbolManager.dataDrivenPropertyUsageMap.values()) {
    assertFalse(value);
  }
  verify(symbolLayer).setProperties(symbolManager.constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
  verify(symbolLayer, times(0)).setFilter(any(Expression.class));
  verify(draggableAnnotationController).onSourceUpdated();
  verify(geoJsonSource).setGeoJson(any(FeatureCollection.class));
}
 
Example #9
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with 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 #10
Source File: SymbolManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testGeoJsonOptionsInitialization() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, geoJsonOptions, draggableAnnotationController);
  verify(style).addSource(optionedGeoJsonSource);
  verify(style).addLayer(symbolLayer);
  assertTrue(symbolManager.dataDrivenPropertyUsageMap.size() > 0);
  for (Boolean value : symbolManager.dataDrivenPropertyUsageMap.values()) {
    assertFalse(value);
  }
  verify(symbolLayer).setProperties(symbolManager.constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
  verify(symbolLayer, times(0)).setFilter(any(Expression.class));
  verify(draggableAnnotationController).onSourceUpdated();
  verify(optionedGeoJsonSource).setGeoJson(any(FeatureCollection.class));
}
 
Example #11
Source File: SymbolManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testSymbolLayerFilter() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  Expression expression = Expression.eq(Expression.get("test"), "selected");
  verify(symbolLayer, times(0)).setFilter(expression);

  symbolManager.setFilter(expression);
  verify(symbolLayer, times(1)).setFilter(expression);

  when(symbolLayer.getFilter()).thenReturn(expression);
  assertEquals(expression, symbolManager.getFilter());
  assertEquals(expression, symbolManager.layerFilter);
}
 
Example #12
Source File: LineManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testInitialization() {
  lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(style).addSource(geoJsonSource);
  verify(style).addLayer(lineLayer);
  assertTrue(lineManager.dataDrivenPropertyUsageMap.size() > 0);
  for (Boolean value : lineManager.dataDrivenPropertyUsageMap.values()) {
    assertFalse(value);
  }
  verify(lineLayer).setProperties(lineManager.constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
  verify(lineLayer, times(0)).setFilter(any(Expression.class));
  verify(draggableAnnotationController).onSourceUpdated();
  verify(geoJsonSource).setGeoJson(any(FeatureCollection.class));
}
 
Example #13
Source File: LineManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testGeoJsonOptionsInitialization() {
  lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, geoJsonOptions, draggableAnnotationController);
  verify(style).addSource(optionedGeoJsonSource);
  verify(style).addLayer(lineLayer);
  assertTrue(lineManager.dataDrivenPropertyUsageMap.size() > 0);
  for (Boolean value : lineManager.dataDrivenPropertyUsageMap.values()) {
    assertFalse(value);
  }
  verify(lineLayer).setProperties(lineManager.constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
  verify(lineLayer, times(0)).setFilter(any(Expression.class));
  verify(draggableAnnotationController).onSourceUpdated();
  verify(optionedGeoJsonSource).setGeoJson(any(FeatureCollection.class));
}
 
Example #14
Source File: LineManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testLineLayerFilter() {
  lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  Expression expression = Expression.eq(Expression.get("test"), "selected");
  verify(lineLayer, times(0)).setFilter(expression);

  lineManager.setFilter(expression);
  verify(lineLayer, times(1)).setFilter(expression);

  when(lineLayer.getFilter()).thenReturn(expression);
  assertEquals(expression, lineManager.getFilter());
  assertEquals(expression, lineManager.layerFilter);
}
 
Example #15
Source File: TrafficPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static Expression getLineColorFunction(@ColorInt int low, @ColorInt int moderate, @ColorInt int heavy,
                                       @ColorInt int severe) {
  return match(get("congestion"), Expression.color(Color.TRANSPARENT),
    stop("low", Expression.color(low)),
    stop("moderate", Expression.color(moderate)),
    stop("heavy", Expression.color(heavy)),
    stop("severe", Expression.color(severe)));
}
 
Example #16
Source File: AirMapMapView.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
public void highlight(AirMapAdvisory advisory) {
    RectF mapRectF = new RectF(getLeft(), getTop(), getRight(), getBottom());
    Expression filter = Expression.has("id");
    List<Feature> selectedFeatures = getMap().queryRenderedFeatures(mapRectF, filter);

    for (Feature feature : selectedFeatures) {
        if (advisory.getId().equals(feature.getStringProperty("id"))) {
            mapStyleController.highlight(feature, advisory);
            zoomToFeatureIfNecessary(feature);
            break;
        }
    }
}
 
Example #17
Source File: MapStyleController.java    From AirMapSDK-Android with 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 #18
Source File: FilterProvider.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
public Expression getTimeFilter() {
    if (expressions.get(LAST_POSITION) != null) {
        return expressions.get(LAST_POSITION);
    } else if (expressions.get(RANGE) != null) {
        return expressions.get(RANGE);
    }

    return all();
}
 
Example #19
Source File: MapDataManager.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private void initInfoWindowLayer() {
    Expression iconOffset = switchCase(
            toBool(get(LAST_LOCATION)), literal(new Float[] {-2f, -25f}),
            literal(new Float[] {-2f, -20f}));
    GeoJsonSource infoWindowSource = new GeoJsonSource(INFO_WINDOW_SRC);
    mapboxStyle.addSource(infoWindowSource);
    mapboxStyle.addLayer(new SymbolLayer(INFO_WINDOW_LAYER, INFO_WINDOW_SRC).withProperties(
            iconImage(INFO_WINDOW_ID),
            iconAnchor(ICON_ANCHOR_BOTTOM_LEFT),
                 /* all info window and marker image to appear at the same time*/
            iconAllowOverlap(true),
                /* offset the info window to be above the marker */
            iconOffset(iconOffset)
    ));
}
 
Example #20
Source File: FillManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testGeoJsonOptionsInitialization() {
  fillManager = new FillManager(mapView, mapboxMap, style, coreElementProvider, null, geoJsonOptions, draggableAnnotationController);
  verify(style).addSource(optionedGeoJsonSource);
  verify(style).addLayer(fillLayer);
  assertTrue(fillManager.dataDrivenPropertyUsageMap.size() > 0);
  for (Boolean value : fillManager.dataDrivenPropertyUsageMap.values()) {
    assertFalse(value);
  }
  verify(fillLayer).setProperties(fillManager.constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
  verify(fillLayer, times(0)).setFilter(any(Expression.class));
  verify(draggableAnnotationController).onSourceUpdated();
  verify(optionedGeoJsonSource).setGeoJson(any(FeatureCollection.class));
}
 
Example #21
Source File: FillManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testInitialization() {
  fillManager = new FillManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(style).addSource(geoJsonSource);
  verify(style).addLayer(fillLayer);
  assertTrue(fillManager.dataDrivenPropertyUsageMap.size() > 0);
  for (Boolean value : fillManager.dataDrivenPropertyUsageMap.values()) {
    assertFalse(value);
  }
  verify(fillLayer).setProperties(fillManager.constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
  verify(fillLayer, times(0)).setFilter(any(Expression.class));
  verify(draggableAnnotationController).onSourceUpdated();
  verify(geoJsonSource).setGeoJson(any(FeatureCollection.class));
}
 
Example #22
Source File: CircleManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testCircleLayerFilter() {
  circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  Expression expression = Expression.eq(Expression.get("test"), "selected");
  verify(circleLayer, times(0)).setFilter(expression);

  circleManager.setFilter(expression);
  verify(circleLayer, times(1)).setFilter(expression);

  when(circleLayer.getFilter()).thenReturn(expression);
  assertEquals(expression, circleManager.getFilter());
  assertEquals(expression, circleManager.layerFilter);
}
 
Example #23
Source File: CircleManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testGeoJsonOptionsInitialization() {
  circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, geoJsonOptions, draggableAnnotationController);
  verify(style).addSource(optionedGeoJsonSource);
  verify(style).addLayer(circleLayer);
  assertTrue(circleManager.dataDrivenPropertyUsageMap.size() > 0);
  for (Boolean value : circleManager.dataDrivenPropertyUsageMap.values()) {
    assertFalse(value);
  }
  verify(circleLayer).setProperties(circleManager.constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
  verify(circleLayer, times(0)).setFilter(any(Expression.class));
  verify(draggableAnnotationController).onSourceUpdated();
  verify(optionedGeoJsonSource).setGeoJson(any(FeatureCollection.class));
}
 
Example #24
Source File: CircleManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testInitialization() {
  circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(style).addSource(geoJsonSource);
  verify(style).addLayer(circleLayer);
  assertTrue(circleManager.dataDrivenPropertyUsageMap.size() > 0);
  for (Boolean value : circleManager.dataDrivenPropertyUsageMap.values()) {
    assertFalse(value);
  }
  verify(circleLayer).setProperties(circleManager.constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
  verify(circleLayer, times(0)).setFilter(any(Expression.class));
  verify(draggableAnnotationController).onSourceUpdated();
  verify(geoJsonSource).setGeoJson(any(FeatureCollection.class));
}
 
Example #25
Source File: FillManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testFillLayerFilter() {
  fillManager = new FillManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  Expression expression = Expression.eq(Expression.get("test"), "selected");
  verify(fillLayer, times(0)).setFilter(expression);

  fillManager.setFilter(expression);
  verify(fillLayer, times(1)).setFilter(expression);

  when(fillLayer.getFilter()).thenReturn(expression);
  assertEquals(expression, fillManager.getFilter());
  assertEquals(expression, fillManager.layerFilter);
}
 
Example #26
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with 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 #27
Source File: MapDataManager.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
private void initContactBasedLayers(MapSource source) {
    if (mapboxStyle.getLayer(source.getMarkerLayer()) != null) {
        return;
    }

    GeoJsonSource markerPositionSource = new GeoJsonSource(source.getMarkerSource());
    GeoJsonSource linePositionSource = new GeoJsonSource(source.getLineSource());

    try {
        mapboxStyle.addSource(markerPositionSource);
        mapboxStyle.addSource(linePositionSource);
    } catch (RuntimeException e) {
        //TODO: specify exception more
        Log.e(TAG, "Unable to init GeoJsonSources. Already added to mapBoxMap? " + e.getMessage());
    }

    mapboxStyle.addImage(source.getMarkerLastPositon(),
            generateColoredLastPositionIcon(source.getColorArgb()));
    mapboxStyle.addImage(source.getMarkerIcon(),
            generateColoredLocationIcon(source.getColorArgb()));
    mapboxStyle.addImage(source.getMarkerPoi(),
            generateColoredPoiIcon(source.getColorArgb()));

    Expression markerSize =
            switchCase(
                    neq(length(get(MARKER_CHAR)), literal(0)),
                        switchCase(toBool(get(MARKER_SELECTED)), literal(2.25f), literal(2.0f)),
                    neq(get(MESSAGE_ID), literal(0)),
                        switchCase(toBool(get(MARKER_SELECTED)), literal(2.25f), literal(2.0f)),
                    switchCase(toBool(get(MARKER_SELECTED)), literal(1.1f), literal(0.7f)));
    Expression markerIcon = get(MARKER_ICON);

    mapboxStyle.addLayerBelow(new LineLayer(source.getLineLayer(), source.getLineSource())
            .withProperties(PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
                    lineJoin(Property.LINE_JOIN_ROUND),
                    lineWidth(3f),
                    lineOpacity(0.5f),
                    lineColor(source.getColorArgb()),
                    visibility(NONE)
            )
            .withFilter(filterProvider.getTimeFilter()),
            LAST_POSITION_LAYER);


    Expression textField = switchCase(eq(length(get(MARKER_CHAR)), 1), get(MARKER_CHAR),
            get(POI_LONG_DESCRIPTION));
    Float[] offset = new Float[] {0.0f, 1.25f};
    Float[] zeroOffset = new Float[] {0.0f, 0.0f};
    Expression textOffset = switchCase(
            has(POI_LONG_DESCRIPTION), literal(offset),
            literal(zeroOffset));
    Expression textColor = switchCase(
            has(POI_LONG_DESCRIPTION), literal("#000000"),
            literal("#FFFFFF")
    );
    Expression textAnchor = switchCase(
            has(POI_LONG_DESCRIPTION), literal(TEXT_ANCHOR_TOP),
            literal(TEXT_ANCHOR_CENTER)
    );
    Expression textSize = switchCase(
            has(POI_LONG_DESCRIPTION), literal(12.0f),
            literal(15.0f)
    );

    mapboxStyle.addLayerBelow(new SymbolLayer(source.getMarkerLayer(), source.getMarkerSource())
                    .withProperties(
                            iconImage(markerIcon),
                            iconSize(markerSize),
                            iconIgnorePlacement(false),
                            iconAllowOverlap(false),
                            textField(textField),
                            textOffset(textOffset),
                            textAnchor(textAnchor),
                            textSize(textSize),
                            textColor(textColor))
                    .withFilter(all(filterProvider.getMarkerFilter(),
                            not(get(LAST_LOCATION)))),
            LAST_POSITION_LAYER);
}
 
Example #28
Source File: CircleManager.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Set filter on the managed circles.
 *
 * @param expression expression
 */
 @Override
public void setFilter(@NonNull Expression expression) {
  layerFilter = expression;
  layer.setFilter(layerFilter);
}
 
Example #29
Source File: FilterProvider.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
public Expression getMarkerFilter() {
    return all(expressions.values().toArray(new Expression[expressions.values().size()]));
}
 
Example #30
Source File: FilterProvider.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
private void addFilter(FilterType type, @NonNull Expression expression) {
    expressions.put(type, expression);
}