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.

A street map of Poland and its neighbours at zoom 6 centred on Kraków, with the opacity transition checkbox below the map.
A screenshot of the example. Map data © OpenStreetMap contributors.

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.ts
import { 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);
  }
}

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] to 0—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

  • transition is 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.

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.