[android] renamed format expression options, added format expression example
This commit is contained in:
committed by
Łukasz Paczos
parent
3d67c7813b
commit
d5b66e56e9
@@ -3246,10 +3246,13 @@ public class Expression {
|
||||
* format(
|
||||
* formatEntry(
|
||||
* get("header_property"),
|
||||
* fontScale(2.0),
|
||||
* textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
* formatFontScale(2.0),
|
||||
* formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
* ),
|
||||
* formatEntry(concat(literal("\n"), get("description_property")), fontScale(1.5)),
|
||||
* formatEntry(concat(literal("\n"), get("description_property")), formatFontScale(1.5))
|
||||
* )
|
||||
* )
|
||||
* );
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
@@ -4375,7 +4378,7 @@ public class Expression {
|
||||
* @return format option
|
||||
*/
|
||||
@NonNull
|
||||
public static FormatOption fontScale(@NonNull Expression expression) {
|
||||
public static FormatOption formatFontScale(@NonNull Expression expression) {
|
||||
return new FormatOption("font-scale", expression);
|
||||
}
|
||||
|
||||
@@ -4389,7 +4392,7 @@ public class Expression {
|
||||
* @return format option
|
||||
*/
|
||||
@NonNull
|
||||
public static FormatOption fontScale(double scale) {
|
||||
public static FormatOption formatFontScale(double scale) {
|
||||
return new FormatOption("font-scale", literal(scale));
|
||||
}
|
||||
|
||||
@@ -4405,7 +4408,7 @@ public class Expression {
|
||||
* @return format option
|
||||
*/
|
||||
@NonNull
|
||||
public static FormatOption textFont(@NonNull Expression expression) {
|
||||
public static FormatOption formatTextFont(@NonNull Expression expression) {
|
||||
return new FormatOption("text-font", expression);
|
||||
}
|
||||
|
||||
@@ -4421,7 +4424,7 @@ public class Expression {
|
||||
* @return format option
|
||||
*/
|
||||
@NonNull
|
||||
public static FormatOption textFont(@NonNull String[] fontStack) {
|
||||
public static FormatOption formatTextFont(@NonNull String[] fontStack) {
|
||||
return new FormatOption("text-font", literal(fontStack));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ public class SymbolLayer extends Layer {
|
||||
* Get the TextField property as {@link Formatted} object
|
||||
*
|
||||
* @return property wrapper value around String
|
||||
* @see Expression#format(Expression...)
|
||||
* @see Expression#format(Expression.FormatEntry...)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public PropertyValue<Formatted> getFormattedTextField() {
|
||||
|
||||
@@ -199,7 +199,7 @@ public class <%- camelize(type) %>Layer extends Layer {
|
||||
* Get the <%- camelize(property.name) %> property as {@link Formatted} object
|
||||
*
|
||||
* @return property wrapper value around <%- propertyType(property) %>
|
||||
* @see Expression#format(Expression...)
|
||||
* @see Expression#format(Expression.FormatEntry...)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public PropertyValue<Formatted> getFormatted<%- camelize(property.name) %>() {
|
||||
|
||||
@@ -14,8 +14,8 @@ import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.fontScale;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.textFont;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatFontScale;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatTextFont;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.abs;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.acos;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.all;
|
||||
@@ -1420,7 +1420,8 @@ public class ExpressionTest {
|
||||
}
|
||||
};
|
||||
Object[] actual = format(
|
||||
formatEntry(literal("test"), fontScale(literal(1.5)), textFont(literal(new String[] {"awesome"})))
|
||||
formatEntry(
|
||||
literal("test"), formatFontScale(literal(1.5)), formatTextFont(literal(new String[] {"awesome"})))
|
||||
).toArray();
|
||||
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
|
||||
}
|
||||
@@ -1455,10 +1456,11 @@ public class ExpressionTest {
|
||||
}
|
||||
};
|
||||
Object[] actual = format(
|
||||
formatEntry(literal("test"), textFont(new String[] {"awesome"})),
|
||||
formatEntry("test2", fontScale(1.5)),
|
||||
formatEntry(literal("test"), formatTextFont(new String[] {"awesome"})),
|
||||
formatEntry("test2", formatFontScale(1.5)),
|
||||
formatEntry(literal("test3")),
|
||||
formatEntry(literal("test4"), fontScale(literal(1.5)), textFont(new String[] {"awesome"}))
|
||||
formatEntry(
|
||||
literal("test4"), formatFontScale(literal(1.5)), formatTextFont(new String[] {"awesome"}))
|
||||
).toArray();
|
||||
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ import java.io.IOException;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.fontScale;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.textFont;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatFontScale;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatTextFont;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.collator;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential;
|
||||
@@ -315,7 +315,7 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry("test", fontScale(1.75))
|
||||
formatEntry("test", formatFontScale(1.75))
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
@@ -344,13 +344,16 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
literal("test"), fontScale(1.0), textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
literal("test"),
|
||||
formatFontScale(1.0),
|
||||
formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
assertFalse(
|
||||
mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer").isEmpty()
|
||||
);
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals("test", layer.getTextField().getValue());
|
||||
@@ -375,13 +378,16 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
"test", fontScale(0.5), textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
"test",
|
||||
formatFontScale(0.5),
|
||||
formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
assertFalse(
|
||||
mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer").isEmpty()
|
||||
);
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals("test", layer.getTextField().getValue());
|
||||
@@ -404,14 +410,17 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
"test", fontScale(1.5), textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
"test",
|
||||
formatFontScale(1.5),
|
||||
formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
),
|
||||
formatEntry("\ntest2", fontScale(2))
|
||||
formatEntry("\ntest2", formatFontScale(2))
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
assertFalse(
|
||||
mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer").isEmpty()
|
||||
);
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals("test\ntest2", layer.getTextField().getValue());
|
||||
@@ -440,8 +449,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
get("test_property"),
|
||||
fontScale(number(get("test_property_number"))),
|
||||
textFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
|
||||
Expression.FormatOption.formatFontScale(number(get("test_property_number"))),
|
||||
formatTextFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
@@ -472,10 +481,10 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
get("test_property"),
|
||||
fontScale(1.25),
|
||||
textFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
|
||||
formatFontScale(1.25),
|
||||
formatTextFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
|
||||
),
|
||||
formatEntry("\ntest2", fontScale(2))
|
||||
formatEntry("\ntest2", formatFontScale(2))
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.mapbox.geojson.Feature;
|
||||
@@ -29,6 +30,11 @@ import com.mapbox.mapboxsdk.utils.BitmapUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatFontScale;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatTextFont;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.concat;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.format;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.formatEntry;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.switchCase;
|
||||
@@ -118,7 +124,16 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
iconSize(switchCase(toBool(get(SELECTED_FEATURE_PROPERTY)), literal(3.0f), literal(1.0f))),
|
||||
iconAnchor(Property.ICON_ANCHOR_BOTTOM),
|
||||
iconColor(Color.RED),
|
||||
textField(get(TITLE_FEATURE_PROPERTY)),
|
||||
textField(
|
||||
format(
|
||||
formatEntry("this is", formatFontScale(0.75)),
|
||||
formatEntry(
|
||||
concat(literal("\n"), get(TITLE_FEATURE_PROPERTY)),
|
||||
formatFontScale(1.25),
|
||||
formatTextFont(new String[] {"DIN Offc Pro Bold", "Arial Unicode MS Regular"})
|
||||
)
|
||||
)
|
||||
),
|
||||
textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"}),
|
||||
textColor(Color.RED),
|
||||
textAllowOverlap(true),
|
||||
|
||||
Reference in New Issue
Block a user