1. Home
  2. Docs
  3. GLayer
  4. Advanced
  5. User Functions

User Functions

GLayer provides a bunch of functions available to the users that can help define dynamic behavior and data formats without having to use complex JavaScript. These functions can all be accessed using the ^fncName(arguments) syntax. This syntax can be used in any settings property that supports parsing JS (paint/layout, gradient labels, popup labels, etc.).

Example: To format a number of seconds (e.g., 12345670) to a string with days/hours/minutes/seconds, you would use the format function: ^format(1234567, "duration") which will then output a string "14d 6h 56m 7s".

List of all User Functions currently supported by GLayer:

  • filter(fieldID, value)
    Sets/gets filter values for the field with the given ID. Used as setter when value is provided, as getter when it is not.
    • fieldID – ID of the field to set/get filter for
    • value (optional) – value to set for the filter.
  • features()
    Returns project features (from /features/ endpoint). Returns empty array when no features are loaded.
  • var(name, value)
    Sets/gets a global variable available to use in other functions. Used as setter when value is provided, as getter when it is not.  This variable is currently not persistent after reload. (Subject to change.)
    • name – unique name of the variable to set/get
    • value (optional) – value to set for the variable.    
  • lvar(lName, vName, value)
    Sets/gets a layer specific variable. Used as setter when value is provided, as getter when it is not. The layer is identified by its name setting. If multiple layers have the same name, the first layer with the given name is used.
    • lName – name of the layer to set/get variable for
    • vName – name of the variable to set/get
    • value (optional) – value to set for the variable.  
  • format(value, type, …args)
    Formatter function for various output types (described further below). If no or invalid format type is provided, returns the value’s .toString() method.
    • duration()
      Converts from seconds to Days Hours Minutes Seconds string (eg. 54321 =>  15h 05m 21s), values < 0 will always return as 0s.
    • hour()
      Converts number of hours to HH:mm (eg. 8.5 => 8:30).
    • day(type)
      Converts day number to localized short/long day name (eg. 2 => Tue/Tuesday).
      • type – type of string to convert to (short/long). Defaults to short.
    • month(type)
      Converts month number to localized short/long month name (eg. 2 => Feb/February)
      • type – type of string to convert to (short/long). Defaults to short.
    • date()
      Converts unix seconds timestamp to localized date string (eg. 1648552631108 => 29.3.2022)
  • filterPreset(id)
    Loads a server-saved filter preset with the given id (URL).
    • name – id of the preset to load
Was this article helpful to you? Yes No

How can we help?