Vector data · Angular, React and OpenLayers
Points, lines, polygons and circles
Declare Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon and Circle geometries declaratively in an OpenLayers template.

What this example shows
Across a street map of Kraków and its surroundings, one feature of every core OpenLayers geometry class renders simultaneously: a green single point, three black multi-points, blue single and multi-part lines, dark-red single and multi-part polygons, and a translucent yellow service-radius circle.
When you need it
Small sets of domain shapes—project boundaries, delivery depots, route corridors and coverage rings—often live directly in component state alongside forms rather than in external GIS files.
Declaring those features directly in markup binds their coordinates and styles to Angular or React component fields without manual imperative Feature construction or cleanup loops.
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.
display-geometry.tsimport { ChangeDetectionStrategy, Component } from '@angular/core';
import {
CollectionCoordinatesComponent,
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
FeatureComponent,
GeometryCircleComponent,
GeometryLinestringComponent,
GeometryMultiLinestringComponent,
GeometryMultiPointComponent,
GeometryMultiPolygonComponent,
GeometryPointComponent,
GeometryPolygonComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
StyleCircleComponent,
StyleComponent,
StyleFillComponent,
StyleStrokeComponent,
ViewComponent,
} from 'cc-openlayers';
/** One feature of every geometry type the library draws, each with its own style or the default one. */
@Component({
selector: 'app-display-geometry',
imports: [
CollectionCoordinatesComponent,
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
FeatureComponent,
GeometryCircleComponent,
GeometryLinestringComponent,
GeometryMultiLinestringComponent,
GeometryMultiPointComponent,
GeometryMultiPolygonComponent,
GeometryPointComponent,
GeometryPolygonComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
StyleCircleComponent,
StyleComponent,
StyleFillComponent,
StyleStrokeComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="11"><aol-coordinate [x]="20.0" [y]="50.055" 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.9373" [y]="50.0617" srid="EPSG:4326" /></aol-geometry-point>
<aol-style>
<aol-style-circle [radius]="10">
<aol-style-stroke color="black" [width]="5" />
<aol-style-fill color="green" />
</aol-style-circle>
</aol-style>
</aol-feature>
<aol-feature>
<aol-geometry-multipoint>
<aol-collection-coordinates [coordinates]="multiPoint" srid="EPSG:4326" />
</aol-geometry-multipoint>
<aol-style>
<aol-style-circle [radius]="5">
<aol-style-stroke color="black" [width]="5" />
<aol-style-fill color="green" />
</aol-style-circle>
</aol-style>
</aol-feature>
<aol-feature>
<aol-geometry-linestring>
<aol-collection-coordinates [coordinates]="lineString" srid="EPSG:4326" />
</aol-geometry-linestring>
</aol-feature>
<aol-feature>
<aol-geometry-multilinestring>
<aol-collection-coordinates [coordinates]="multiLineString" srid="EPSG:4326" />
</aol-geometry-multilinestring>
</aol-feature>
<aol-feature>
<aol-geometry-polygon>
<aol-collection-coordinates [coordinates]="polygon" srid="EPSG:4326" />
</aol-geometry-polygon>
<aol-style>
<aol-style-stroke color="rgba(90, 17, 26)" [width]="3" />
<aol-style-fill color="rgba(90, 17, 26, 0.5)" />
</aol-style>
</aol-feature>
<aol-feature>
<aol-geometry-multipolygon>
<aol-collection-coordinates [coordinates]="multiPolygon" srid="EPSG:4326" />
</aol-geometry-multipolygon>
<aol-style>
<aol-style-stroke color="rgba(81, 15, 23)" [width]="2" />
<aol-style-fill color="rgba(81, 15, 23, 0.4)" />
</aol-style>
</aol-feature>
<aol-feature>
<aol-geometry-circle [radius]="2000">
<aol-coordinate [x]="20.0373" [y]="50.0718" srid="EPSG:4326" />
</aol-geometry-circle>
<aol-style>
<aol-style-stroke color="blue" [width]="2" />
<aol-style-fill color="rgba(255, 255, 0, 0.5)" />
</aol-style>
</aol-feature>
</aol-source-vector>
</aol-layer-vector>
</aol-map>
`,
})
export class DisplayGeometry {
readonly multiPoint = [
[20.065, 49.987],
[20.217, 50.035],
[19.828, 49.975],
];
readonly lineString = [
[19.85, 50.04],
[19.9, 50.05],
[19.935, 50.05],
[19.96, 50.045],
[20.0, 50.04],
[20.05, 50.03],
];
readonly multiLineString = [
[
[19.88, 50.1],
[19.94, 50.11],
],
[
[19.88, 50.115],
[19.94, 50.125],
],
[
[19.88, 50.13],
[19.94, 50.14],
],
];
readonly polygon = [
[
[19.96, 50.075],
[19.99, 50.075],
[19.99, 50.09],
[19.96, 50.09],
[19.96, 50.075],
],
];
readonly multiPolygon = [
[
[
[20.1, 50.06],
[20.13, 50.06],
[20.13, 50.08],
[20.1, 50.08],
[20.1, 50.06],
],
],
[
[
[20.15, 50.06],
[20.18, 50.06],
[20.18, 50.08],
[20.15, 50.08],
[20.15, 50.06],
],
],
];
} 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.
display-geometry.react.tsximport {
CircleGeometry,
CircleStyle,
CollectionCoordinates,
Coordinate,
DefaultControls,
DefaultInteractions,
Feature,
Fill,
LineStringGeometry,
Map,
MultiLineStringGeometry,
MultiPointGeometry,
MultiPolygonGeometry,
OSMSource,
PointGeometry,
PolygonGeometry,
Stroke,
Style,
TileLayer,
VectorLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
const multiPoint = [
[20.065, 49.987],
[20.217, 50.035],
[19.828, 49.975],
];
const lineString = [
[19.85, 50.04],
[19.9, 50.05],
[19.935, 50.05],
[19.96, 50.045],
[20.0, 50.04],
[20.05, 50.03],
];
const multiLineString = [
[
[19.88, 50.1],
[19.94, 50.11],
],
[
[19.88, 50.115],
[19.94, 50.125],
],
[
[19.88, 50.13],
[19.94, 50.14],
],
];
const polygon = [
[
[19.96, 50.075],
[19.99, 50.075],
[19.99, 50.09],
[19.96, 50.09],
[19.96, 50.075],
],
];
const multiPolygon = [
[
[
[20.1, 50.06],
[20.13, 50.06],
[20.13, 50.08],
[20.1, 50.08],
[20.1, 50.06],
],
],
[
[
[20.15, 50.06],
[20.18, 50.06],
[20.18, 50.08],
[20.15, 50.08],
[20.15, 50.06],
],
],
];
/** One feature of every geometry type the library draws, each with its own style or the default one. */
export function DisplayGeometry() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={11}>
<Coordinate x={20.0} y={50.055} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<VectorLayer>
<VectorSource>
<Feature>
<PointGeometry>
<Coordinate x={19.9373} y={50.0617} srid="EPSG:4326" />
</PointGeometry>
<Style>
<CircleStyle radius={10}>
<Stroke color="black" width={5} />
<Fill color="green" />
</CircleStyle>
</Style>
</Feature>
<Feature>
<MultiPointGeometry>
<CollectionCoordinates coordinates={multiPoint} srid="EPSG:4326" />
</MultiPointGeometry>
<Style>
<CircleStyle radius={5}>
<Stroke color="black" width={5} />
<Fill color="green" />
</CircleStyle>
</Style>
</Feature>
<Feature>
<LineStringGeometry>
<CollectionCoordinates coordinates={lineString} srid="EPSG:4326" />
</LineStringGeometry>
</Feature>
<Feature>
<MultiLineStringGeometry>
<CollectionCoordinates coordinates={multiLineString} srid="EPSG:4326" />
</MultiLineStringGeometry>
</Feature>
<Feature>
<PolygonGeometry>
<CollectionCoordinates coordinates={polygon} srid="EPSG:4326" />
</PolygonGeometry>
<Style>
<Stroke color="rgba(90, 17, 26)" width={3} />
<Fill color="rgba(90, 17, 26, 0.5)" />
</Style>
</Feature>
<Feature>
<MultiPolygonGeometry>
<CollectionCoordinates coordinates={multiPolygon} srid="EPSG:4326" />
</MultiPolygonGeometry>
<Style>
<Stroke color="rgba(81, 15, 23)" width={2} />
<Fill color="rgba(81, 15, 23, 0.4)" />
</Style>
</Feature>
<Feature>
<CircleGeometry radius={2000}>
<Coordinate x={20.0373} y={50.0718} srid="EPSG:4326" />
</CircleGeometry>
<Style>
<Stroke color="blue" width={2} />
<Fill color="rgba(255, 255, 0, 0.5)" />
</Style>
</Feature>
</VectorSource>
</VectorLayer>
</Map>
);
}How the React version works
One feature of each geometry type the library draws (point, line, polygon, circle and their multi variants), with its own or the default style.
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-geometry-…> with <aol-collection-coordinates> | <…Geometry> with <CollectionCoordinates> |
<aol-style> with <aol-style-circle>, -fill, -stroke | <Style> with <CircleStyle>, <Fill>, <Stroke> |
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
Each aol-feature wraps a dedicated geometry element—aol-geometry-point, -multipoint, -linestring, -multilinestring, -polygon, -multipolygon or -circle—populated from component arrays via aol-collection-coordinates with srid="EPSG:4326" so degree tuples project automatically into Web Mercator.
Attaching a child aol-style overrides the layer style for that specific feature, while omitting it (as on the two line features) falls back cleanly to OpenLayers’ default blue stroke, and aol-geometry-circle expresses its radius in map projection units.
How it works
- Each
aol-featuremounts one geometry component (aol-geometry-point,-multipoint,-linestring,-multilinestring,-polygon,-multipolygonor-circle). aol-collection-coordinateswithsrid="EPSG:4326"transforms WGS84 degree arrays from component properties into the view projection.- Feature-level
aol-styleblocks override layer defaults, whereas unstyled line features inherit OpenLayers’ default stroke. aol-geometry-circledefines its radius in the map projection’s metre units.
Pitfalls
- Every linear ring of a polygon must close by repeating its first coordinate pair at the end—leaving a ring open produces malformed geometry.
- Analytical circles are not a native GeoJSON geometry type: serialise them either as a centre point plus numeric radius attribute or approximate them as a multi-vertex polygon before exporting to GeoJSON.
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.