Vector data · Angular, React and OpenLayers

Vector tiles from OGC API - Tiles

Render Natural Earth lake polygons as Mapbox Vector Tiles from an OGC API - Tiles WebMercatorQuad service in OpenLayers using flat styles.

OpenStreetMap of Europe and western Asia at zoom 3 with the large lakes in blue.
A screenshot of the example. Lakes: Natural Earth, from the pygeoapi demonstration server. Map data © OpenStreetMap contributors.

What this example shows

Zoomed out to continental scale (zoom 3) across Europe and western Asia over OpenStreetMap, major Eurasian lakes—including Ladoga, Onega, Vänern, the Aral Sea, Balkhash and western Lake Baikal—stream as binary Mapbox Vector Tiles discovered automatically from an OGC API - Tiles JSON endpoint and render in translucent blue.

When you need it

OGC API - Tiles brings vendor-neutral JSON discovery and standardized tile matrix sets (WebMercatorQuad, WorldCRS84Quad) to binary vector tiles.

Pointing OpenLayers at the OGC tileset URL discovers the matrix grid and MVT item template automatically without hardcoding {z}/{x}/{y}.pbf paths.

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.ts
import { ChangeDetectionStrategy, Component } from '@angular/core';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  FormatMVTComponent,
  LayerTileComponent,
  LayerVectorTileComponent,
  MapComponent,
  SourceOGCVectorTileComponent,
  SourceOsmComponent,
  ViewComponent,
} from 'cc-openlayers';

/**
 * The large lakes of Natural Earth as vector tiles from an OGC API - Tiles service (the pygeoapi demonstration
 * server), drawn in a flat style over OpenStreetMap.
 */
@Component({
  selector: 'app-ogc-vector-tiles',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    FormatMVTComponent,
    LayerTileComponent,
    LayerVectorTileComponent,
    MapComponent,
    SourceOGCVectorTileComponent,
    SourceOsmComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="3">
        <aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
      </aol-view>
      <aol-layer-tile><aol-source-osm /></aol-layer-tile>
      <aol-layer-vectortile [style]="style">
        <aol-source-ogcvectortile
          url="https://demo.pygeoapi.io/master/collections/lakes/tiles/WebMercatorQuad"
          attributions="Lakes: Natural Earth"
        >
          <aol-format-mvt />
        </aol-source-ogcvectortile>
      </aol-layer-vectortile>
    </aol-map>
  `,
})
export class OgcVectorTiles {
  protected readonly style = {
    'stroke-width': 1.5,
    'stroke-color': '#1f4e8c',
    'fill-color': 'rgba(31, 78, 140, 0.45)',
  };
}

Architecture and OpenLayers mechanics

aol-source-ogcvectortile fetches the JSON tileset metadata at url, resolves its linked WebMercatorQuad matrix set definition, and selects the tile URL template matching the MIME type supported by its child aol-format-mvt decoder.

A concise flat style paints each polygon with fill-color and stroke-color.

How it works

  • aol-source-ogcvectortile reads the OGC JSON tileset at url and configures the WebMercatorQuad tile pyramid automatically.
  • aol-format-mvt decodes incoming binary payloads as Mapbox Vector Tiles.
  • Flat style properties fill-color and stroke-color render translucent blue lake interiors with dark-blue shorelines.
  • Opening at zoom 3 frames major continental lakes across Europe and western Asia appropriate to the dataset’s global scale.

Pitfalls

  • This demonstration collection serves 1:110M Natural Earth global overview polygons—zooming closely into individual shorelines reveals coarse generalised vertices inherent to the source dataset rather than a client rendering issue.
  • OpenLayers does not reproject vector tiles on the fly: ensure the OGC tile matrix set CRS (here WebMercatorQuad / EPSG:3857) matches your map view projection.

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.