Projections · Angular, React and OpenLayers

OGC API vector tiles in WorldCRS84Quad

Serve static serverless Mapbox Vector Tiles in OGC WorldCRS84Quad geographic coordinates to an EPSG:4326 OpenLayers map using absolute URLs.

The municipalities of Kraków's county in pale yellow with grey borders on a grey background, Kraków the large one in the middle with its neighbours around it.
A screenshot of the example. Municipal boundaries: Państwowy Rejestr Granic © GUGiK.

What this example shows

In a pure EPSG:4326 degree view at [zoom]="10" over background="#d1d1d1", Kraków and its surrounding county municipalities render in pale cream ('#f7f7e9') with crisp 0.6-pixel grey borders ('#8c8b8b') from a static folder of OGC WorldCRS84Quad .mvt files—requiring zero dynamic tile server.

When you need it

Static CDNs, offline Electron/Capacitor bundles and air-gapped intranets can host pre-generated OGC API - Tiles directory trees (WorldCRS84Quad.json + {z}/{y}/{x}.mvt files) as plain static assets.

Serving WorldCRS84Quad vector tiles directly into an EPSG:4326 view delivers crisp, unwarped geographic boundaries with zero backend compute.

The code

The example uses cc-openlayers, my Angular component library for OpenLayers: each aol-… element creates the OpenLayers object it names, updates it from its inputs and disposes of it with the component.

ogc-vector-tiles-geographic.shared.ts
import type { FlatStyle } from 'ol/style/flat.js';

/** The municipalities in pale yellow with grey borders. */
export const style: FlatStyle = {
  'stroke-width': 0.6,
  'stroke-color': '#8c8b8b',
  'fill-color': '#f7f7e9',
};
ogc-vector-tiles-geographic.ts
import { ChangeDetectionStrategy, Component } from '@angular/core';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  FormatMVTComponent,
  LayerVectorTileComponent,
  MapComponent,
  SourceOGCVectorTileComponent,
  ViewComponent,
} from 'cc-openlayers';
import { style } from './ogc-vector-tiles-geographic.shared';

/**
 * Kraków and the municipalities of its county as Mapbox vector tiles from an OGC API - Tiles tileset in the
 * geographic WorldCRS84Quad tile matrix set, shown in a geographic view in a flat style. The tileset is static, in
 * the gallery's assets (made by `tools/make-ogc-tilesets.mjs`).
 */
@Component({
  selector: 'app-ogc-vector-tiles-geographic',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    FormatMVTComponent,
    LayerVectorTileComponent,
    MapComponent,
    SourceOGCVectorTileComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view projection="EPSG:4326" [zoom]="10">
        <aol-coordinate [x]="19.94" [y]="50.1" srid="EPSG:4326" />
      </aol-view>
      <aol-layer-vectortile background="#d1d1d1" [style]="style">
        <aol-source-ogcvectortile
          [url]="url"
          projection="EPSG:4326"
          attributions="Boundaries: PRG, Główny Urząd Geodezji i Kartografii"
        >
          <aol-format-mvt />
        </aol-source-ogcvectortile>
      </aol-layer-vectortile>
    </aol-map>
  `,
})
export class OgcVectorTilesGeographic {
  /** The tileset document, as an absolute URL: OpenLayers resolves the tile links against it. */
  protected readonly url = new URL('assets/krakow/municipality-tiles/WorldCRS84Quad.json', document.baseURI).href;
  protected readonly style = style;
}

Architecture and OpenLayers mechanics

Because the static JSON descriptor uses relative tile hrefs and OpenLayers resolves relative OGC item links via new URL(relativeHref, tilesetUrl), [url]="url" converts the asset path into a full absolute URL using new URL('assets/krakow/municipality-tiles/WorldCRS84Quad.json', document.baseURI).href.

aol-source-ogcvectortile pairs with <aol-format-mvt /> across matrix levels 4–10 (drawing matrix 9 at view [zoom]="10", 0.0014°/px).

How it works

  • aol-source-ogcvectortile reads the static tileset descriptor at [url]="url" and decodes tiles with <aol-format-mvt />.
  • new URL('assets/krakow/municipality-tiles/WorldCRS84Quad.json', document.baseURI).href supplies the scheme-and-host base URL OpenLayers needs to resolve relative tile links.
  • Matrix levels 4–10 cover the Kraków county area, with view [zoom]="10" (0.0014°/px) rendering WorldCRS84Quad level 9.
  • Flat style rules fill municipalities in '#f7f7e9' with 0.6 px '#8c8b8b' strokes over background="#d1d1d1".

Pitfalls

  • Passing a bare relative path (a bare assets path) as [url] fails when the JSON itself contains relative tile templates, because new URL(template, base) throws a TypeError when base lacks a protocol and host.
  • Remember the 1-level offset in EPSG:4326: OpenLayers view zoom 0 is 1.40625°/px (1 tile wide) whereas WorldCRS84Quad level 0 is 0.703125°/px (2 tiles wide), so view zoom 10 requests matrix 9.

The same feature in the OpenLayers examples .

Background: state and lifecycle of maps in Angular with OpenLayers, which the components of cc-openlayers take care of.