Class MBFunction

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class 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.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected JSONObject json  
      protected MBObjectParser parse  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      • Methods inherited from class Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • json

        protected final JSONObject json
    • Constructor Detail

      • MBFunction

        public MBFunction​(JSONObject json)
      • MBFunction

        public MBFunction​(MBObjectParser parse,
                          JSONObject json)
    • Method Detail

      • getType

        public MBFunction.FunctionType getType()
        Access the function 'type', or null if not specified.

        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.

        Returns:
        function type, or null if not defined.
      • getDefault

        public Object getDefault()
        A value to serve as a fallback function result when a value isn't otherwise available. It is used in the following circumstances:
        • In categorical functions, when the feature value does not match any of the stop domain values.
        • In property and zoom-and-property functions, when a feature does not contain a value for the specified property.
        • In identity functions, when the feature value is not valid for the style property (for example, if the function is being used for a circle-color property but the feature property value is not a string or not a valid color).
        • In interval or exponential property and zoom-and-property functions, when the feature value is not numeric.

        If no default is provided, the style property's default is used in these circumstances.

        Returns:
        The function's default value, or null if none was provided.
      • getTypeWithDefault

        public 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. 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
         
        Parameters:
        clazz - The class for which to return the default function type
        Returns:
        The function type, falling back to the default when the provided Class is the return type.
        See Also:
        The "type" header under Mapbox Spec: Functions
      • getProperty

        public String getProperty()
        If specified, the function will take the specified feature property as an input. See Zoom Functions and Property Functions for more information.
        Returns:
        property evaluated by function, optional (may be null for zoom functions).
      • getStops

        public JSONArray getStops()
        Functions are defined in terms of input and output values. A set of one input value and one output value is known as a "stop."
        Returns:
        stops definition, optional may be null.
      • getBase

        public Number getBase()
        (Optional) Number. Default is 1. The exponential base of the interpolation curve. It controls the rate at which the function output increases. Higher values make the output increase more towards the high end of the range. With values close to 1 the output increases linearly.
        Returns:
        The exponential base of the interpolation curve.
      • font

        public Expression font()
        GeoTools Expression from json definition that evaluates to a font string, used for 'text-font'.

        Fonts only use interval functions

        Returns:
        Expression providing font string (used for `text-font`)
      • isArrayFunction

        public boolean isArrayFunction()
        Returns true if this function's stop values are all arrays.

        For example, the following is an array function:

        
         "{'property':'temperature',
           'type':'exponential',
           'base':1.5,
           'stops': [
                  // [stopkey, stopValueArray]
                     [0,       [0,10]],
                     [100,     [2,15]]
            ]
           }"
         
        Returns:
        true if this function's stop values are all arrays.
      • splitArrayFunction

        public List<MBFunction> splitArrayFunction()
                                            throws ParseException
        Splits an array function into multiple functions, one for each dimension in the function's stop value arrays.

        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]
            ]
           }"
         
        Returns:
        A list of MBFunction, one for each dimension in the stop value array.
        Throws:
        ParseException