public class MBFunction extends Object
As of v0.41.0, data expressions are the preferred method for styling features based on zoom level or the feature's properties.
Each function is evaluated according type: MBFunction.FunctionType.IDENTITY
, MBFunction.FunctionType.INTERVAL
, MBFunction.FunctionType.CATEGORICAL
, MBFunction.FunctionType.EXPONENTIAL
.
We have several methods that intelligently review getType()
and produce the correct
expression:
Modifier and Type | Class and Description |
---|---|
static class |
MBFunction.FunctionCategory
Function category property, zoom, or property and zoom.
|
static class |
MBFunction.FunctionType
Optional type, one of identity, exponential, interval, categorical.
|
Modifier and Type | Field and Description |
---|---|
protected JSONObject |
json |
protected MBObjectParser |
parse |
Constructor and Description |
---|
MBFunction(JSONObject json) |
MBFunction(MBObjectParser parse,
JSONObject json) |
Modifier and Type | Method and Description |
---|---|
EnumSet<MBFunction.FunctionCategory> |
category()
Programmatically look at the structure of the function and determine if it is a Zoom
function, Property function or Zoom-and-property functions.
|
Expression |
color()
GeoTools
Expression from json definition that evaluates to a color, used for
properties such as 'color' and 'fill-color'. |
Expression |
enumeration(Class<? extends Enum<?>> enumeration)
GeoTools
Expression from json definition that evaluates to the provided Enum, used
for properties such as 'line-cap' and 'text-transform'. |
Expression |
font()
GeoTools
Expression from json definition that evaluates to a font string, used for
'text-font'. |
Expression |
function(Class<?> clazz)
GeoTools
Expression from json definition. |
Number |
getBase()
(Optional) Number.
|
Object |
getDefault()
A value to serve as a fallback function result when a value isn't otherwise available.
|
String |
getProperty()
If specified, the function will take the specified feature property as an input.
|
JSONArray |
getStops()
Functions are defined in terms of input and output values.
|
MBFunction.FunctionType |
getType()
Access the function 'type', or null if not specified.
|
MBFunction.FunctionType |
getTypeWithDefault(Class<?> clazz)
Return the function type, falling back to the default function type for the provided
Class if no function type is explicitly declared. |
boolean |
isArrayFunction()
Returns true if this function's stop values are all arrays.
|
Expression |
numeric()
GeoTools
Expression from json definition that evaluates to a numeric, used for
properties such as 'line-width' and 'opacity'. |
List<MBFunction> |
splitArrayFunction()
Splits an array function into multiple functions, one for each dimension in the function's
stop value arrays.
|
protected final MBObjectParser parse
protected final JSONObject json
public MBFunction(JSONObject json)
public MBFunction(MBObjectParser parse, JSONObject json)
public MBFunction.FunctionType getType()
Depending on the domain you are working with ( enumeration(Class)
, color()
, enumeration(Class)
} ) the default value to use is different. These
functions check for null and use the appropriate setting.
public Object getDefault()
If no default is provided, the style property's default is used in these circumstances.
public MBFunction.FunctionType getTypeWithDefault(Class<?> clazz)
Class
if no function type is explicitly declared. The parameter is necessary because
different output classes will have different default function types.
Examples (For a function with no explicitly declared type):
getTypeWithDefault(String.class); // "interval" function type getTypeWithDefault(Number.class); // "exponential" function type
clazz
- The class for which to return the default function typeClass
is the
return type.public String getProperty()
public EnumSet<MBFunction.FunctionCategory> category()
MBFunction.FunctionCategory.PROPERTY
, MBFunction.FunctionCategory.ZOOM
or both.public JSONArray getStops()
public Number getBase()
public Expression color()
Expression
from json definition that evaluates to a color, used for
properties such as 'color' and 'fill-color'.
This is the same as numeric()
except we can make some assumptions about the
values (converting hex to color, looking up color names).
MBFunction.FunctionType.IDENTITY
: input is directly converted to a color, providing a way
to process attribute data into colors.
MBFunction.FunctionType.CATEGORICAL
: selects stop equal to input value
MBFunction.FunctionType.INTERVAL
: selects stop less than numeric input value
MBFunction.FunctionType.EXPONENTIAL
: interpolates an output color between two stops
Function
(or identity Expression
for the provided json)public Expression font()
Expression
from json definition that evaluates to a font string, used for
'text-font'.
Fonts only use interval functions
MBFunction.FunctionType.INTERVAL
: selects stop less than numeric input, and returns stop
value as a number
public Expression numeric()
Expression
from json definition that evaluates to a numeric, used for
properties such as 'line-width' and 'opacity'.
This is the same as color()
except we can make some assumptions about the values
(converting "50%" to 0.5).
MBFunction.FunctionType.IDENTITY
: input is directly converted to a numeric output
MBFunction.FunctionType.CATEGORICAL
: selects stop equal to input, and returns stop value
as a number
MBFunction.FunctionType.INTERVAL
: selects stop less than numeric input, and returns stop
value as a number
MBFunction.FunctionType.EXPONENTIAL
: interpolates a numeric output between two stops
Function
(or identity Expression
for the provided json)public Expression function(Class<?> clazz)
Expression
from json definition.
Delegates handling of Color, Number and Enum - for generic values (such as String) the following are available:
MBFunction.FunctionType.IDENTITY
: input is directly converted to a literal
MBFunction.FunctionType.CATEGORICAL
: selects stop equal to input, and returns stop value
as a literal
MBFunction.FunctionType.INTERVAL
: selects stop less than numeric input, and returns stop
value a literal
clazz
- Type of data expectedFunction
(or identity Expression
for the provided json)public Expression enumeration(Class<? extends Enum<?>> enumeration)
Expression
from json definition that evaluates to the provided Enum, used
for properties such as 'line-cap' and 'text-transform'.
MBFunction.FunctionType.IDENTITY
: input is directly converted to an appropriate literal
MBFunction.FunctionType.CATEGORICAL
: selects stop equal to input, and returns stop value
as a literal
MBFunction.FunctionType.INTERVAL
: selects stop less than numeric input, and returns stop
value a literal
Function
(or identity Expression
for the provided json)public boolean isArrayFunction()
For example, the following is an array function:
"{'property':'temperature', 'type':'exponential', 'base':1.5, 'stops': [ // [stopkey, stopValueArray] [0, [0,10]], [100, [2,15]] ] }"
public List<MBFunction> splitArrayFunction() throws ParseException
For example, for the following array function:
"{'property':'temperature', 'type':'exponential', 'base':1.5, 'stops': [ // [stopkey, stopValueArray] [0, [0,10]], [100, [2,15]] ] }"
This method would split the above function into the following two functions:
"X" Function:
"{'property':'temperature', 'type':'exponential', 'base':1.5, 'stops': [ [0, 0], [100, 2] ] }"
And "Y" Function:
"{'property':'temperature', 'type':'exponential', 'base':1.5, 'stops': [ [0, 10], [100, 15] ] }"
MBFunction
, one for each dimension in the stop value array.ParseException
Copyright © 1996–2022 Geotools. All rights reserved.