Operators and utilities used for style expressions
Members
-
module:ol/style/expressions.ValueTypes{number}
-
Possible inferred types from a given value or expression. Note: these are binary flags.
Type Definitions
-
ExpressionValue{Array.<*>} {module:ol/color~Color} {string} {number} {boolean}
-
Base type used for literal style parameters; can be a number literal or the output of an operator, which in turns takes
module:ol/style/expressions~ExpressionValuearguments.The following operators can be used:
Reading operators:
['band', bandIndex, xOffset, yOffset]For tile layers only. Fetches pixel values from bandbandIndexof the source's data. The firstbandIndexof the source data is1. Fetched values are in the 0..1 range.module:ol/source/TileImage~TileImagesources have 4 bands: red, green, blue and alpha.module:ol/source/DataTile~DataTileSourcesources can have any number of bands, depending on the underlying data source andconfiguration.xOffsetandyOffsetare optional and allow specifying pixel offsets for x and y. This is used for sampling data from neighboring pixels.['get', 'attributeName']fetches a feature attribute (it will be prefixed bya_in the shader) Note: those will be taken from the attributes provided to the renderer['resolution']returns the current resolution['time']returns the time in seconds since the creation of the layer['var', 'varName']fetches a value from the style variables, or 0 if undefined['zoom']returns the current zoom level
Math operators:
['*', value1, value2]multipliesvalue1byvalue2['/', value1, value2]dividesvalue1byvalue2['+', value1, value2]addsvalue1andvalue2['-', value1, value2]subtractsvalue2fromvalue1['clamp', value, low, high]clampsvaluebetweenlowandhigh['%', value1, value2]returns the result ofvalue1 % value2(modulo)['^', value1, value2]returns the value ofvalue1raised to thevalue2power['abs', value1]returns the absolute value ofvalue1['sin', value1]returns the sine ofvalue1['cos', value1]returns the cosine ofvalue1['atan', value1, value2]returnsatan2(value1, value2). Ifvalue2is not provided, returnsatan(value1)
Transform operators:
['case', condition1, output1, ...conditionN, outputN, fallback]selects the first output whose corresponding condition evaluates totrue. If no match is found, returns thefallbackvalue. All conditions should beboolean, output and fallback can be any kind.['match', input, match1, output1, ...matchN, outputN, fallback]compares theinputvalue against all providedmatchXvalues, returning the output associated with the first valid match. If no match is found, returns thefallbackvalue.inputandmatchXvalues must all be of the same type, and can benumberorstring.outputXandfallbackvalues must be of the same type, and can be of any kind.['interpolate', interpolation, input, stop1, output1, ...stopN, outputN]returns a value by interpolating between pairs of inputs and outputs;interpolationcan either be['linear']or['exponential', base]wherebaseis the rate of increase from stop A to stop B (i.e. power to which the interpolation ratio is raised); a value of 1 is equivalent to['linear'].inputandstopXvalues must all be of typenumber.outputXvalues can benumberorcolorvalues. Note:inputwill be clamped betweenstop1andstopN, meaning that all output values will be comprised betweenoutput1andoutputN.
Logical operators:
['<', value1, value2]returnstrueifvalue1is strictly lower thanvalue2, orfalseotherwise.['<=', value1, value2]returnstrueifvalue1is lower than or equalsvalue2, orfalseotherwise.['>', value1, value2]returnstrueifvalue1is strictly greater thanvalue2, orfalseotherwise.['>=', value1, value2]returnstrueifvalue1is greater than or equalsvalue2, orfalseotherwise.['==', value1, value2]returnstrueifvalue1equalsvalue2, orfalseotherwise.['!=', value1, value2]returnstrueifvalue1does not equalvalue2, orfalseotherwise.['!', value1]returnsfalseifvalue1istrueor greater than0, ortrueotherwise.['all', value1, value2, ...]returnstrueif all the inputs aretrue,falseotherwise.['any', value1, value2, ...]returnstrueif any of the inputs aretrue,falseotherwise.['between', value1, value2, value3]returnstrueifvalue1is contained betweenvalue2andvalue3(inclusively), orfalseotherwise.
Conversion operators:
['array', value1, ...valueN]creates a numerical array fromnumbervalues; please note that the amount of values can currently only be 2, 3 or 4.['color', red, green, blue, alpha]creates acolorvalue fromnumbervalues; thealphaparameter is optional; if not specified, it will be set to 1. Note:red,greenandbluecomponents must be values between 0 and 255;alphabetween 0 and 1.
Values can either be literals or another operator, as they will be evaluated recursively. Literal values can be of the following types:
booleannumberstringmodule:ol/color~Color
-
Operator{Object}
-
An operator declaration must contain two methods:
getReturnTypewhich returns a type based on the operator arguments, andtoGlslwhich returns a GLSL-compatible string. Note: both methods can process arguments recursively.Properties:
Name Type Description getReturnTypefunction Returns one or several types
toGlslfunction Returns a GLSL-compatible string Note: takes in an optional type hint as 3rd parameter
-
ParsingContext{Object}
-
Context available during the parsing of an expression.
Properties:
Name Type Argument Description inFragmentShaderboolean <optional>
If false, means the expression output should be made for a vertex shader
variablesArray.<string> List of variables used in the expression; contains unprefixed names
attributesArray.<string> List of attributes used in the expression; contains unprefixed names
stringLiteralsMapObject.<string, number> This object maps all encountered string values to a number
bandCountnumber <optional>
Number of bands per pixel.
OpenLayers