ExpressionBuilder

open class ExpressionBuilder(operator: String) : Expression.Builder

Builder for Expression.

Parameters

operator

compulsory operator field for the builder

Constructors

ExpressionBuilder
Link copied to clipboard
fun ExpressionBuilder(operator: String)

Functions

abs
Link copied to clipboard
fun abs(value: Double)
fun abs(block: Expression.ExpressionBuilder.() -> Unit)

Returns the absolute value of the input.

accumulated
Link copied to clipboard
fun accumulated()

Returns the value of a cluster property accumulated so far. Can only be used in the clusterProperties option of a clustered GeoJSON source.

acos
Link copied to clipboard
fun acos(value: Double)
fun acos(block: Expression.ExpressionBuilder.() -> Unit)

Returns the arccosine of the input.

addArgument
Link copied to clipboard
fun addArgument(expression: Expression): Expression.ExpressionBuilder

Add an Expression to the builder.

all
Link copied to clipboard
fun all(block: Expression.ExpressionBuilder.() -> Unit)

Returns true if all the inputs are true, false otherwise. The inputs are evaluated in order, and evaluation is short-circuiting: once an input expression evaluates to false, the result is false and no further input expressions are evaluated.

any
Link copied to clipboard
fun any(block: Expression.ExpressionBuilder.() -> Unit)

Returns true if any of the inputs are true, false otherwise. The inputs are evaluated in order, and evaluation is short-circuiting: once an input expression evaluates to true, the result is true and no further input expressions are evaluated.

array
Link copied to clipboard
fun array(block: Expression.ExpressionBuilder.() -> Unit)

Asserts that the input is an array (optionally with a specific item type and length). If, when the input expression is evaluated, it is not of the asserted type, then this assertion will cause the whole expression to be aborted.

asin
Link copied to clipboard
fun asin(value: Double)
fun asin(block: Expression.ExpressionBuilder.() -> Unit)

Returns the arcsine of the input.

at
Link copied to clipboard
fun at(block: Expression.ExpressionBuilder.() -> Unit)
fun at(index: Double, array: Expression)

Retrieves an item from an array.

atan
Link copied to clipboard
fun atan(value: Double)
fun atan(block: Expression.ExpressionBuilder.() -> Unit)

Returns the arctangent of the input.

boolean
Link copied to clipboard
fun boolean(block: Expression.ExpressionBuilder.() -> Unit)

Asserts that the input value is a boolean. If multiple values are provided, each one is evaluated in order until a boolean is obtained. If none of the inputs are booleans, the expression is an error.

build
Link copied to clipboard
open fun build(): Expression

Build the Expression with the settings.

ceil
Link copied to clipboard
fun ceil(value: Double)
fun ceil(block: Expression.ExpressionBuilder.() -> Unit)

Returns the smallest integer that is greater than or equal to the input.

coalesce
Link copied to clipboard
fun coalesce(block: Expression.ExpressionBuilder.() -> Unit)

Evaluates each expression in turn until the first valid value is obtained. Invalid values are null and #types-image expressions that are unavailable in the style. If all values are invalid, coalesce returns the first value listed.

collator
Link copied to clipboard
fun collator(block: Expression.CollatorBuilder.() -> Unit)

Returns a collator for use in locale-dependent comparison operations. The case-sensitive and diacritic-sensitive options default to false. The locale argument specifies the IETF language tag of the locale to use. If none is provided, the default locale is used. If the requested locale is not available, the collator will use a system-defined fallback locale. Use resolved-locale to test the results of locale fallback behavior.

color
Link copied to clipboard
fun color(@ColorInt intColor: Int)

Add a color expression to the current expression builder.

concat
Link copied to clipboard
fun concat(vararg values: String)

Returns a string consisting of the concatenation of the inputs.

fun concat(block: Expression.ExpressionBuilder.() -> Unit)

Returns a string consisting of the concatenation of the inputs. Each input is converted to a string as if by to-string.

cos
Link copied to clipboard
fun cos(value: Double)
fun cos(block: Expression.ExpressionBuilder.() -> Unit)

Returns the cosine of the input.

distance
Link copied to clipboard
fun distance(geojson: GeoJson)

Returns the shortest distance in meters between the evaluated feature and the input geometry. The input value can be a valid GeoJSON of type Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, Feature, or FeatureCollection. Distance values returned may vary in precision due to loss in precision from encoding geometries, particularly below zoom level 13.

distanceFromCenter
Link copied to clipboard
fun distanceFromCenter()

Returns the distance of a symbol instance from the center of the map. The distance is measured in pixels divided by the height of the map container. It measures 0 at the center, decreases towards the camera and increase away from the camera. For example, if the height of the map is 1000px, a value of -1 means 1000px away from the center towards the camera, and a value of 1 means a distance of 1000px away from the camera from the center. ["distance-from-center"] may only be used in the filter expression for a symbol layer.

division
Link copied to clipboard
fun division(block: Expression.ExpressionBuilder.() -> Unit)
fun division(first: Double, second: Double)

Returns the result of floating point division of the first input by the second.

downcase
Link copied to clipboard
fun downcase(block: Expression.ExpressionBuilder.() -> Unit)
fun downcase(value: String)

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

e
Link copied to clipboard
fun e()

Returns the mathematical constant e.

eq
Link copied to clipboard
fun eq(block: Expression.ExpressionBuilder.() -> Unit)

Returns true if the input values are equal, false otherwise. The comparison is strictly typed: values of different runtime types are always considered unequal. Cases where the types are known to be different at parse time are considered invalid and will produce a parse error. Accepts an optional collator argument to control locale-dependent string comparisons.

featureState
Link copied to clipboard
fun featureState(block: Expression.ExpressionBuilder.() -> Unit)

Retrieves a property value from the current feature's state. Returns null if the requested property is not present on the feature's state. A feature's state is not part of the GeoJSON or vector tile data, and must be set programmatically on each feature. Features are identified by their id attribute, which must be an integer or a string that can be cast to an integer. Note that "feature-state" can only be used with paint properties that support data-driven styling.

floor
Link copied to clipboard
fun floor(value: Double)
fun floor(block: Expression.ExpressionBuilder.() -> Unit)

Returns the largest integer that is less than or equal to the input.

format
Link copied to clipboard
fun format(block: Expression.FormatBuilder.() -> Unit)

Returns a formatted string for displaying mixed-format text in the text-field property. The input may contain a string literal or expression, including an #types-image expression. Strings may be followed by a style override object that supports the following properties:

geometryType
Link copied to clipboard
fun geometryType()

Returns the feature's geometry type: Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon. Multi- feature types are only returned in GeoJSON sources. When working with vector tile sources, use the singular forms.

get
Link copied to clipboard
fun get(block: Expression.ExpressionBuilder.() -> Unit)

Retrieves a property value from the current feature's properties, or from another object if a second argument is provided. Returns null if the requested property is missing.

fun get(key: String)

Retrieves a property value from the current feature's properties. Returns null if the requested property is missing.

fun get(key: String, expression: Expression)

Retrieves a property value from the current feature's properties, or from another object if a second argument is provided. Returns null if the requested property is missing.

gt
Link copied to clipboard
fun gt(block: Expression.ExpressionBuilder.() -> Unit)

Returns true if the first input is strictly greater than the second, false otherwise. The arguments are required to be either both strings or both numbers; if during evaluation they are not, expression evaluation produces an error. Cases where this constraint is known not to hold at parse time are considered in valid and will produce a parse error. Accepts an optional collator argument to control locale-dependent string comparisons.

gte
Link copied to clipboard
fun gte(block: Expression.ExpressionBuilder.() -> Unit)

Returns true if the first input is greater than or equal to the second, false otherwise. The arguments are required to be either both strings or both numbers; if during evaluation they are not, expression evaluation produces an error. Cases where this constraint is known not to hold at parse time are considered in valid and will produce a parse error. Accepts an optional collator argument to control locale-dependent string comparisons.

has
Link copied to clipboard
fun has(block: Expression.ExpressionBuilder.() -> Unit)
fun has(string: String, expression: Expression)

Tests for the presence of an property value in the current feature's properties, or from another object if a second argument is provided.

fun has(string: String)

Tests for the presence of an property value in the current feature's properties

heatmapDensity
Link copied to clipboard
fun heatmapDensity()

Returns the kernel density estimation of a pixel in a heatmap layer, which is a relative measure of how many data points are crowded around a particular pixel. Can only be used in the heatmap-color property.

id
Link copied to clipboard
fun id()

Returns the feature's id, if it has one.

image
Link copied to clipboard
fun image(block: Expression.ExpressionBuilder.() -> Unit)

Returns a /mapbox-gl-js/style-spec/types/#resolvedimage for use in /mapbox-gl-js/style-spec/layers/#layout-symbol-icon-image, --pattern entries, and as a section in the #types-format expression. A #coalesce expression containing image expressions will evaluate to the first listed image that is currently in the style. This validation process is synchronous and requires the image to have been added to the style before requesting it in the 'image' argument.

indexOf
Link copied to clipboard
fun indexOf(block: Expression.ExpressionBuilder.() -> Unit)

Returns the first position at which an item can be found in an array or a substring can be found in a string, or -1 if the input cannot be found. Accepts an optional index from where to begin the search.

inExpression
Link copied to clipboard
fun inExpression(block: Expression.ExpressionBuilder.() -> Unit)

Determines whether an item exists in an array or a substring exists in a string. In the specific case when the second and third arguments are string literals, you must wrap at least one of them in a #types-literal expression to hint correct interpretation to the #type-system.

fun inExpression(needle: Double, haystack: Expression)
fun inExpression(needle: String, haystack: Expression)

Determines whether an item exists in an array or a substring exists in a string.

interpolate
Link copied to clipboard
fun interpolate(block: Expression.InterpolatorBuilder.() -> Unit)

Produces continuous, smooth results by interpolating between pairs of input and output values ("stops"). The input may be any numeric expression (e.g., ["get", "population"]). Stop inputs must be numeric literals in strictly ascending order. The output type must be number, array<number>, or color.

isSupportedScript
Link copied to clipboard
fun isSupportedScript(block: Expression.ExpressionBuilder.() -> Unit)
fun isSupportedScript(script: String)

Returns true if the input string is expected to render legibly. Returns false if the input string contains sections that cannot be rendered without potential loss of meaning (e.g. Indic scripts that require complex text shaping, or right-to-left scripts if the the mapbox-gl-rtl-text plugin is not in use in Mapbox GL JS).

length
Link copied to clipboard
fun length(block: Expression.ExpressionBuilder.() -> Unit)

Returns the length of an array or string.

fun length(string: String)

Gets the length of an string.

letExpression
Link copied to clipboard
fun letExpression(block: Expression.ExpressionBuilder.() -> Unit)

Binds expressions to named variables, which can then be referenced in the result expression using "var", "variable_name".

lineProgress
Link copied to clipboard
fun lineProgress()

Returns the progress along a gradient line. Can only be used in the line-gradient property.

literal
Link copied to clipboard
fun literal(value: HashMap<String, Any>)
fun literal(value: Boolean)
fun literal(value: Double)
fun literal(value: Long)
fun literal(value: String)
fun literal(value: List<Any>)

Provides a literal array or object value.

ln
Link copied to clipboard
fun ln(value: Double)
fun ln(block: Expression.ExpressionBuilder.() -> Unit)

Returns the natural logarithm of the input.

ln2
Link copied to clipboard
fun ln2()

Returns mathematical constant ln(2).

log10
Link copied to clipboard
fun log10(value: Double)
fun log10(block: Expression.ExpressionBuilder.() -> Unit)

Returns the base-ten logarithm of the input.

log2
Link copied to clipboard
fun log2(value: Double)
fun log2(block: Expression.ExpressionBuilder.() -> Unit)

Returns the base-two logarithm of the input.

lt
Link copied to clipboard
fun lt(block: Expression.ExpressionBuilder.() -> Unit)

Returns true if the first input is strictly less than the second, false otherwise. The arguments are required to be either both strings or both numbers; if during evaluation they are not, expression evaluation produces an error. Cases where this constraint is known not to hold at parse time are considered in valid and will produce a parse error. Accepts an optional collator argument to control locale-dependent string comparisons.

lte
Link copied to clipboard
fun lte(block: Expression.ExpressionBuilder.() -> Unit)

Returns true if the first input is less than or equal to the second, false otherwise. The arguments are required to be either both strings or both numbers; if during evaluation they are not, expression evaluation produces an error. Cases where this constraint is known not to hold at parse time are considered in valid and will produce a parse error. Accepts an optional collator argument to control locale-dependent string comparisons.

match
Link copied to clipboard
fun match(block: Expression.ExpressionBuilder.() -> Unit)

Selects the output for which the label value matches the input value, or the fallback value if no match is found. The input can be any expression (for example, ["get", "building_type"]). Each label must be unique, and must be either:

max
Link copied to clipboard
fun max(vararg values: Double)
fun max(block: Expression.ExpressionBuilder.() -> Unit)

Returns the maximum value of the inputs.

min
Link copied to clipboard
fun min(vararg values: Double)
fun min(block: Expression.ExpressionBuilder.() -> Unit)

Returns the minimum value of the inputs.

mod
Link copied to clipboard
fun mod(block: Expression.ExpressionBuilder.() -> Unit)
fun mod(first: Double, second: Double)

Returns the remainder after integer division of the first input by the second.

neq
Link copied to clipboard
fun neq(block: Expression.ExpressionBuilder.() -> Unit)

Returns true if the input values are not equal, false otherwise. The comparison is strictly typed: values of different runtime types are always considered unequal. Cases where the types are known to be different at parse time are considered invalid and will produce a parse error. Accepts an optional collator argument to control locale-dependent string comparisons.

not
Link copied to clipboard
fun not(bool: Boolean)
fun not(block: Expression.ExpressionBuilder.() -> Unit)

Logical negation. Returns true if the input is false, and false if the input is true.

number
Link copied to clipboard
fun number(block: Expression.ExpressionBuilder.() -> Unit)

Asserts that the input value is a number. If multiple values are provided, each one is evaluated in order until a number is obtained. If none of the inputs are numbers, the expression is an error.

numberFormat
Link copied to clipboard
fun numberFormat(input: Expression, block: Expression.NumberFormatBuilder.() -> Unit)

Converts the input number into a string representation using the providing formatting rules. If set, the locale argument specifies the locale to use, as a BCP 47 language tag. If set, the currency argument specifies an ISO 4217 code to use for currency-style formatting. If set, the unit argument specifies a simple ECMAScript unit to use for unit-style formatting. If set, the min-fraction-digits and max-fraction-digits arguments specify the minimum and maximum number of fractional digits to include.

fun numberFormat(value: Double, block: Expression.NumberFormatBuilder.() -> Unit)

Converts the input number into a string representation using the providing formatting rules. If set, the locale argument specifies the locale to use, as a BCP 47 language tag. If set, the currency argument specifies an ISO 4217 code to use for currency-style formatting. If set, the min-fraction-digits and max-fraction-digits arguments specify the minimum and maximum number of fractional digits to include.

objectExpression
Link copied to clipboard
fun objectExpression(block: Expression.ExpressionBuilder.() -> Unit)

Asserts that the input value is an object. If multiple values are provided, each one is evaluated in order until an object is obtained. If none of the inputs are objects, the expression is an error.

pi
Link copied to clipboard
fun pi()

Returns the mathematical constant pi.

pitch
Link copied to clipboard
fun pitch()

Returns the current pitch in degrees. ["pitch"] may only be used in the filter expression for a symbol layer.

pow
Link copied to clipboard
fun pow(block: Expression.ExpressionBuilder.() -> Unit)
fun pow(first: Double, second: Double)

Returns the result of raising the first input to the power specified by the second.

product
Link copied to clipboard
fun product(vararg double: Double)
fun product(block: Expression.ExpressionBuilder.() -> Unit)

Returns the product of the inputs.

properties
Link copied to clipboard
fun properties()

Returns the feature properties object. Note that in some cases, it may be more efficient to use ["get", "property_name"] directly.

resolvedLocale
Link copied to clipboard
fun resolvedLocale(block: Expression.ExpressionBuilder.() -> Unit)

Returns the IETF language tag of the locale being used by the provided collator. This can be used to determine the default system locale, or to determine if a requested locale was successfully loaded.

rgb
Link copied to clipboard
fun rgb(block: Expression.ExpressionBuilder.() -> Unit)

Creates a color value from red, green, and blue components, which must range between 0 and 255, and an alpha component of 1. If any component is out of range, the expression is an error.

fun rgb(red: Double, green: Double, blue: Double)

Add a RGB color expression from numbers to the current expression builder.

rgba
Link copied to clipboard
fun rgba(block: Expression.ExpressionBuilder.() -> Unit)

Creates a color value from red, green, blue components, which must range between 0 and 255, and an alpha component which must range between 0 and 1. If any component is out of range, the expression is an error.

fun rgba(red: Double, green: Double, blue: Double, alpha: Double)

Add a RGBA color expression from numbers to the current expression builder.

round
Link copied to clipboard
fun round(value: Double)
fun round(block: Expression.ExpressionBuilder.() -> Unit)

Rounds the input to the nearest integer. Halfway values are rounded away from zero. For example, ["round", -1.5] evaluates to -2.

sin
Link copied to clipboard
fun sin(value: Double)
fun sin(block: Expression.ExpressionBuilder.() -> Unit)

Returns the sine of the input.

skyRadialProgress
Link copied to clipboard
fun skyRadialProgress()

Returns the distance of a point on the sky from the sun position. Returns 0 at sun position and 1 when the distance reaches sky-gradient-radius. Can only be used in the sky-gradient property.

slice
Link copied to clipboard
fun slice(block: Expression.ExpressionBuilder.() -> Unit)

Returns an item from an array or a substring from a string from a specified start index, or between a start index and an end index if set. The return value is inclusive of the start index but not of the end index.

sqrt
Link copied to clipboard
fun sqrt(value: Double)
fun sqrt(block: Expression.ExpressionBuilder.() -> Unit)

Returns the square root of the input.

step
Link copied to clipboard
fun step(block: Expression.ExpressionBuilder.() -> Unit)

Produces discrete, stepped results by evaluating a piecewise-constant function defined by pairs of input and output values ("stops"). The input may be any numeric expression (e.g., ["get", "population"]). Stop inputs must be numeric literals in strictly ascending order. Returns the output value of the stop just less than the input, or the first output if the input is less than the first stop.

stop
Link copied to clipboard
fun stop(block: Expression.ExpressionBuilder.() -> Unit)
fun stop(key: Double, block: Expression.ExpressionBuilder.() -> Unit)

Add a pair of input and output values. The input may be any numeric expression (e.g., ["get", "population"]). Stop inputs must be numeric literals in strictly ascending order. Returns the output value of the stop just less than the input, or the first output if the input is less than the first stop.

string
Link copied to clipboard
fun string(block: Expression.ExpressionBuilder.() -> Unit)

Asserts that the input value is a string. If multiple values are provided, each one is evaluated in order until a string is obtained. If none of the inputs are strings, the expression is an error.

subtract
Link copied to clipboard
fun subtract(value: Double)

Returns the result of subtracting it from 0.

fun subtract(block: Expression.ExpressionBuilder.() -> Unit)

For two inputs, returns the result of subtracting the second input from the first. For a single input, returns the result of subtracting it from 0.

fun subtract(first: Double, second: Double)

Returns the result of subtracting the second input from the first.

sum
Link copied to clipboard
fun sum(vararg double: Double)
fun sum(block: Expression.ExpressionBuilder.() -> Unit)

Returns the sum of the inputs.

switchCase
Link copied to clipboard
fun switchCase(block: Expression.ExpressionBuilder.() -> Unit)

Selects the first output whose corresponding test condition evaluates to true, or the fallback value otherwise.

tan
Link copied to clipboard
fun tan(value: Double)
fun tan(block: Expression.ExpressionBuilder.() -> Unit)

Returns the tangent of the input.

toBoolean
Link copied to clipboard
fun toBoolean(block: Expression.ExpressionBuilder.() -> Unit)

Converts the input value to a boolean. The result is false when then input is an empty string, 0, false, null, or NaN; otherwise it is true.

toColor
Link copied to clipboard
fun toColor(block: Expression.ExpressionBuilder.() -> Unit)

Converts the input value to a color. If multiple values are provided, each one is evaluated in order until the first successful conversion is obtained. If none of the inputs can be converted, the expression is an error.

toNumber
Link copied to clipboard
fun toNumber(block: Expression.ExpressionBuilder.() -> Unit)

Converts the input value to a number, if possible. If the input is null or false, the result is 0. If the input is true, the result is 1. If the input is a string, it is converted to a number as specified by the "ToNumber Applied to * the String Type" algorithm of the ECMAScript Language Specification. If multiple values are provided, each one is evaluated in order until the first successful conversion is obtained. If none of the inputs can be converted, the expression is an error.

toRgba
Link copied to clipboard
fun toRgba(block: Expression.ExpressionBuilder.() -> Unit)

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

toString
Link copied to clipboard
fun toString(block: Expression.ExpressionBuilder.() -> Unit)

Converts the input value to a string. If the input is null, the result is "". If the input is a #types-boolean, the result is "true" or "false". If the input is a number, it is converted to a string as specified by the "NumberToString" algorithm of the ECMAScript Language Specification. If the input is a #color, it is converted to a string of the form "rgba(r,g,b,a)", where r, g, and b are numerals ranging from 0 to 255, and a ranges from 0 to 1. If the input is an #types-image expression, 'to-string' returns the image name. Otherwise, the input is converted to a string in the format specified by the JSON.stringify function of the ECMAScript Language Specification.

typeofExpression
Link copied to clipboard
fun typeofExpression(block: Expression.ExpressionBuilder.() -> Unit)

Returns a string describing the type of the given value.

upcase
Link copied to clipboard
fun upcase(block: Expression.ExpressionBuilder.() -> Unit)
fun upcase(value: String)

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

varExpression
Link copied to clipboard
fun varExpression(block: Expression.ExpressionBuilder.() -> Unit)
fun varExpression(value: String)

References variable bound using "let".

within
Link copied to clipboard
fun within(geometry: Geometry)

Returns true if the evaluated feature is fully contained inside a boundary of the input geometry, false otherwise. The input value can be a valid GeoJSON of type Polygon, MultiPolygon, Feature, or FeatureCollection. Supported features for evaluation:

zoom
Link copied to clipboard
fun zoom()

Returns the current zoom level. Note that in style layout and paint properties, "zoom" may only appear as the input to a top-level "step" or "interpolate" expression.

Inheritors

Expression
Link copied to clipboard