Tile and image services · Angular, React and OpenLayers

XYZ tiles from a URL template

Load CyclOSM bicycle map tiles in OpenLayers from a multi-subdomain {a-c} XYZ URL template with CORS image tile fetching and attributions.

A cycle map of Kraków at zoom 12: the cycle paths in blue over the streets, the parks and the Vistula, and the EuroVelo routes 4 and 11 labelled in pink.
A screenshot of the example. Map style © CyclOSM, hosted by OpenStreetMap France. Map data © OpenStreetMap contributors.

What this example shows

Centred on Kraków at zoom 12, the CyclOSM cartographic style highlights dedicated cycleways in vivid blue, parks, riverside boulevards along the Vistula and international EuroVelo corridors 4 and 11 in pink.

Tiles stream cleanly across three load-balanced subdomains with full style, hosting and OpenStreetMap contributor attributions anchored in the bottom-right corner.

When you need it

Standard {z}/{x}/{y} URL templates are the universal lingua franca of web mapping—powering custom Mapbox/MapTiler styles, self-hosted Martin/TileServer-GL caches and thematic community basemaps.

Connecting via a declarative URL template needs zero XML capability parsing or custom grid math whenever tiles follow the standard Web Mercator slippy-map pyramid.

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.

xyz.ts
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ATTRIBUTION } from 'ol/source/OSM';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  LayerTileComponent,
  MapComponent,
  SourceImageTileComponent,
  ViewComponent,
} from 'cc-openlayers';

/** CyclOSM's cycle map of Kraków, read as XYZ tiles by an image tile source. */
@Component({
  selector: 'app-xyz',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerTileComponent,
    MapComponent,
    SourceImageTileComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="12">
        <aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
      </aol-view>
      <aol-layer-tile>
        <aol-source-imagetile
          url="https://{a-c}.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png"
          [attributions]="attributions"
        />
      </aol-layer-tile>
    </aol-map>
  `,
})
export class Xyz {
  protected readonly attributions = [
    'Tiles style by <a href="https://www.cyclosm.org/" target="_blank">CyclOSM</a> hosted by ' +
      '<a href="https://openstreetmap.fr/" target="_blank">OpenStreetMap France</a>',
    ATTRIBUTION,
  ];
}

Architecture and OpenLayers mechanics

aol-source-imagetile substitutes {z}, {x} and {y} placeholders in its url for each visible cell of the default Web Mercator tile grid. Expanding {a-c} yields three mirror hostnames; rather than picking randomly on every load, OpenLayers hashes each tile’s coordinate tuple deterministically so a given tile always hits the same subdomain and reuses the browser’s HTTP disk cache.

Legal credits combine CyclOSM’s authorship and hosting notice with the standard OpenStreetMap ATTRIBUTION constant.

How it works

  • aol-source-imagetile populates {z}, {x} and {y} in url over the standard north-origin Web Mercator grid.
  • {a-c} expands across three subdomains using deterministic coordinate hashing so browser HTTP caching stays effective across reloads.
  • [attributions] pairs CyclOSM’s style and hosting credit with OpenLayers’ exported OpenStreetMap ATTRIBUTION string.

Pitfalls

  • ImageTile sources enable anonymous CORS requests by default so canvases remain exportable—if a legacy tile server omits Access-Control-Allow-Origin headers, tiles will fail to load unless CORS mode is adjusted.
  • Community-hosted style servers such as CyclOSM enforce fair-use bandwidth limits; configure a self-hosted cache or commercial SLA before launching high-traffic public apps.

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.