Search in sources :

Example 11 with Expression

use of com.mapbox.mapboxsdk.style.expressions.Expression in project mapbox-plugins-android by mapbox.

the class LocalizationPlugin method convertExpression.

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)));
    }
}
Also used : Expression(com.mapbox.mapboxsdk.style.expressions.Expression)

Aggregations

Expression (com.mapbox.mapboxsdk.style.expressions.Expression)11 Test (org.junit.Test)8 MapView (com.mapbox.mapboxsdk.maps.MapView)4 Style (com.mapbox.mapboxsdk.maps.Style)4 GeoJsonSource (com.mapbox.mapboxsdk.style.sources.GeoJsonSource)4 PointF (android.graphics.PointF)1 Point (com.mapbox.geojson.Point)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 Symbol (com.mapbox.mapboxsdk.plugins.annotation.Symbol)1