Controls · Angular, React and OpenLayers

A static attribution that never disappears

Configure a persistent control-level attribution in OpenLayers that stays visible on the map even when every tile and vector layer is hidden.

A street map of central Europe around southern Poland at zoom 6 with the static attribution link beside the OpenStreetMap credit in the bottom right corner of the map, and the Toggle layer button below it.
A screenshot of the example. Map data © OpenStreetMap contributors.

What this example shows

At zoom 6 over central Europe around southern Poland, the bottom-right attribution bar displays both a permanent application-level credit link and OpenStreetMap’s layer credit side by side without a collapse button.

Clicking the Toggle layer button beneath the viewport hides the OpenStreetMap tile layer completely: the OSM tile credit disappears with its hidden layer, while the static control-level attribution remains anchored in the corner.

When you need it

Enterprise geoportals and analytical maps often carry overarching legal notices, cartographic authorship credits or platform terms that apply to the viewer as a whole rather than to any single toggleable layer.

Attaching global credits to the attribution control itself—while keeping dataset-specific credits on their respective sources—ensures layer credits come and go accurately as overlays are switched on and off without ever losing the platform notice.

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.

static-attribution.ts
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import {
  ControlAttributionComponent,
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  LayerTileComponent,
  MapComponent,
  SourceOsmComponent,
  ViewComponent,
} from 'cc-openlayers';

/** An attribution that never disappears: it stays on the map when the only layer is hidden. */
@Component({
  selector: 'app-static-attribution',
  imports: [
    ControlAttributionComponent,
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerTileComponent,
    MapComponent,
    SourceOsmComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults [attribution]="false" />
      <aol-control-attribution [collapsible]="false" [attributions]="attribution" />
      <aol-view [zoom]="6">
        <aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
      </aol-view>
      <aol-layer-tile [visible]="visible()"><aol-source-osm /></aol-layer-tile>
    </aol-map>
    <div class="example-controls">
      <button type="button" (click)="visible.set(!visible())">Toggle layer</button>
    </div>
  `,
})
export class StaticAttribution {
  readonly visible = signal(true);
  protected readonly attribution = '<a href="https://openlayers.org">I\'m a static attribution. I never disappear</a>';
}

Architecture and OpenLayers mechanics

Passing [attributions] directly to aol-control-attribution registers fixed credit strings (or HTML links) that OpenLayers appends after whatever credits are collected from currently visible layer sources on each render frame.

Setting [attribution]="false" on aol-control-defaults suppresses the duplicate built-in widget, while [collapsible]="false" keeps the combined credit strip permanently open.

How it works

  • [attributions] on the attribution control supplies a permanent credit link merged with the credits of any visible layers during rendering.
  • [attribution]="false" on aol-control-defaults disables the default widget so only the configured [collapsible]="false" control appears.
  • Toggling the OpenStreetMap layer’s visibility removes and restores its source credit dynamically while the control’s static credit never disappears.

Pitfalls

  • OpenLayers injects attribution strings as HTML markup so links can render—never pass unescaped user input or untrusted third-party strings into attributions without sanitising them first.
  • Do not place dataset-specific copyrights in static control attributions if those layers can be turned off; attach dataset credits to their sources so hidden layers do not clutter the corner.
  • Because the wrapper renders aol-control-attribution inside its own host element for flexible layout, ensure the nearest positioned ancestor is the map frame so OpenLayers’ corner CSS places it inside the canvas.

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.