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

The following examples show how to use com.mapbox.mapboxsdk.style.layers.Layer#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: 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: 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 3
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 4
Source File: TrafficPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Toggles the visibility of the traffic layers.
 *
 * @param visible true for visible, false for none
 */
public void setVisibility(boolean visible) {
  this.visible = visible;

  if (!style.isFullyLoaded()) {
    // We are in progress of loading a new style
    return;
  }

  Source source = style.getSource(TrafficData.SOURCE_ID);
  if (source == null) {
    initialise();
  }

  List<Layer> layers = style.getLayers();
  for (Layer layer : layers) {
    if (layerIds.contains(layer.getId())) {
      layer.setProperties(visibility(visible ? Property.VISIBLE : Property.NONE));
    }
  }
}
 
Example 5
Source File: MapWayname.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void createWaynameIcon(String wayname, Layer waynameLayer) {
  boolean isVisible = waynameLayer.getVisibility().getValue().contentEquals(Property.VISIBLE);
  if (isVisible) {
    Bitmap waynameLayoutBitmap = layoutProvider.generateLayoutBitmap(wayname);
    if (waynameLayoutBitmap != null) {
      layerInteractor.addLayerImage(MAPBOX_WAYNAME_ICON, waynameLayoutBitmap);
      waynameLayer.setProperties(iconImage(MAPBOX_WAYNAME_ICON));
    }
  }
}
 
Example 6
Source File: MapLayerInteractor.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void updateLayerWithVisibility(String layerIdentifier, List<Layer> layers, boolean isVisible) {
  for (Layer layer : layers) {
    if (isValid(layer)) {
      String sourceLayerId = retrieveSourceLayerId(layer);
      if (sourceLayerId.equals(layerIdentifier)) {
        layer.setProperties(visibility(isVisible ? VISIBLE : NONE));
      }
    }
  }
}
 
Example 7
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
/**
 * Loops through all the route layers stored inside the layerId list and toggles the visibility.
 * if the layerId matches the primary route index, we skip since we still want that route to be
 * displayed.
 */
private void toggleAlternativeVisibility(boolean visible) {
  for (String layerId : layerIds) {
    if (layerId.contains(String.valueOf(primaryRouteIndex))
      || layerId.contains(WAYPOINT_LAYER_ID)) {
      continue;
    }
    Layer layer = mapboxMap.getLayer(layerId);
    if (layer != null) {
      layer.setProperties(
        visibility(visible ? VISIBLE : NONE)
      );
    }
  }
}
 
Example 8
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void updateArrowLayersVisibilityTo(boolean visible) {
  for (Layer layer : arrowLayers) {
    String targetVisibility = visible ? VISIBLE : NONE;
    if (!targetVisibility.equals(layer.getVisibility().getValue())) {
      layer.setProperties(visibility(targetVisibility));
    }
  }
}
 
Example 9
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);
    }
  }
}
 
Example 10
Source File: MapWayname.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
private void adjustWaynameVisibility(boolean isVisible, Layer waynameLayer) {
  if (waynameLayer != null) {
    waynameLayer.setProperties(visibility(isVisible ? Property.VISIBLE : Property.NONE));
  }
}