{ //required"alphaMultiplier":1,//A float between 0 and 1"radius":valueMapping,//A mapping that assigns a float"width":valueMapping,//A mapping that assigns a float"fill": colorMapping/iconMapping/patternMapping ,//A mapping that assigns a hex color, pattern or icon//optional"dashedLine":[valueMapping, valueMapping],//An array with two mappings that assign a float"borderColor":colorMapping,//A mapping that assigns a hex color"elevation":valueMapping,//A mapping that assings a value}
Aside from the alphaMultiplier which should be a float, all properties in the parameters should be mappings. These mappings should be objects. There is a couple of mapping types you can use. All of these types are listed in the table below.
//Sent an expression to a color by hashing it, this mapping can only be used to assing hex colors{"type":"hashMap",//should be hashMap"expressionObject": {"expression":"2*property1+1","properties":["myProperty"]} ,//An expression to hash to a hex color}
//Assign a color based on conditions {"type":"caseMap",//must be caseMap"defaultTarget":target //A target object of type color, float, pattern or icon. See documentation below"caseMap": [ {"expressionObject": {"expression":"property1<0","properties":["myProperty"]} ,//An expression to evaluate"target": target //A target object of type color, float, pattern or icon. See documentation below"label":"label"//An optional label to use in the legend }, {"expressionObject": {"expression":"property1==1","properties":["myProperty"]} ,//An expression to evaluate"target": target //A target object of type color, float, pattern or icon. See documentation below"label":"label"//An optional label to use in the legend }, {"expressionObject": {"expression":"property1>2","properties":["myProperty"]} ,//An expression to evaluate"target": target //A target object of type color, float, pattern or icon. See documentation below"label":"label"//An optional label to use in the legend } ],}
//Assign a color based on ranges of an expression . {"type":"rangeMap",//must be rangeMap"gradient":true,//Boolean indicating whether to apply a gradient to the mapping"expressionObject":{"expression":"2*property1+1","properties":["myProperty"]},//expression which outcome to apply the rangeMap to"rangeMap": [ {"value":1,//Start of the range"target": target //A target object of type color, float, pattern or icon. See documentation below"label":"label"//An optional label to use in the legend }, {"value":2,//Start of the range"target": target //A target object of type color, float, pattern or icon. See documentation below"label":"label"//An optional label to use in the legend }, {"value":3,//Start of the range"target": target //A target object of type color, float, pattern or icon. See documentation below"label":"label"//An optional label to use in the legend } ],}
//Assign a color based on values of an expression.{"type":"valueMap",//must be valueMap"expressionObject":{"expression":"property1","properties":["myProperty"]},//expression which outcome to apply the valueMap to"rangeMap": [ {"value":1,//Value to map"target": target //A target object of type color, float, pattern or icon. See documentation below"label":"label"//An optional label to use in the legend }, {"value":2,//Value to map"target": target //A target object of type color, float, pattern or icon. See documentation below"label":"label"//An optional label to use in the legend }, {"value":3,//Value to map"target": target //A target object of type color, float, pattern or icon. See documentation below"label":"label"//An optional label to use in the legend } ],}
// Some code{"type":"expression","expressionObject":{properties:["myProperty"],"expression":"2*property1+1"}}
Expressions
An expressionObject is an object that consists of a properties and an expression.
The properties should be an array of strings. Each element in the array should be the name of a property of the features within the layer that you are styling.
For example if your layer contains features with properties "constructionMaterial", "Height", and "housingType" then your properties array can be:
The expression should be a string that can be interpreted as a formula or logical expression outputting either a number or boolean.
You can use the values of the properties array by referencing them as "property1", "property2",...
For example:
expression="and(property1=='wood', property3>5)"
Here property1 refers to the first element in the properties array which is in this case "housingType" and the second to "Height". That is to say the expression results in true for all features with building material wood and altitude higher than 3 and false otherwise.
The expression can contain standard operators such as:
*,+,-,/, floor(_),),(
and logical operators such as:
&&, ||, !, ==,<=,<,>,>=,!=
An expressionObject can simply assign the value of a property:
An expression can also be used to apply more complicated logic. For example finding the population density based on the properties "surfaceArea" and "population":