Skip to main content

Module convert

Module convert 

Source
Expand description

Converting legacy MapLibre function objects into modern expressions.

Before expressions existed, data- and zoom-driven styling was expressed with function objects{ "type": "exponential", "property": "x", "stops": [...] } and friends. MapLibre still accepts them, converting each to the equivalent modern expression (interpolate / step / match / case / …) before parsing. This module is a port of maplibre-style-spec’s src/function/convert.ts, so the produced expressions match the reference implementation.

convert_function does the conversion given the function object and its property spec (the style-spec entry for the property being styled). The spec supplies information the object alone lacks — whether the property is interpolatable (which picks exponential vs interval when type is omitted), whether {token} strings expand to ["get", …], and the item type for identity array/enum/color properties. Pass &Value::Null (or an empty object) when no spec is available: conversion then relies only on the object’s own type/base/default/stops/property fields, which covers the common cases.

By default parse applies this transparently: hand it either a modern expression or a legacy function object and it does the right thing. Disable that with Options::convert_legacy when you want bare objects to be rejected instead.

Functions§

convert_function
Convert a legacy function object to the equivalent modern expression.
is_function
Whether value looks like a legacy function object — i.e. a JSON object carrying stops (interval/exponential/categorical) or property (an identity function). Other objects are not functions and remain parse errors.