Skip to content

Make WMTSSource configurable from JSON and add OGC capabilities helpers - #482

Open
pjeweb wants to merge 8 commits into
mainfrom
feat/wmts-source-and-ogc-capabilities
Open

pjeweb wants to merge 8 commits into
mainfrom
feat/wmts-source-and-ogc-capabilities

Conversation

@pjeweb

@pjeweb pjeweb commented Nov 12, 2026

Copy link
Copy Markdown
Member

Summary

WMTSSource definition (@mapsight/core)

A WMTS layer could not be configured from JSON: the ol-proxy definition did not map layer, style and requestEncoding, and passed tileGrid through as raw JSON, so the OpenLayers constructor threw or the source ignored layer, style and REST encoding.

  • The definition now maps these options and builds the ol/tilegrid/WMTS from a plain JSON description (origin/origins, resolutions, matrixIds, tileSize/tileSizes, optionally extent, sizes, tileRanges). Tile grid instances are still accepted.
  • The description is validated before the source is created (validateWMTSTileGridDescription and createWMTSTileGrid are exported). An invalid or missing tile grid logs one error and no source is created, instead of failing later during rendering. tileRanges take precedence over extent.
  • dimensions is copied instead of being handed to OpenLayers, so frozen config is never mutated. Changing, adding or removing a dimension creates a new source, because OpenLayers can merge dimensions but never remove one.

Capabilities helpers (@mapsight/ui)

  • New pure helpers wmsCapabilitiesToLayers (@mapsight/ui/config/ogc/wms) and wmtsCapabilitiesToLayers (@mapsight/ui/config/ogc/wmts). They take a capabilities XML string or its parsed form and return plain data per layer plus a ready-to-use layer definition (TileLayer with TileWMSSource or WMTSSource). They make no requests; fetching and cross-origin handling stay with the host application. Parsing needs a DOM (DOMParser).
  • Text from a capabilities document is untrusted. It is returned as data only and never written to metaData (attribution, legends) or other fields that may be rendered as HTML.
  • WMS: nested layers are flattened and inherited values resolved over the whole layer tree. queryable is resolved per layer element and omitted when unknown. Parameters the source generates itself are removed from the advertised GetMap URL; vendor and authentication parameters are kept.
  • WMTS: matrix set, projection and style selection are checked after OpenLayers' own selection, and layers with malformed tile matrix data, an unknown matrix set or style, or an unregistered projection are left out.
  • Identifiers (layer, style, matrix set, format) are compared case-sensitively; only CRS codes are compared case-insensitively.

Docs: new "WMTS" and "From capabilities to layer config" sections in docs/integration/OGC_LAYERS.md.

Test plan

  • pnpm --filter @mapsight/core test (356 tests) and pnpm --filter @mapsight/ui test (621 tests); typecheck and lint for both (no errors); pnpm run check
  • WMTSSource through the ol-proxy machinery: tile URLs for KVP and REST, origin handling, tile ranges, instance pass-through; the original tests fail against the previous definition
  • Lifecycle with deeply frozen config: create, change, add and remove a dimension
  • Tile grid validation: missing fields, length mismatches, non-finite values, resolutions not descending
  • Helpers with synthetic WMS 1.1.1 / 1.3.0 and WMTS documents: flattening and inheritance, format selection, case-sensitive identifiers, queryable for same-named layers, malformed numeric fields, final TileWMS tile URLs for both WMS versions, and a round trip from helper output through ol-proxy to a working ol/source/WMTS
  • Not covered: real services and rendering in a browser

The WMTSSource ol-proxy definition now maps layer, style and requestEncoding and builds its tile grid from a plain JSON description. New helpers in @mapsight/ui turn WMS and WMTS capabilities documents into plain data and ready-to-use layer definitions.
WMTSSource copies the dimensions it is given, recreates the source when a
dimension changes or is removed, and validates the tile grid description
before creating the source, so frozen config is never mutated and no source
without a working tile grid reaches the map.

The capabilities helpers skip WMTS layers with malformed tile matrix data,
compare identifiers case-sensitively (CRS codes excepted), resolve WMS
queryable per layer element and report it only when known, and remove the
parameters the WMS source generates from the advertised GetMap URL.
@changeset-bot

changeset-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4b5bb5a

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

This PR includes changesets to release 2 packages
Name Type
@mapsight/ui Minor
@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-482 — 4b5bb5a7 Deployed Nov 24, 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