[android] renamed format expression options, added format expression example

This commit is contained in:
Łukasz Paczos
2018-10-23 19:37:32 +02:00
committed by Łukasz Paczos
parent 3d67c7813b
commit d5b66e56e9
6 changed files with 63 additions and 34 deletions

View File

@@ -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);

View File

@@ -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),