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

The following examples show how to use com.mapbox.mapboxsdk.style.layers.Layer. 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
/**
 * 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 #2
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 #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: 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 #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: 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 #7
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with MIT License 6 votes vote down vote up
/**
 * Iterate through map style layers backwards till the first not-symbol layer is found.
 */
private void placeRouteBelow() {
  if (belowLayer == null || belowLayer.isEmpty()) {
    List<Layer> styleLayers = mapboxMap.getLayers();
    if (styleLayers == null) {
      return;
    }
    for (int i = 0; i < styleLayers.size(); i++) {
      if (!(styleLayers.get(i) instanceof SymbolLayer)
        // Avoid placing the route on top of the user location layer
        && !styleLayers.get(i).getId().contains("mapbox-location")) {
        belowLayer = styleLayers.get(i).getId();
      }
    }
  }
}
 
Example #8
Source File: MapLayerInteractorTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void isLayerVisible_visibleReturnsFalseIfInvalidLayer() {
  HeatmapLayer invalidLayer = mock(HeatmapLayer.class);
  List<Layer> layers = buildLayerListWith(invalidLayer);
  MapboxMap map = mock(MapboxMap.class);
  when(map.getLayers()).thenReturn(layers);
  MapLayerInteractor layerInteractor = new MapLayerInteractor(map);

  boolean isVisible = layerInteractor.isLayerVisible("heatmap");

  assertFalse(isVisible);
}
 
Example #9
Source File: MapLayerInteractorTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void updateLayerVisibility_visibilityIsSet() {
  LineLayer anySymbolOrLineLayer = mock(LineLayer.class);
  when(anySymbolOrLineLayer.getSourceLayer()).thenReturn("any");
  List<Layer> layers = buildLayerListWith(anySymbolOrLineLayer);
  MapboxMap map = mock(MapboxMap.class);
  when(map.getLayers()).thenReturn(layers);
  MapLayerInteractor layerInteractor = new MapLayerInteractor(map);

  layerInteractor.updateLayerVisibility(true, "any");

  verify(anySymbolOrLineLayer).setProperties(any(PropertyValue.class));
}
 
Example #10
Source File: MapLayerInteractorTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void updateLayerVisibility_visibilityIsNotSet() {
  SymbolLayer anySymbolOrLineLayer = mock(SymbolLayer.class);
  when(anySymbolOrLineLayer.getSourceLayer()).thenReturn("any");
  List<Layer> layers = buildLayerListWith(anySymbolOrLineLayer);
  MapboxMap map = mock(MapboxMap.class);
  when(map.getLayers()).thenReturn(layers);
  MapLayerInteractor layerInteractor = new MapLayerInteractor(map);

  layerInteractor.updateLayerVisibility(true, "random");

  verify(anySymbolOrLineLayer, times(0)).setProperties(any(PropertyValue.class));
}
 
Example #11
Source File: MapLayerInteractorTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void updateLayerVisibility_visibilityIsNotSetIfInvalidLayer() {
  CircleLayer invalidLayer = mock(CircleLayer.class);
  List<Layer> layers = buildLayerListWith(invalidLayer);
  MapboxMap map = mock(MapboxMap.class);
  when(map.getLayers()).thenReturn(layers);
  MapLayerInteractor layerInteractor = new MapLayerInteractor(map);

  layerInteractor.updateLayerVisibility(true, "circle");

  verify(invalidLayer, times(0)).setProperties(any(PropertyValue.class));
}
 
Example #12
Source File: MapLayerInteractorTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void isLayerVisible_visibleReturnsTrue() {
  SymbolLayer anySymbolOrLineLayer = mock(SymbolLayer.class);
  when(anySymbolOrLineLayer.getSourceLayer()).thenReturn("any");
  when(anySymbolOrLineLayer.getVisibility()).thenReturn(visibility(Property.VISIBLE));
  List<Layer> layers = buildLayerListWith(anySymbolOrLineLayer);
  MapboxMap map = mock(MapboxMap.class);
  when(map.getLayers()).thenReturn(layers);
  MapLayerInteractor layerInteractor = new MapLayerInteractor(map);

  boolean isVisible = layerInteractor.isLayerVisible("any");

  assertTrue(isVisible);
}
 
Example #13
Source File: MapLayerInteractorTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void isLayerVisible_visibleReturnsFalse() {
  LineLayer anySymbolOrLineLayer = mock(LineLayer.class);
  when(anySymbolOrLineLayer.getSourceLayer()).thenReturn("any");
  when(anySymbolOrLineLayer.getVisibility()).thenReturn(visibility(Property.NONE));
  List<Layer> layers = buildLayerListWith(anySymbolOrLineLayer);
  MapboxMap map = mock(MapboxMap.class);
  when(map.getLayers()).thenReturn(layers);
  MapLayerInteractor layerInteractor = new MapLayerInteractor(map);

  boolean isVisible = layerInteractor.isLayerVisible("any");

  assertFalse(isVisible);
}
 
Example #14
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 #15
Source File: TrafficPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Add Layer to the map and track the id.
 *
 * @param layer        the layer to be added to the map
 * @param idAboveLayer the id of the layer above
 */
private void addTrafficLayersToMap(Layer layerCase, Layer layer, String idAboveLayer) {
  style.addLayerBelow(layerCase, idAboveLayer);
  style.addLayerAbove(layer, layerCase.getId());
  layerIds.add(layerCase.getId());
  layerIds.add(layer.getId());
}
 
Example #16
Source File: LocalizationPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * You can pass in a {@link MapLocale} directly into this method which uses the language defined
 * in it to represent the language found on the map.
 *
 * @param mapLocale the {@link MapLocale} object which contains the desired map language
 * @since 0.1.0
 */
public void setMapLanguage(@NonNull MapLocale mapLocale) {
  this.mapLocale = mapLocale;
  if (!style.isFullyLoaded()) {
    // We are in progress of loading a new style
    return;
  }

  List<Layer> layers = style.getLayers();
  for (Source source : style.getSources()) {
    if (sourceIsFromMapbox(source)) {
      boolean isStreetsV8 = sourceIsStreetsV8(source);
      for (Layer layer : layers) {
        if (layer instanceof SymbolLayer) {
          PropertyValue<?> textFieldProperty = ((SymbolLayer) layer).getTextField();
          if (textFieldProperty.isExpression()) {
            if (isStreetsV8) {
              convertExpressionV8(mapLocale, layer, textFieldProperty);
            } else {
              boolean isStreetsV7 = sourceIsStreetsV7(source);
              convertExpression(mapLocale, layer, textFieldProperty, isStreetsV7);
            }
          }
        }
      }
    } else {
      String url = null;
      if (source instanceof VectorSource) {
        url = ((VectorSource) source).getUrl();
      }
      if (url == null) {
        url = "not found";
      }
      Timber.d("The %s (%s) source is not based on Mapbox Vector Tiles. Supported sources:\n %s",
        source.getId(), url, SUPPORTED_SOURCES);
    }
  }
}
 
Example #17
Source File: TrafficPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Attempts to find the layer which the traffic should be placed below. Depending on the style, this might not always
 * be accurate.
 */
private String placeLayerBelow() {
  if (belowLayer == null || belowLayer.isEmpty()) {
    List<Layer> styleLayers = style.getLayers();
    Layer layer;
    for (int i = styleLayers.size() - 1; i >= 0; i--) {
      layer = styleLayers.get(i);
      if (!(layer instanceof SymbolLayer)) {
        return layer.getId();
      }
    }
  }
  return belowLayer;
}
 
Example #18
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 #19
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 #20
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 #21
Source File: MapUtils.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
/**
 * Generic method for adding layers to the map.
 *
 * @param mapboxMap    that the current mapView is using
 * @param layer        a layer that will be added to the map
 * @param idBelowLayer optionally providing the layer which the new layer should be placed below
 * @since 0.8.0
 */
public static void addLayerToMap(@NonNull MapboxMap mapboxMap, @NonNull Layer layer,
                                 @Nullable String idBelowLayer) {
  if (mapboxMap.getLayer(layer.getId()) != null) {
    return;
  }
  if (idBelowLayer == null) {
    mapboxMap.addLayer(layer);
  } else {
    mapboxMap.addLayerBelow(layer, idBelowLayer);
  }
}
 
Example #22
Source File: MapLayerInteractor.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private String retrieveSourceLayerId(Layer layer) {
  String sourceIdentifier;
  if (layer instanceof LineLayer) {
    sourceIdentifier = ((LineLayer) layer).getSourceLayer();
  } else {
    sourceIdentifier = ((SymbolLayer) layer).getSourceLayer();
  }
  return sourceIdentifier;
}
 
Example #23
Source File: MapLayerInteractor.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private boolean findLayerVisibility(String layerIdentifier, List<Layer> layers) {
  for (Layer layer : layers) {
    if (isValid(layer)) {
      String sourceLayerId = retrieveSourceLayerId(layer);
      if (sourceLayerId.equals(layerIdentifier)) {
        return layer.getVisibility().value.equals(VISIBLE);
      }
    }
  }
  return false;
}
 
Example #24
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 #25
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 #26
Source File: MapStyleController.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private void setupJurisdictionsForEnterprise() {
    // Reload the style after setup is complete
    if (map == null || map.getMap() == null || map.getMap().getStyle() == null) {
        return;
    }

    OfflineManager.getInstance(map.getContext()).clearAmbientCache(null);

    Style style = map.getMap().getStyle();
    String jurisdictionsId = "jurisdictions";

    if (style.getLayer(jurisdictionsId) != null) {
        style.removeLayer(jurisdictionsId);
    }

    if (style.getSource(jurisdictionsId) != null) {
        style.removeSource(jurisdictionsId);
    }

    TileSet tileSet = new TileSet(tileJsonSpecVersion, AirMap.getBaseJurisdictionsUrlTemplate());
    tileSet.setMaxZoom(12f);
    tileSet.setMinZoom(8f);
    Source source = new VectorSource(jurisdictionsId, tileSet);
    style.addSource(source);
    Layer layer = new FillLayer(jurisdictionsId, jurisdictionsId)
            .withSourceLayer(jurisdictionsId)
            .withProperties(fillColor(TRANSPARENT), fillOpacity(1f));
    style.addLayerAt(layer, 0);
}
 
Example #27
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 #28
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 #29
Source File: MapStyleController.java    From AirMapSDK-Android with Apache License 2.0 4 votes vote down vote up
private void addTemporalFilter(Layer layer) {
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();

    long start = System.currentTimeMillis() / 1000;
    long end = start + (4 * 60 * 60);

    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;
        }

        start = cal1.getTime().getTime() / 1000;
        end = cal2.getTime().getTime() / 1000;
    }

    Expression validNowFilter = Expression.all(Expression.lt(Expression.get("start"), start), Expression.gt(Expression.get("end"), start));
    Expression startsSoonFilter = Expression.all(Expression.gt(Expression.get("start"), start), Expression.lt(Expression.get("start"), end));
    Expression permanent = Expression.all(Expression.has("permanent"), Expression.eq(Expression.get("permanent"), "true"));
    Expression hasNoEnd = Expression.all(Expression.not(Expression.has("end")), Expression.not(Expression.has("base")));
    Expression filter = Expression.any(permanent, hasNoEnd, validNowFilter, startsSoonFilter);

    if (layer instanceof FillLayer) {
        ((FillLayer) layer).setFilter(filter);
    } else if (layer instanceof LineLayer) {
        ((LineLayer) layer).setFilter(filter);
    }
}
 
Example #30
Source File: AirMapFillLayerStyle.java    From AirMapSDK-Android with Apache License 2.0 4 votes vote down vote up
@Override
public FillLayer toMapboxLayer(Layer layerToClone, String sourceId) {
    FillLayer fillLayer = new FillLayer(id + "|" + sourceId + "|new", sourceId);
    fillLayer.setSourceLayer(sourceId + "_" + sourceLayer);

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

    PropertyValue fillColor = getFillColor(layer.getFillColor());
    if (fillColor != null) {
        properties.add(fillColor);
    }

    PropertyValue fillOpacity = getFillOpacity(layer.getFillOpacity());
    if (fillOpacity != null) {
        properties.add(fillOpacity);
    }

    PropertyValue fillAntialias = getFillAntialias(layer.getFillAntialias());
    if (fillAntialias != null) {
        properties.add(fillAntialias);
    }

    PropertyValue fillOutlineColor = getFillOutlineColor(layer.getFillOutlineColor());
    if (fillOutlineColor != null) {
        properties.add(fillOutlineColor);
    }

    PropertyValue fillTranslate = getFillTranslate(layer.getFillTranslate());
    if (fillTranslate != null) {
        properties.add(fillTranslate);
    }

    PropertyValue fillTranslateAnchor = getFillTranslateAnchor(layer.getFillTranslateAnchor());
    if (fillTranslateAnchor != null) {
        properties.add(fillTranslateAnchor);
    }

    PropertyValue fillPattern = getFillPattern(layer.getFillPattern());
    if (fillPattern != null) {
        properties.add(fillPattern);
    }

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

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

    return fillLayer;
}