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

The following examples show how to use com.mapbox.mapboxsdk.style.layers.PropertyValue. 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 Project: mapbox-plugins-android   Author: mapbox   File: LocalizationPlugin.java    License: 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 #2
Source Project: mapbox-plugins-android   Author: mapbox   File: LocalizationPlugin.java    License: 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 #3
Source Project: mapbox-plugins-android   Author: mapbox   File: AnnotationManager.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initializeSourcesAndLayers(GeoJsonOptions geoJsonOptions) {
  geoJsonSource = coreElementProvider.getSource(geoJsonOptions);
  layer = coreElementProvider.getLayer();

  style.addSource(geoJsonSource);
  if (belowLayerId == null) {
    style.addLayer(layer);
  } else {
    style.addLayerBelow(layer, belowLayerId);
  }

  initializeDataDrivenPropertyMap();
  layer.setProperties(constantPropertyUsageMap.values().toArray(new PropertyValue[0]));
  if (layerFilter != null) {
    setFilter(layerFilter);
  }

  updateSource();
}
 
Example #4
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapLayerInteractorTest.java    License: 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 #5
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapLayerInteractorTest.java    License: 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 #6
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapLayerInteractorTest.java    License: 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 #7
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapWaynameTest.java    License: MIT License 5 votes vote down vote up
@Test
public void onFeatureWithoutNamePropertyReturned_updateIsIgnored() {
  PointF point = mock(PointF.class);
  SymbolLayer waynameLayer = mock(SymbolLayer.class);
  List<Feature> roads = new ArrayList<>();
  Feature road = mock(Feature.class);
  roads.add(road);
  MapWayname mapWayname = buildMapWayname(point, waynameLayer, roads);

  mapWayname.updateWaynameWithPoint(point, waynameLayer);

  verify(waynameLayer, times(0)).setProperties(any(PropertyValue.class));
}
 
Example #8
Source Project: mapbox-plugins-android   Author: mapbox   File: LocalizationPlugin.java    License: 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 #9
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapLineLayerStyle.java    License: 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 #10
Source Project: mapbox-plugins-android   Author: mapbox   File: PropertyValueMatcher.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public boolean matches(PropertyValue argument) {
  if (argument == wanted) {
    return true;
  } else if (!argument.name.equals(wanted.name)) {
    return false;
  } else if (argument.getValue() != null && wanted.getValue() != null) {
    return argument.getValue().equals(wanted.getValue());
  } else if (argument.getExpression() != null && wanted.getExpression() != null) {
    return Arrays.deepEquals(argument.getExpression().toArray(), wanted.getExpression().toArray());
  } else {
    return argument.getValue() == null && wanted.getValue() == null
      && argument.getExpression() == null && wanted.getExpression() == null;
  }
}
 
Example #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
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 #27
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;
}
 
Example #28
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapLineLayerStyle.java    License: 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 #29
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapFillLayerStyle.java    License: 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 #30
Source Project: AirMapSDK-Android   Author: airmap   File: AirMapFillLayerStyle.java    License: 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;
}