Expression

sealed interface Expression<out T : ExpressionValue>(source)

An Expression that evaluates to a value of type T.

The functions to create expressions are defined in the dev.sargunv.maplibrecompose.expressions.dsl package.

Most functions are named the same as in the MapLibre style specification, a few have been renamed to be Kotlin-idiomatic or made into extension functions (to an Expression).

Function overview

Literals

  • const - literal expression

  • nil - literal null expression

Decision

Ramps, scales, curves

Math

Inputs, feature data

  • zoom - get current zoom level

  • heatmapDensity - get heatmap density

  • feature.get - get feature attribute

  • feature.has - check presence of feature attribute

  • feature.properties - get all feature attributes

  • feature.state - get property from feature state

  • feature.geometryType - get feature's geometry type

  • feature.id - get feature id

  • feature.lineProgress - progress along a gradient line

  • feature.accumulated - value of accumulated cluster property so far

  • feature.within - check whether feature is within geometry

  • feature.distance - distance of feature to geometry

Collections

  • Expression<ListValue<T>>.get - get value at index

  • Expression<ListValue<T>>.contains - check whether list contains value

  • Expression<ListValue<T>>.indexOf - check where the list contains value

  • Expression<ListValue<T>>.slice - return a sub-list

  • Expression<ListValue<T>>.length - list length

  • Expression<MapValue<T>>.get - get value

  • Expression<MapValue<T>>.has - check presence of key

Strings

  • Expression<StringValue>.contains - check if string contains another

  • Expression<StringValue>.indexOf - check where string contains another

  • Expression<StringValue>.substring - return a sub-string

  • Expression<StringValue>.length - string length

  • Expression<StringValue>. isScriptSupported - whether string is expected to render correctly

  • Expression<StringValue>.uppercase - uppercase the string

  • Expression<StringValue>.lowercase - lowercase the string

  • Expression<StringValue>.+ - concatenate the string

  • resolvedLocale - return locale

Format

  • format - format text with spans of different text styling

Color

Image

  • image - image for use in iconImage

Variable binding

Inheritors

Properties

Link copied to clipboard

Converts a numeric Expression to a DpValue expression.

Link copied to clipboard

Converts a numeric Expression to an TextUnitValue expression in EM

Link copied to clipboard

Converts a numeric Expression in milliseconds to a MillisecondsValue expression.

Link copied to clipboard

Converts a numeric Expression in seconds to a MillisecondsValue expression.

Link copied to clipboard

Converts a numeric Expression to an TextUnitValue expression in SP.

Functions

Link copied to clipboard

Returns whether both this and other expressions are true.

Link copied to clipboard
fun Expression<*>.asBoolean(vararg fallbacks: Expression<*>): Expression<BooleanValue>

Asserts that this value is a boolean.

Link copied to clipboard

Asserts that this is a list of numbers of length 2.

Link copied to clipboard
inline fun <T : Enum<T>, EnumValue<T>> Expression<*>.asEnum(vararg fallbacks: Expression<*>): Expression<T>

Asserts that this value is an entry of the enum specified by T.

Link copied to clipboard
fun Expression<*>.asList(type: Expression<ExpressionType> = nil(), length: Expression<IntValue> = nil()): Expression<ListValue<*>>

Asserts that this is a list (optionally with a specific item type and length).

Link copied to clipboard
fun Expression<*>.asMap(vararg fallbacks: Expression<*>): Expression<MapValue<*>>

Asserts that this value is a map.

Link copied to clipboard
fun Expression<*>.asNumber(vararg fallbacks: Expression<*>): Expression<FloatValue>

Asserts that this value is a number.

Link copied to clipboard

Asserts that this is a list of numbers of length 2.

Link copied to clipboard

Asserts that this is a list of numbers of length 4.

Link copied to clipboard
fun Expression<*>.asString(vararg fallbacks: Expression<*>): Expression<StringValue>

Asserts that this value is a string.

Link copied to clipboard
fun <U, V : NumberValue<U>> Expression<*>.asVector(length: Expression<IntValue> = nil()): Expression<V>

Asserts that this is a list of numbers, optionally with a specific length.

Link copied to clipboard
open fun <X : ExpressionValue> cast(): Expression<X>
Link copied to clipboard

Transform this expression into the equivalent CompiledExpression.

Link copied to clipboard

Returns whether this list contains the item.

@JvmName(name = "containsString")
fun Expression<StringValue>.contains(substring: String): Expression<BooleanValue>

Returns whether this string contains the substring.

Link copied to clipboard

Converts this expression to a boolean expression.

Link copied to clipboard

Converts this expression to a color expression.

Link copied to clipboard

Converts this expression to a number.

Link copied to clipboard

Converts this expression to a string.

Link copied to clipboard
@JvmName(name = "divUnitBoth")
operator fun <U, V : NumberValue<U>> Expression<V>.div(divisor: Expression<V>): Expression<FloatValue>
@JvmName(name = "divUnitLeftOnly")
operator fun <U, V : NumberValue<U>> Expression<V>.div(divisor: Expression<FloatValue>): Expression<V>

Returns the result of floating point division of this number expression by divisor.

Link copied to clipboard

Returns whether this expression is equal to other.

Link copied to clipboard
fun Expression<NumberValue<*>>.formatToString(    locale: Expression<StringValue>? = null,     currency: Expression<StringValue>? = null,     minFractionDigits: Expression<IntValue>? = null,     maxFractionDigits: Expression<IntValue>? = null): Expression<StringValue>
fun Expression<NumberValue<*>>.formatToString(    locale: String? = null,     currency: String? = null,     minFractionDigits: Int? = null,     maxFractionDigits: Int? = null): Expression<StringValue>

Converts this number into a string representation using the provided formatting rules.

Link copied to clipboard
@JvmName(name = "getAt")
operator fun <T : ExpressionValue> Expression<ListValue<T>>.get(index: Expression<IntValue>): Expression<T>
@JvmName(name = "getAt")
operator fun <T : ExpressionValue> Expression<ListValue<T>>.get(index: Int): Expression<T>

Returns the item at index.

Returns the value corresponding the given key or null if it is not present in this map.

Link copied to clipboard

Returns whether this expression is strictly greater than other.

Link copied to clipboard

Returns whether this expression is greater than or equal to other.

Link copied to clipboard

Returns whether the given key is in this map.

Link copied to clipboard
@JvmName(name = "indexOfList")
fun <T : ExpressionValue> Expression<ListValue<T>>.indexOf(    item: Expression<T>,     startIndex: Expression<IntValue>? = null): Expression<IntValue>
@JvmName(name = "indexOfList")
fun <T : ExpressionValue> Expression<ListValue<T>>.indexOf(item: Expression<T>, startIndex: Int? = null): Expression<IntValue>

Returns the first index at which the item is located in this list, or -1 if it cannot be found. Accepts an optional startIndex from where to begin the search.

@JvmName(name = "indexOfString")
fun Expression<StringValue>.indexOf(substring: Expression<StringValue>, startIndex: Expression<IntValue>? = null): Expression<IntValue>
@JvmName(name = "indexOfString")
fun Expression<StringValue>.indexOf(substring: String, startIndex: Int? = null): Expression<IntValue>

Returns the first index at which the substring is located in this string, or -1 if it cannot be found. Accepts an optional startIndex from where to begin the search.

Link copied to clipboard

Returns true if this string is expected to render legibly. Returns false if this string contains sections that cannot be rendered without potential loss of meaning (e.g. Indic scripts that require complex text shaping).

Link copied to clipboard
@JvmName(name = "lengthOfList")
fun Expression<ListValue<*>>.length(): Expression<IntValue>

Gets the length of a this list.

@JvmName(name = "lengthOfString")
fun Expression<StringValue>.length(): Expression<IntValue>

Gets the length of this string.

Link copied to clipboard

Returns this string converted to lowercase. Follows the Unicode Default Case Conversion algorithm and the locale-insensitive case mappings in the Unicode Character Database.

Link copied to clipboard

Returns whether this expression is strictly less than other.

Link copied to clipboard

Returns whether this string expression is less than or equal to other.

Link copied to clipboard
operator fun <U, V : NumberValue<U>> Expression<V>.minus(other: Expression<NumberValue<U>>): Expression<V>

Returns the result of subtracting other from this number expression.

Link copied to clipboard

Returns whether this expression is not equal to other.

Link copied to clipboard
@JvmName(name = "notOperator")
operator fun Expression<BooleanValue>.not(): Expression<BooleanValue>

Negates this expression.

Link copied to clipboard

Returns whether any of this or the other expressions are true.

Link copied to clipboard
operator fun <U, V : NumberValue<U>> Expression<V>.plus(other: Expression<V>): Expression<V>

Returns the sum of this number expression with other.

Concatenates this string expression with other.

Link copied to clipboard

Returns the result of raising this number expression to the power of exponent.

Link copied to clipboard
operator fun <U, V : NumberValue<U>> Expression<V>.rem(divisor: Expression<IntValue>): Expression<V>

Returns the remainder after integer division of this number expression by divisor.

Link copied to clipboard
fun <T : ExpressionValue> Expression<ListValue<T>>.slice(    startIndex: Expression<IntValue>,     endIndex: Expression<IntValue>? = null): Expression<ListValue<T>>
fun <T : ExpressionValue> Expression<ListValue<T>>.slice(startIndex: Int, endIndex: Int? = null): Expression<ListValue<T>>

Returns the items in this list from the startIndex (inclusive) to the end of this list if endIndex is not specified or null, otherwise to endIndex (exclusive).

Link copied to clipboard
fun Expression<StringValue>.substring(startIndex: Int, endIndex: Int? = null): Expression<StringValue>

Returns a substring from this string from the startIndex (inclusive) to the end of the string if endIndex is not specified or null, otherwise to endIndex (exclusive).

Link copied to clipboard
@JvmName(name = "timesUnitLeft")
operator fun <U, V : NumberValue<U>> Expression<V>.times(other: Expression<FloatValue>): Expression<V>
@JvmName(name = "timesUnitRight")
operator fun <U, V : NumberValue<U>> Expression<FloatValue>.times(other: Expression<V>): Expression<V>

Returns the product of this number expression with other.

Link copied to clipboard

Returns a four-element list, containing the color's red, green, blue, and alpha components, in that order.

Link copied to clipboard

Returns a string describing the type of this expression.

Link copied to clipboard
operator fun <U, V : NumberValue<U>> Expression<V>.unaryMinus(): Expression<V>

Negates this number expression.

Link copied to clipboard

Returns this string converted to uppercase. Follows the Unicode Default Case Conversion algorithm and the locale-insensitive case mappings in the Unicode Character Database.

Link copied to clipboard
abstract fun visit(block: (Expression<*>) -> Unit)