We’ve just pushed beta build 151, which tweaks formula auto-completion behaviour on Mac and also brings some changes to an advanced use case of “style” formulas:
The “style” formulas let you adjust how the locations of your collection are displayed on the map – including having multiple map representations for a single location by using a list/array.
The styles now handle nil
values gracefully (rather than returning errors) – which is useful when dealing with collections that use different data formats for different locations. You can then provide a style for each of those formats, and the map will display the style for which the location returns something other than nil
.
As an example, let’s say you visualise data from a GeoJSON API that returns points (i.e., GeoJSON Position features) and some of them have an additional GeoJSON point in the properties under the field destination
and you want to display those as lines from to the destination and with a circle around the destination, and others with just a circle around their location. You can do that with a “style” formula as follows:
[
fixedCircle(200, geometryValue("destination?"))
.fill(red),
LineString(geometryValue("destination?"), coordinate)
.stroke(yellow)
]
There are a few things notable about this:
-
geometryValue("destination?")
returnsnil
if the propertydestination
does not exist, and if it exists, it parses it as a GeoJSON geometry (i.e., a Position in the example). -
fixedCircle(..., center)
will draw a circle of 200m radius around the destination if that returned non-nil and around the location if it returned nil. -
LineString(..., coordinate)
will draw a line from that destination to the coordinate of the location, if that destination returned non-nil and will draw nothing if it did returnnil
. - The circles are coloured with a red fill and the lines with a yellow stroke, which no longer requires wrapping them in a
Style(...)
.
Quite an advanced use, but good to be aware of in case you need it.
Full change log is below.
Added:
- Formulas: Allow calling
.fill/.stroke/.cluster
directly on a geometry - Formulas: Added
pin(..., center)
,circle(..., center)
andfixedCircle(..., center)
variants that allow specifying a different center location rather than the one from the location.
Changed:
- Views: When using a list for the styles and some of them evaluate to
nil
, those are now ignored rather than being treated like an error. - Formulas:
geometryValue
is nownil
-friendly, i.e., when using a JSON path that has a question mark in it.geometryValue
will then returnnil
rather than an error. - Formulas:
LineString(...)
,Polygon(...)
andPosition/2
are all friendly tonil
values in the parameter list. If any parameter value isnil
, these will now returnnil
rather than returning an error. - Formulas:
LineString(...)
andPolygon(...)
can take a mix of positions and geometries
Fixed:
- Fixed auto-completion pop-over on Mac showing when moving cursor around. Now it’ll just show after typing non-whitespace or pressing Esc.
- Auto-completion pop-over now includes exact match, for quick access to documentation by pressing Escape
- Fix auto-completion in partial formulas that use a
??
- Fixes a crash when typing
function(value)()
in the formula editor - Fixes handling of viewing the formula of a preset and pressing “Done” without editing it
- Style tweak for the “empty state” view on iPhone