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.

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.tsimport { 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,
];
} The React version uses the library's React adapter, cc-openlayers/react: each component creates the OpenLayers object it names when it mounts, updates it from its props and disposes of it when it unmounts.
xyz.react.tsximport { ATTRIBUTION } from 'ol/source/OSM.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
ImageTileSource,
Map,
TileLayer,
View,
} from 'cc-openlayers/react';
const 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,
];
/** CyclOSM's cycle map of Kraków, read as XYZ tiles by an image tile source. */
export function Xyz() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={12}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<ImageTileSource
url="https://{a-c}.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png"
attributions={ATTRIBUTIONS}
/>
</TileLayer>
</Map>
);
}How the React version works
The CyclOSM cycling map of Kraków read as XYZ tiles by an ImageTile source from a {z}/{x}/{y} URL template, credited to CyclOSM and OpenStreetMap.
What both versions share
OpenLayers renders the map and handles the interactions; the cc-openlayers/core layer gives both adapters the same view binding (MapViewBinding) and the same conversion of coordinates from EPSG:4326 to the map's projection.
From Angular to React
| Angular | React |
|---|---|
<aol-source-imagetile [url] [attributions]> | <ImageTileSource url attributions> |
Who creates, updates and disposes
Map creates the ol/Map in useLayoutEffect and disposes of it on unmount; each layer, source and interaction component adds its object to the parent it gets from context and removes it in its effect's cleanup, as ngOnDestroy does in Angular.
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-imagetilepopulates{z},{x}and{y}inurlover 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 OpenStreetMapATTRIBUTIONstring.
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.
Related examples
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.