Skip to main content
Version: 4.64

Dynamic Values

Many layers have a value field that defines their main content or appearance. Examples include the text and color layers.

Dynamic values can be assigned to a layer using evaluables. These values are evaluated at runtime and update automatically when their underlying data changes.

For example, when you use the query context in a value expression, mos. monitors the query's dependencies. Whenever a table used by the query is updated, the query runs again and the layer's value is refreshed.

The same principle applies to other contexts that can change during runtime, such as variables and user settings.

Quick guide​

Dynamic values use evaluables in a layer's value field.

For example, the following text layer uses the variable value expression to display the displayValue variable.

{
"type": "text",
"value": {
"context": "variable",
"field": "displayValue"
}
}
note

You can also use transformation expressions, such as formatDate, to process values before displaying them.

Using dynamic values​

Displaying the current device time​

The following example uses the date context with the formatDate transformation expression to display the current device time.

{
"type": "text",
"value": {
"transform": "formatDate",
"left": {
"context": "date"
},
"right": {
"value": "HH:mm"
}
}
}

Displaying the current outdoor temperature​

In the following example, the current outdoor temperature is stored in a db_table and updated from an external source.

The query context retrieves the temperature. When the underlying table is updated, the query runs again and the displayed value is refreshed.

{
"type": "text",
"value": {
"context": "query",
"table": "weather",
"query": "currentWeather",
"field": "temperature"
}
}