Skip to content

Add styleTransforms option to MapboxVectorLayer - #477

Open
pjeweb wants to merge 2 commits into
mainfrom
feat/mapbox-vector-layer-style-transforms
Open

pjeweb wants to merge 2 commits into
mainfrom
feat/mapbox-vector-layer-style-transforms

Conversation

@pjeweb

@pjeweb pjeweb commented Nov 12, 2026

Copy link
Copy Markdown
Member

Summary

Hosts that want a variant of a vector basemap style (other colours, hidden layers, an emphasis) currently need a server that rewrites the style document. This lets a host apply the same kind of rewrite in the browser.

  • MapboxVectorLayer accepts an initial-only styleTransforms option: a list of setLayerProperties transforms in the format the tile-proxy uses, applied to the style document before it reaches ol-mapbox-style. Without the option the load path is unchanged.
  • With transforms, the layer fetches styleUrl itself (http(s) or relative only) and passes the transformed object on together with the original styleUrl, so relative source and sprite URLs still resolve against it. Layers that share one style URL share one pending request, and each transforms its own copy.
  • applyMapboxStyleTransforms is exported as a pure function with JSON-compatible types, so a transform list is assignable to typed layer options.
  • The browser implementation supports only setLayerProperties and plain JSON and is stricter than the proxy: malformed containers and invalid transforms surface as a style load error before any request is made.
  • Changing styleUrl or styleTransforms in the state recreates the layer, as for other initial-only options.
  • Disposing a MapboxVectorLayer now cancels its own pending style request and no longer applies a style, changes source state or gets a source re-attached when a load finishes late. The re-attachment race also existed for layers without transforms.
  • Docs: docs/integration/TILE_PROXY.md documents the option, the contract and its differences from the proxy, and for the first time lists the layer's existing options (sourceId, layers, background, accessToken, declutter), how to register the definition and the ol-mapbox-style peer dependency.

Limitations: with transforms, mapbox:// style URLs are not supported. On the untransformed path the requests made by ol-mapbox-style itself cannot be aborted on disposal; they no longer affect the disposed layer.

Test plan

  • pnpm --filter @mapsight/core test (352 tests), typecheck (includes a compile-time check that transforms fit layer options), lint (no errors), pnpm run check
  • Transform semantics and validation, immutability
  • Layer: transforms applied before the style is used, no fetch by the layer without transforms, container validation, error paths, disposal during a deferred response on both load paths, shared requests with different transforms per layer
  • ol-proxy level: changing styleTransforms or styleUrl recreates the layer, equal options keep it
  • Against the real ol-mapbox-style with a stubbed fetch: relative source URL resolution and the source re-attachment race
  • Not covered: rendering in a real browser, relative sprite URLs (needs image loading)

Apply tile-proxy compatible setLayerProperties transforms to the style
document in the browser, and document the layer's options.
Type transforms as JSON so they fit layer options, reject malformed
styleTransforms containers, cancel pending style loads on disposal
(also for the untransformed path), share pending style requests per URL
and document the stricter browser contract.
@changeset-bot

changeset-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 18f775b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@mapsight/core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch was successfully deployed

1 active deployment
preview/pr-477 — 18f775b1 Deployed Nov 12, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant