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.

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.tsimport { 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>';
} 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.
static-attribution.react.tsximport { useState } from 'react';
import {
AttributionControl,
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
OSMSource,
TileLayer,
View,
} from 'cc-openlayers/react';
const attribution = '<a href="https://openlayers.org">I\'m a static attribution. I never disappear</a>';
/** An attribution that never disappears: it stays on the map when the only layer is hidden. */
export function StaticAttribution() {
const [visible, setVisible] = useState(true);
return (
<>
<Map height="480px">
<DefaultInteractions />
<DefaultControls attribution={false} />
<AttributionControl collapsible={false} attributions={attribution} />
<View zoom={6}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer visible={visible}>
<OSMSource />
</TileLayer>
</Map>
<div className="example-controls">
<button type="button" onClick={() => setVisible(!visible)}>
Toggle layer
</button>
</div>
</>
);
}How the React version works
The attribution control gets a fixed text instead of collecting it from the visible layers, so it stays when a button hides the 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 |
|---|---|
<aol-control-attribution [attributions]> with the default one turned off | <DefaultControls attribution={false} /> and <AttributionControl attributions={…} collapsible={false} /> |
(click)="visible.set(!visible())" | onClick={() => setVisible(!visible)} |
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. The control is a child of Map, as in the Angular template; the adapter adds it to the map and removes it on unmount.
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"onaol-control-defaultsdisables 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-attributioninside 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.
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.