MvtMapboxStyleLoader

Parser for a subset of the Mapbox GL Style Specification, producing an MvtRuleBasedStyle usable with MvtVectorLayer. The intent is "drop in a hand-authored style.json or a downloaded one from Maptiler/Mapbox and have it just work for typical basemap use cases" — not full spec fidelity.

Supported

  • Layer types: fill, line, symbol (text-only — no icons).

  • Properties: id (display name), source-layer, filter, minzoom, maxzoom, paint, layout.

  • Filter expressions (legacy "filter" form only): ["==", k, v], ["!=", k, v], ["in", k, ...], ["!in", k, ...], ["has", k], ["!has", k], ["<", k, n], ["<=", k, n], [">", k, n], [">=", k, n], ["all", ...], ["any", ...], ["!", subFilter]. $type is not supported — set MvtStyleRule.geometryType manually or use a layer-name convention.

  • Paint/layout values:

  • Constants (number, color hex string #rrggbb/#rrggbbaa).

  • Legacy zoom-stop form: { "stops": [[zoom, value], …] }.

  • Not supported: modern ["interpolate", …] expressions, ["case", …], ["match", …], ["step", …], arithmetic, ["get", …], ["zoom"], feature-state. Throws MvtStyleParseException when encountered so misrendering doesn't go silent.

  • Paint/layout properties (fill / line / symbol):

  • fill-color, fill-opacity

  • line-color, line-width, line-opacity

  • text-field (plain string "{name}" form or top-level property reference)

  • text-color, text-size, text-halo-color, text-halo-width, text-font (first entry; weight inferred from "bold"/"italic" suffix)

Not supported (deliberately)

  • Modern expression DSL (["interpolate", "linear", ["zoom"], …], ["case", …], ["match", …], arithmetic, string concatenation). Not yet implemented.

  • Icons / sprites / images / patterns. Symbol layers without text-field are silently dropped.

  • Layer types other than fill/line/symbol (heatmap, hillshade, raster, background).

  • Layout properties beyond text-field/text-size/text-font.

  • Source / sprite / glyphs / metadata blocks at the top of the document — parsed and ignored.

  • Visibility = "none" on layout — handled, layer skipped.

If your style relies on something unsupported, MvtStyleParseException surfaces a specific error pointing at the offending node.

Functions

Link copied to clipboard

Parse a Mapbox GL style document into an MvtRuleBasedStyle. The returned style's rules paint in the order the layers appear in the document — same paint-order semantics as Mapbox GL itself.

Link copied to clipboard

Parse a Mapbox color string. Supports #rgb, #rrggbb, #rrggbbaa, and basic rgb(r,g,b) / rgba(r,g,b,a) syntax. Named colors and hsl(...) are intentionally out of scope; the rare style that uses them can be patched at the JSON layer.