Add array support for icon-padding (#2845)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "collection.hpp"
|
||||
#include "../style/formatted.hpp"
|
||||
|
||||
#include <mbgl/style/conversion/stringify.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -33,6 +34,16 @@ Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, Color>::o
|
||||
return jni::Make<jni::String>(env, value.stringify());
|
||||
}
|
||||
|
||||
Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, Padding>::operator()(
|
||||
jni::JNIEnv& env, const Padding& value) const {
|
||||
const auto values = value.toArray();
|
||||
auto result = jni::Array<jni::Float>::New(env, values.size());
|
||||
for (size_t i = 0; i < values.size(); i++) {
|
||||
result.Set(env, i, jni::Box(env, values[i]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, style::expression::Formatted>::operator()(
|
||||
jni::JNIEnv& env, const style::expression::Formatted& value) const {
|
||||
return Formatted::New(env, value);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "conversion.hpp"
|
||||
|
||||
#include <mbgl/util/color.hpp>
|
||||
#include <mbgl/util/padding.hpp>
|
||||
#include <mbgl/util/enum.hpp>
|
||||
|
||||
#include <mbgl/style/expression/formatted.hpp>
|
||||
@@ -57,6 +58,11 @@ struct Converter<jni::Local<jni::Object<>>, Color> {
|
||||
Result<jni::Local<jni::Object<>>> operator()(jni::JNIEnv& env, const Color& value) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<jni::Local<jni::Object<>>, Padding> {
|
||||
Result<jni::Local<jni::Object<>>> operator()(jni::JNIEnv& env, const Padding& value) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<jni::Local<jni::Object<>>, style::expression::Formatted> {
|
||||
Result<jni::Local<jni::Object<>>> operator()(jni::JNIEnv& env, const style::expression::Formatted& value) const;
|
||||
|
||||
@@ -3688,6 +3688,20 @@ public class Expression {
|
||||
return new Expression("to-color", input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts input value to a padding.
|
||||
*
|
||||
* If the input is a number or an array of numbers padding is created following
|
||||
* the same pattern as CSS padding. See <a href="https://maplibre.org/maplibre-style-spec/types/#padding">Style specification</a>.
|
||||
* Otherwise, the expression is an error.
|
||||
*
|
||||
* @param input expression input
|
||||
* @return expression
|
||||
*/
|
||||
public static Expression toPadding(@NonNull Expression input) {
|
||||
return new Expression("to-padding", input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds input to named variables,
|
||||
* which can then be referenced in the result expression using {@link #var(String)} or {@link #var(Expression)}.
|
||||
|
||||
@@ -2050,18 +2050,18 @@ The unit is in density-independent pixels only for SDF sprites that were created
|
||||
/**
|
||||
* Size of additional area round the icon bounding box used for detecting symbol collisions.
|
||||
*
|
||||
* @param value a Float value
|
||||
* @return property wrapper around Float
|
||||
* @param value a Float[] value
|
||||
* @return property wrapper around Float[]
|
||||
*/
|
||||
public static PropertyValue<Float> iconPadding(Float value) {
|
||||
public static PropertyValue<Float[]> iconPadding(Float[] value) {
|
||||
return new LayoutPropertyValue<>("icon-padding", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Size of additional area round the icon bounding box used for detecting symbol collisions.
|
||||
*
|
||||
* @param value a Float value
|
||||
* @return property wrapper around Float
|
||||
* @param value a Float[] value
|
||||
* @return property wrapper around Float[]
|
||||
*/
|
||||
public static PropertyValue<Expression> iconPadding(Expression value) {
|
||||
return new LayoutPropertyValue<>("icon-padding", value);
|
||||
|
||||
@@ -316,13 +316,13 @@ public class SymbolLayer extends Layer {
|
||||
/**
|
||||
* Get the IconPadding property
|
||||
*
|
||||
* @return property wrapper value around Float
|
||||
* @return property wrapper value around Float[]
|
||||
*/
|
||||
@NonNull
|
||||
@SuppressWarnings("unchecked")
|
||||
public PropertyValue<Float> getIconPadding() {
|
||||
public PropertyValue<Float[]> getIconPadding() {
|
||||
checkThread();
|
||||
return (PropertyValue<Float>) new PropertyValue("icon-padding", nativeGetIconPadding());
|
||||
return (PropertyValue<Float[]>) new PropertyValue("icon-padding", nativeGetIconPadding());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1124,6 +1124,14 @@ class ExpressionTest {
|
||||
Assert.assertTrue("expression should match", Arrays.deepEquals(expected, actual))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testToPadding() {
|
||||
val expected = arrayOf<Any>("to-padding", "value")
|
||||
val actual = Expression.toPadding(Expression.literal("value")).toArray()
|
||||
Assert.assertTrue("expression should match", Arrays.deepEquals(expected, actual))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLet() {
|
||||
|
||||
Reference in New Issue
Block a user