diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers')
3 files changed, 63 insertions, 3 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java index 848165f00f..6936c302b2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java @@ -62,7 +62,7 @@ public class PropertyValue<T> { ? Expression.Converter.convert((JsonArray) value) : (Expression) value; } else { - Logger.w(TAG, "not a expression, try value"); + Logger.w(TAG, "not an expression, try PropertyValue#getValue()"); return null; } } @@ -87,7 +87,7 @@ public class PropertyValue<T> { // noinspection unchecked return value; } else { - Logger.w(TAG, "not a value, try function"); + Logger.w(TAG, "not a value, try PropertyValue#getExpression()"); return null; } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java index 1d45f34bd3..7b9128343c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java @@ -13,6 +13,8 @@ import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; import com.google.gson.JsonArray; import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.style.types.Formatted; +import com.mapbox.mapboxsdk.style.types.FormattedSection; /** * An icon or a text label. @@ -365,7 +367,31 @@ public class SymbolLayer extends Layer { @SuppressWarnings("unchecked") public PropertyValue<String> getTextField() { checkThread(); - return (PropertyValue<String>) new PropertyValue("text-field", nativeGetTextField()); + + PropertyValue propertyValue = new PropertyValue<>("text-field", nativeGetTextField()); + if (propertyValue.isExpression()) { + return (PropertyValue<String>) propertyValue; + } else { + Formatted formatted = (Formatted) nativeGetTextField(); + StringBuilder builder = new StringBuilder(); + for (FormattedSection section : formatted.getFormattedSections()) { + builder.append(section.getText()); + } + + return (PropertyValue<String>) new PropertyValue("text-field", builder.toString()); + } + } + + /** + * Get the TextField property as {@link Formatted} object + * + * @return property wrapper value around String + * @see Expression#format(Expression...) + */ + @SuppressWarnings("unchecked") + public PropertyValue<Formatted> getFormattedTextField() { + checkThread(); + return (PropertyValue<Formatted>) new PropertyValue("text-field", nativeGetTextField()); } /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs index 958cb7383d..961991c7a1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs @@ -18,6 +18,10 @@ import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; import com.google.gson.JsonArray; import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +<% if (type === 'symbol') { -%> +import com.mapbox.mapboxsdk.style.types.Formatted; +import com.mapbox.mapboxsdk.style.types.FormattedSection; +<% } -%> /** * <%- doc %> @@ -171,8 +175,38 @@ public class <%- camelize(type) %>Layer extends Layer { @SuppressWarnings("unchecked") public PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() { checkThread(); +<% if (property.name === 'text-field' && property.type === 'formatted') { -%> + + PropertyValue propertyValue = new PropertyValue<>("text-field", nativeGetTextField()); + if (propertyValue.isExpression()) { + return (PropertyValue<String>) propertyValue; + } else { + Formatted formatted = (Formatted) nativeGetTextField(); + StringBuilder builder = new StringBuilder(); + for (FormattedSection section : formatted.getFormattedSections()) { + builder.append(section.getText()); + } + + return (PropertyValue<String>) new PropertyValue("text-field", builder.toString()); + } +<% } else { -%> return (PropertyValue<<%- propertyType(property) %>>) new PropertyValue("<%- property.name %>", nativeGet<%- camelize(property.name) %>()); +<% } -%> + } +<% if (property.name === 'text-field' && property.type === 'formatted') { -%> + + /** + * Get the <%- camelize(property.name) %> property as {@link Formatted} object + * + * @return property wrapper value around <%- propertyType(property) %> + * @see Expression#format(Expression...) + */ + @SuppressWarnings("unchecked") + public PropertyValue<Formatted> getFormatted<%- camelize(property.name) %>() { + checkThread(); + return (PropertyValue<Formatted>) new PropertyValue("<%- property.name %>", nativeGet<%- camelize(property.name) %>()); } +<% } -%> <% if (property.type == 'color') { -%> /** |