[core] Enable 'text-radial-offset' property

This commit is contained in:
Mikhail Pozdnyakov
2019-03-07 18:52:00 +02:00
parent a6d8742e63
commit 2b9a52f5e4
10 changed files with 98 additions and 6 deletions

View File

@@ -134,6 +134,10 @@ public:
PropertyValue<TextJustifyType> getTextJustify() const;
void setTextJustify(PropertyValue<TextJustifyType>);
static PropertyValue<float> getDefaultTextRadialOffset();
PropertyValue<float> getTextRadialOffset() const;
void setTextRadialOffset(PropertyValue<float>);
static PropertyValue<std::vector<TextVariableAnchorType>> getDefaultTextVariableAnchor();
PropertyValue<std::vector<TextVariableAnchorType>> getTextVariableAnchor() const;
void setTextVariableAnchor(PropertyValue<std::vector<TextVariableAnchorType>>);

View File

@@ -2276,7 +2276,27 @@ public class PropertyFactory {
}
/**
* To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the `text-radial-offset` instead of the two-dimensional {@link PropertyFactory#textOffset}.
* Radial offset of text, in the direction of the symbol's anchor. Useful in combination with {@link PropertyFactory#textVariableAnchor}, which doesn't support the two-dimensional {@link PropertyFactory#textOffset}.
*
* @param value a Float value
* @return property wrapper around Float
*/
public static PropertyValue<Float> textRadialOffset(Float value) {
return new LayoutPropertyValue<>("text-radial-offset", value);
}
/**
* Radial offset of text, in the direction of the symbol's anchor. Useful in combination with {@link PropertyFactory#textVariableAnchor}, which doesn't support the two-dimensional {@link PropertyFactory#textOffset}.
*
* @param value a Float value
* @return property wrapper around Float
*/
public static PropertyValue<Expression> textRadialOffset(Expression value) {
return new LayoutPropertyValue<>("text-radial-offset", value);
}
/**
* To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the {@link PropertyFactory#textRadialOffset} instead of the two-dimensional {@link PropertyFactory#textOffset}.
*
* @param value a String[] value
* @return property wrapper around String[]
@@ -2286,7 +2306,7 @@ public class PropertyFactory {
}
/**
* To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the `text-radial-offset` instead of the two-dimensional {@link PropertyFactory#textOffset}.
* To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the {@link PropertyFactory#textRadialOffset} instead of the two-dimensional {@link PropertyFactory#textOffset}.
*
* @param value a String[] value
* @return property wrapper around String[]

View File

@@ -469,6 +469,18 @@ public class SymbolLayer extends Layer {
return (PropertyValue<String>) new PropertyValue("text-justify", nativeGetTextJustify());
}
/**
* Get the TextRadialOffset property
*
* @return property wrapper value around Float
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextRadialOffset() {
checkThread();
return (PropertyValue<Float>) new PropertyValue("text-radial-offset", nativeGetTextRadialOffset());
}
/**
* Get the TextVariableAnchor property
*
@@ -1197,6 +1209,10 @@ public class SymbolLayer extends Layer {
@Keep
private native Object nativeGetTextJustify();
@NonNull
@Keep
private native Object nativeGetTextRadialOffset();
@NonNull
@Keep
private native Object nativeGetTextVariableAnchor();

View File

@@ -577,6 +577,19 @@ public class SymbolLayerTest extends BaseLayerTest {
assertEquals(layer.getTextJustify().getExpression(), expression);
}
@Test
@UiThreadTest
public void testTextRadialOffsetAsConstant() {
Timber.i("text-radial-offset");
assertNotNull(layer);
assertNull(layer.getTextRadialOffset().getValue());
// Set and Get
Float propertyValue = 0.3f;
layer.setProperties(textRadialOffset(propertyValue));
assertEquals(layer.getTextRadialOffset().getValue(), propertyValue);
}
@Test
@UiThreadTest
public void testTextVariableAnchorAsConstant() {

View File

@@ -176,6 +176,11 @@ namespace android {
return std::move(*convert<jni::Local<jni::Object<>>>(env, toSymbolLayer(layer).getTextJustify()));
}
jni::Local<jni::Object<>> SymbolLayer::getTextRadialOffset(jni::JNIEnv& env) {
using namespace mbgl::android::conversion;
return std::move(*convert<jni::Local<jni::Object<>>>(env, toSymbolLayer(layer).getTextRadialOffset()));
}
jni::Local<jni::Object<>> SymbolLayer::getTextVariableAnchor(jni::JNIEnv& env) {
using namespace mbgl::android::conversion;
return std::move(*convert<jni::Local<jni::Object<>>>(env, toSymbolLayer(layer).getTextVariableAnchor()));
@@ -519,6 +524,7 @@ namespace android {
METHOD(&SymbolLayer::getTextLineHeight, "nativeGetTextLineHeight"),
METHOD(&SymbolLayer::getTextLetterSpacing, "nativeGetTextLetterSpacing"),
METHOD(&SymbolLayer::getTextJustify, "nativeGetTextJustify"),
METHOD(&SymbolLayer::getTextRadialOffset, "nativeGetTextRadialOffset"),
METHOD(&SymbolLayer::getTextVariableAnchor, "nativeGetTextVariableAnchor"),
METHOD(&SymbolLayer::getTextAnchor, "nativeGetTextAnchor"),
METHOD(&SymbolLayer::getTextMaxAngle, "nativeGetTextMaxAngle"),

View File

@@ -80,6 +80,8 @@ public:
jni::Local<jni::Object<jni::ObjectTag>> getTextJustify(jni::JNIEnv&);
jni::Local<jni::Object<jni::ObjectTag>> getTextRadialOffset(jni::JNIEnv&);
jni::Local<jni::Object<jni::ObjectTag>> getTextVariableAnchor(jni::JNIEnv&);
jni::Local<jni::Object<jni::ObjectTag>> getTextAnchor(jni::JNIEnv&);

View File

@@ -153,7 +153,11 @@ global.defaultValue = function (property) {
switch (property.type) {
case 'number':
if (property.default === undefined) {
return 0;
} else {
return property.default;
}
case 'formatted':
case 'string':
return JSON.stringify(property.default || "");

View File

@@ -5,6 +5,4 @@ delete spec.layout_symbol['symbol-sort-key'];
delete spec.layout_symbol['symbol-z-order'].values['auto'];
spec.layout_symbol['symbol-z-order'].default = 'viewport-y';
delete spec.layout_symbol['text-radial-offset'];
delete spec.layout_symbol['text-justify'].values['auto'];
spec.layout_symbol['text-offset'].requires.splice(1, 1); // { "!": "text-radial-offset" }
delete spec.layout_symbol['text-justify'].values['auto'];

View File

@@ -492,6 +492,22 @@ void SymbolLayer::setTextJustify(PropertyValue<TextJustifyType> value) {
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
PropertyValue<float> SymbolLayer::getDefaultTextRadialOffset() {
return TextRadialOffset::defaultValue();
}
PropertyValue<float> SymbolLayer::getTextRadialOffset() const {
return impl().layout.get<TextRadialOffset>();
}
void SymbolLayer::setTextRadialOffset(PropertyValue<float> value) {
if (value == getTextRadialOffset())
return;
auto impl_ = mutableImpl();
impl_->layout.get<TextRadialOffset>() = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
PropertyValue<std::vector<TextVariableAnchorType>> SymbolLayer::getDefaultTextVariableAnchor() {
return TextVariableAnchor::defaultValue();
}
@@ -1341,6 +1357,7 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
TextLineHeight,
TextLetterSpacing,
TextJustify,
TextRadialOffset,
TextVariableAnchor,
TextAnchor,
TextMaxAngle,
@@ -1381,6 +1398,7 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
{ "text-line-height", static_cast<uint8_t>(Property::TextLineHeight) },
{ "text-letter-spacing", static_cast<uint8_t>(Property::TextLetterSpacing) },
{ "text-justify", static_cast<uint8_t>(Property::TextJustify) },
{ "text-radial-offset", static_cast<uint8_t>(Property::TextRadialOffset) },
{ "text-variable-anchor", static_cast<uint8_t>(Property::TextVariableAnchor) },
{ "text-anchor", static_cast<uint8_t>(Property::TextAnchor) },
{ "text-max-angle", static_cast<uint8_t>(Property::TextMaxAngle) },
@@ -1543,7 +1561,7 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
}
if (property == Property::IconSize || property == Property::IconRotate || property == Property::TextSize || property == Property::TextMaxWidth || property == Property::TextLetterSpacing || property == Property::TextRotate) {
if (property == Property::IconSize || property == Property::IconRotate || property == Property::TextSize || property == Property::TextMaxWidth || property == Property::TextLetterSpacing || property == Property::TextRadialOffset || property == Property::TextRotate) {
Error error;
optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false);
if (!typedValue) {
@@ -1575,6 +1593,11 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
return nullopt;
}
if (property == Property::TextRadialOffset) {
setTextRadialOffset(*typedValue);
return nullopt;
}
if (property == Property::TextRotate) {
setTextRotate(*typedValue);
return nullopt;

View File

@@ -147,6 +147,11 @@ struct TextJustify : DataDrivenLayoutProperty<TextJustifyType> {
static TextJustifyType defaultValue() { return TextJustifyType::Center; }
};
struct TextRadialOffset : DataDrivenLayoutProperty<float> {
static constexpr const char *name() { return "text-radial-offset"; }
static float defaultValue() { return 0; }
};
struct TextVariableAnchor : LayoutProperty<std::vector<TextVariableAnchorType>> {
static constexpr const char *name() { return "text-variable-anchor"; }
static std::vector<TextVariableAnchorType> defaultValue() { return { }; }
@@ -289,6 +294,7 @@ class SymbolLayoutProperties : public Properties<
TextLineHeight,
TextLetterSpacing,
TextJustify,
TextRadialOffset,
TextVariableAnchor,
TextAnchor,
TextMaxAngle,