Layers · Angular, React and OpenLayers
Fade tiles in, or show them at once
Compare OpenLayers’ default 250 ms tile opacity fade-in against instant zero-transition tile rendering using two toggleable OSM sources.

What this example shows
Centred on Kraków across Poland at zoom 6, a checkbox beneath the map switches [visible] between two OpenStreetMap layers backed by separate sources: one using OpenLayers’ default quarter-second opacity fade-in, and the other configured with [transition] set to 0 so newly downloaded tiles appear at full opacity on their very first frame.
When you need it
Understanding source tile transitions helps you choose between smooth visual polish during everyday browsing and deterministic instant rendering for translucent themes, automated Playwright screenshots or map image exports.
While a 250 ms fade softens tile loading on opaque basemaps, turning transitions off prevents temporary double-opacity artifacts on semi-transparent overlays and avoids capturing half-faded tiles in headless print/export jobs.
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.
tile-transitions.tsimport { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { ATTRIBUTION } from 'ol/source/OSM';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceImageTileComponent,
ViewComponent,
} from 'cc-openlayers';
/** OpenStreetMap around Kraków from two image tile sources, one fading its tiles in and one without a transition. */
@Component({
selector: 'app-tile-transitions',
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]="6" [maxZoom]="11">
<aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
</aol-view>
<aol-layer-tile [visible]="transition()">
<aol-source-imagetile [url]="url" [attributions]="attributions" />
</aol-layer-tile>
<aol-layer-tile [visible]="!transition()">
<aol-source-imagetile [url]="url" [transition]="0" [attributions]="attributions" />
</aol-layer-tile>
</aol-map>
<div class="example-controls">
<label>
render with an opacity transition
<input name="transition" type="checkbox" [checked]="transition()" (change)="toggle($event)" />
</label>
</div>
`,
})
export class TileTransitions {
readonly transition = signal(true);
protected readonly url = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
protected readonly attributions = ATTRIBUTION;
protected toggle(event: Event): void {
this.transition.set((event.target as HTMLInputElement).checked);
}
} 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.
tile-transitions.react.tsximport { useState } from 'react';
import { ATTRIBUTION } from 'ol/source/OSM.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
ImageTileSource,
Map,
TileLayer,
View,
} from 'cc-openlayers/react';
const url = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
/** OpenStreetMap around Kraków from two image tile sources, one fading its tiles in and one without a transition. */
export function TileTransitions() {
const [transition, setTransition] = useState(true);
return (
<>
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={6} maxZoom={11}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer visible={transition}>
<ImageTileSource url={url} attributions={ATTRIBUTION} />
</TileLayer>
<TileLayer visible={!transition}>
<ImageTileSource url={url} transition={0} attributions={ATTRIBUTION} />
</TileLayer>
</Map>
<div className="example-controls">
<label>
render with an opacity transition
<input
name="transition"
type="checkbox"
checked={transition}
onChange={(event) => setTransition(event.target.checked)}
/>
</label>
</div>
</>
);
}How the React version works
Two sources read the same OpenStreetMap tiles: one fades them in (the default transition), the other shows them at once (transition: 0). A checkbox switches the visible layer.
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 |
|---|---|
(change)="toggle($event)" | onChange setting transition |
[visible]="transition()" and [visible]="!transition()" | visible={transition} and visible={!transition} |
<aol-source-imagetile [transition]="0"> | <ImageTileSource transition={0}> |
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
Tile fade timing belongs to the tile source rather than the layer: by default, each newly decoded tile animates its alpha from 0 to 1 over 250 milliseconds on top of the retained coarser ancestor tile, scheduling continuous animation frames until completion.
Configuring [transition] as 0 on the second source skips that alpha ramp completely. Because OpenLayers issues zero tile requests for layers with [visible] false, unchecking the box loads the zero-transition source cleanly on demand so you can compare fresh tile arrival side by side.
How it works
- Two layers point at OpenStreetMap with independent sources—one keeping the default 250 ms fade and the second setting
[transition]to0—switched via[visible]. - During a default 250 ms fade, OpenLayers keeps the coarser ancestor tile underneath so the map sharpens progressively instead of flashing the canvas background.
- Because hidden layers (
[visible]false) request no tiles, switching to the second layer demonstrates live network tile arrival without cached fade state.
Pitfalls
transitionis a property of the tile source, not the tile layer: two layers sharing a single source instance will always share the exact same fade behaviour.- Disabling transitions on slow cellular links makes individual opaque tiles pop in sharply square by square—keep the default 250 ms fade on primary opaque basemaps unless transparency or deterministic capture requires
0.
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.