Essentials · Angular, React and OpenLayers
The smallest complete map
Create the smallest complete OpenLayers map in Angular and React with a sized container, Web Mercator view, OpenStreetMap tiles, controls and gestures.

What this example shows
This example distils an OpenLayers integration down to the minimal self-contained markup needed for a fully interactive street map. Opening at zoom level 13 over central Kraków—framing the Old Town Planty ring, Wawel bend of the Vistula and neighbouring districts—it renders top-left zoom buttons, auto-hiding rotation reset and bottom-right OpenStreetMap attribution.
The component class itself holds zero state, event handlers or lifecycle hooks: every piece of map behaviour comes directly from explicit elements in the template.
When you need it
Context maps that simply present a fixed location—such as a company office on a contact page, an event venue card or a clean baseline to copy when starting a new map feature—need no external state management.
Keeping a minimal reference template is also the fastest way to verify bundler styles, SSR/prerender compatibility and container layout sizing before adding dynamic vector layers, projections or custom pointer tools.
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.
simple.tsimport { ChangeDetectionStrategy, Component } from '@angular/core';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
ViewComponent,
} from 'cc-openlayers';
/** A simple map with an OSM source. */
@Component({
selector: 'app-simple',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="13">
<aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
</aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
</aol-map>
`,
})
export class Simple {} 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.
simple.react.tsximport { DefaultControls, DefaultInteractions, Coordinate, Map, OSMSource, TileLayer, View } from 'cc-openlayers/react';
/** A simple map with an OSM source. */
export function Simple() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={13}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
</Map>
);
}How the React version works
The smallest complete map: the default interactions and controls, a view on Kraków at zoom 13 and an OSM layer. It is the reference for the other ports: the JSX declaration has the same structure as the Angular template.
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-map height="480px"> | <Map height="480px"> |
<aol-interaction-default />, <aol-control-defaults /> | <DefaultInteractions />, <DefaultControls /> |
<aol-view [zoom]="13"> + <aol-coordinate> | <View zoom={13}> + <Coordinate> |
<aol-layer-tile><aol-source-osm /></aol-layer-tile> | <TileLayer><OSMSource /></TileLayer> |
| a component class without fields | a function that returns JSX |
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 example has no state of its own, so it needs no hook.
Architecture and OpenLayers mechanics
Whereas OpenLayers’ imperative map constructor silently attaches default pan/zoom interactions and default controls behind the scenes, the declarative wrapper uses strict opt-in composition. aol-map owns the DOM viewport, aol-view sets scale and centre, aol-layer-tile pairs with aol-source-osm for raster tiles, aol-interaction-default enables mouse, wheel and touch navigation, and aol-control-defaults mounts zoom, rotate and attribution widgets.
At zoom 13, Web Mercator ground resolution is roughly 19 metres per pixel at the equator and 12 metres per pixel at Kraków’s 50° N latitude—ideal for city-centre legibility on initial load.
How it works
aol-map,aol-view,aol-layer-tileandaol-source-osmassemble the map container, view, raster layer and OpenStreetMap source with an empty component class.- Interactions and widgets are opted into explicitly: without
aol-interaction-defaultthe map cannot be panned or zoomed, and withoutaol-control-defaultszoom buttons and data credits are omitted. - The view runs in Web Mercator to match standard XYZ tiles while
aol-coordinatewithsrid="EPSG:4326"specifies the Kraków centre in decimal degrees. height="480px"gives the host element a concrete pixel height before OpenLayers measures its canvas.
Pitfalls
- When porting imperative OpenLayers snippets, remember that the component library adds nothing behind your back: include both
aol-interaction-defaultandaol-control-defaultswhenever standard navigation and attribution are required. - Public OpenStreetMap tile servers require visible credit on the map and permit only light traffic; production apps with commercial or heavy usage must switch to a dedicated self-hosted or commercial tile service.
- Always load OpenLayers’ base CSS in global application styles so zoom buttons and collapsible attributions lay out properly inside the viewport corners.
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.