Styling and labels · Angular, React and OpenLayers
Street names along the streets
Render curved street names along Kraków Old Town road centrelines over Esri satellite imagery in OpenLayers using line placement and decluttering.

What this example shows
Over high-resolution Esri aerial imagery of Kraków’s Old Town and Kazimierz (fenced with [minZoom]="14"), bold white street names curve character-by-character directly along twisting medieval lanes and riverside boulevards without ever rendering upside down.
When you need it
Satellite imagery, custom engineering plans and drone orthophotos carry no road names of their own, and horizontal point labels obscure adjacent buildings while failing to show which street corridor they name.
Curved vector line placement produces sharp, rotatable cartographic street lettering at any zoom level.
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.
street-labels.tsimport { ChangeDetectionStrategy, Component } from '@angular/core';
import type { FeatureLike } from 'ol/Feature';
import { getCenter } from 'ol/extent';
import GeoJSON from 'ol/format/GeoJSON';
import { transformExtent } from 'ol/proj';
import Fill from 'ol/style/Fill';
import Style from 'ol/style/Style';
import Text from 'ol/style/Text';
import {
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceImageTileComponent,
SourceVectorComponent,
ViewComponent,
} from 'cc-openlayers';
const style = new Style({
text: new Text({
// The generic family stays unquoted: in quotes, "sans-serif" would name a font of that name.
font: 'bold 11px "Open Sans", "Arial Unicode MS", sans-serif',
placement: 'line',
fill: new Fill({ color: '#ffffff' }),
}),
});
/** The street's name, written along its line. */
function streetName(feature: FeatureLike): Style {
style.getText()?.setText(feature.get('name'));
return style;
}
/** The Old Town, Kazimierz and the streets around them, in Web Mercator. */
const viewExtent = transformExtent([19.915, 50.046, 19.96, 50.07], 'EPSG:4326', 'EPSG:3857');
/**
* The names of the streets of Kraków's Old Town and Kazimierz written along them (a text style with
* `placement: 'line'`), decluttered, over Esri's World Imagery; the view stays within the streets' extent.
*/
@Component({
selector: 'app-street-labels',
imports: [
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceImageTileComponent,
SourceVectorComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [extent]="viewExtent" [center]="center" [zoom]="17" [minZoom]="14" />
<aol-layer-tile>
<aol-source-imagetile
url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
[maxZoom]="19"
attributions="Tiles © Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community"
/>
</aol-layer-tile>
<aol-layer-vector [declutter]="true" [style]="style">
<aol-source-vector
url="assets/krakow/old-town-streets.geojson"
[format]="format"
attributions='Streets © <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors'
/>
</aol-layer-vector>
</aol-map>
`,
})
export class StreetLabels {
protected readonly viewExtent = viewExtent;
protected readonly center = getCenter(viewExtent);
protected readonly format = new GeoJSON();
protected readonly style = streetName;
} 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.
street-labels.react.tsximport type { FeatureLike } from 'ol/Feature.js';
import { getCenter } from 'ol/extent.js';
import GeoJSON from 'ol/format/GeoJSON.js';
import { transformExtent } from 'ol/proj.js';
import Fill from 'ol/style/Fill.js';
import Style from 'ol/style/Style.js';
import Text from 'ol/style/Text.js';
import {
DefaultControls,
DefaultInteractions,
ImageTileSource,
Map,
TileLayer,
VectorLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
const style = new Style({
text: new Text({
// The generic family stays unquoted: in quotes, "sans-serif" would name a font of that name.
font: 'bold 11px "Open Sans", "Arial Unicode MS", sans-serif',
placement: 'line',
fill: new Fill({ color: '#ffffff' }),
}),
});
/** The street's name, written along its line. */
function streetName(feature: FeatureLike): Style {
style.getText()?.setText(feature.get('name'));
return style;
}
/** The Old Town, Kazimierz and the streets around them, in Web Mercator. */
const viewExtent = transformExtent([19.915, 50.046, 19.96, 50.07], 'EPSG:4326', 'EPSG:3857');
const center = getCenter(viewExtent);
const format = new GeoJSON();
/**
* The names of the streets of Kraków's Old Town and Kazimierz written along them (a text style with
* `placement: 'line'`), decluttered, over Esri's World Imagery; the view stays within the streets' extent.
*/
export function StreetLabels() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View extent={viewExtent} center={center} zoom={17} minZoom={14} />
<TileLayer>
<ImageTileSource
url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
maxZoom={19}
attributions="Tiles © Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community"
/>
</TileLayer>
<VectorLayer declutter={true} style={streetName}>
<VectorSource
url="assets/krakow/old-town-streets.geojson"
format={format}
attributions='Streets © <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors'
/>
</VectorLayer>
</Map>
);
}How the React version works
The names of the streets of the Old Town and Kazimierz written along them (placement: 'line'), decluttered, over Esri's World Imagery; the view stays within the streets' extent.
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> | <ImageTileSource> |
<aol-layer-vector [declutter]> with <aol-source-vector [url] [format]> | <VectorLayer declutter={true}> with <VectorSource url format>; the format is a module constant |
a style function reusing one Style | the same module function, which sets the name on one shared Style before returning it |
<aol-view [extent]> | <View extent> with the extent computed once in the module |
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
Configuring the Text style with placement: 'line' instructs OpenLayers to lay the label along each LineString, drop the whole name as soon as two adjacent characters bend by more than maxAngle (45° by default), flip east-to-west geometry runs automatically so text always reads upright left-to-right, and omit names longer than the available segment.
A single shared Style instance is mutated per feature with the current street’s name for zero allocation overhead, while [declutter]="true" eliminates intersection collisions and view [extent] + [minZoom]="14" keep the camera over the street dataset.
How it works
placement: 'line'curves each street name character by character along the road geometry.- OpenLayers lays the name along the line and drops the whole label when adjacent characters bend past 45° or the segment is shorter than the text.
- Lines digitised from east to west are reversed automatically during text layout so labels never appear upside down.
- Reusing one
Styleobject across all streets—updating only its text string per call—keeps rendering fast alongside[declutter]="true"and[minZoom]="14".
Pitfalls
- Never wrap CSS generic font-family keywords such as
sans-serifin quotes inside Canvas font strings:"sans-serif"looks for a literal font named sans-serif and falls back to browser default Times/serif when Open Sans is absent—keep generic fallback families unquoted. - OpenStreetMap splits long avenues into many short way segments wherever attributes or junctions change—merge contiguous segments by name in preprocessing if short blocks drop long street names.
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.