Styling and labels · Angular, React and OpenLayers
An SVG marker on a coordinate
Anchor a crisp scaled SVG map pin by its bottom edge on a WGS84 coordinate in OpenLayers using aol-style-icon and a fractional icon anchor.

What this example shows
Zoomed onto Wawel Castle in central Kraków over OpenStreetMap, a crisp vector SVG map pin (assets/marker.svg) scaled to 2× size stands anchored by its bottom edge on the exact geographic coordinate even as you zoom in and out.
When you need it
Store locators, parcel pins, incident markers and search results rely on teardrop or pushpin icons whose tip—not the middle of the image—must stay locked to the target coordinate across all zoom scales.
Rendering markers via aol-style-icon inside the WebGL/2D map canvas scales effortlessly to thousands of pins without flooding the DOM with HTML elements.
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.
marker.tsimport { ChangeDetectionStrategy, Component } from '@angular/core';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
FeatureComponent,
GeometryPointComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
StyleComponent,
StyleIconComponent,
ViewComponent,
} from 'cc-openlayers';
/** A point drawn as an SVG marker whose tip sits on the coordinate. */
@Component({
selector: 'app-marker',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
FeatureComponent,
GeometryPointComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
StyleComponent,
StyleIconComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="15"><aol-coordinate [x]="19.9356" [y]="50.054" srid="EPSG:4326" /></aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
<aol-layer-vector>
<aol-source-vector>
<aol-feature>
<aol-geometry-point><aol-coordinate [x]="19.9356" [y]="50.054" srid="EPSG:4326" /></aol-geometry-point>
<aol-style><aol-style-icon src="assets/marker.svg" [anchor]="[0.5, 1]" [scale]="2" /></aol-style>
</aol-feature>
</aol-source-vector>
</aol-layer-vector>
</aol-map>
`,
})
export class Marker {} 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.
marker.react.tsximport {
Coordinate,
DefaultControls,
DefaultInteractions,
Feature,
IconStyle,
Map,
OSMSource,
PointGeometry,
Style,
TileLayer,
VectorLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
const ANCHOR = [0.5, 1];
/** A point drawn as an SVG marker whose tip sits on the coordinate. */
export function Marker() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={15}>
<Coordinate x={19.9356} y={50.054} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<VectorLayer>
<VectorSource>
<Feature>
<PointGeometry>
<Coordinate x={19.9356} y={50.054} srid="EPSG:4326" />
</PointGeometry>
<Style>
<IconStyle src="assets/marker.svg" anchor={ANCHOR} scale={2} />
</Style>
</Feature>
</VectorSource>
</VectorLayer>
</Map>
);
}How the React version works
One point near the Main Square drawn as an SVG marker at twice its size, anchored at the tip of the pin.
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-feature> with <aol-geometry-point> and <aol-coordinate> | <Feature> with <PointGeometry> and <Coordinate> |
<aol-style> with <aol-style-icon [src] [anchor] [scale]> | <Style> with <IconStyle src anchor scale>; the anchor array is a module constant |
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
A point feature declared in WGS84 degrees (srid="EPSG:4326") carries an aol-style-icon loading assets/marker.svg at [scale]="2". Setting [anchor]="[0.5, 1]" in OpenLayers’ default fractional icon units (0..1 left-to-right, 0..1 top-to-bottom) shifts the registration point from the default [0.5, 0.5] image centre down to the horizontal midpoint of the bottom edge.
How it works
aol-style-iconloads vectorassets/marker.svgand enlarges it cleanly via[scale]="2".[anchor]="[0.5, 1]"pins the bottom edge of the icon (in fractional icon coordinates) to the map coordinate, so the drawn tip sits two source units above it.- Declaring
srid="EPSG:4326"lets the template specify Wawel’s coordinate in standard longitude and latitude degrees.
Pitfalls
- Leaving
anchorat OpenLayers’ default [0.5, 0.5] centres the pin graphic over the coordinate, making the bottom tip point significantly south of the real location at street zooms. - Always include explicit numeric width and
heightattributes on the root <svg> element of external SVG icons—dimensionless SVGs can render at 0 × 0 pixels in cross-browser canvas image loaders.
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.