Vector data · Angular, React and OpenLayers
Polygons across the antimeridian
Render continuous trans-Pacific polygons across the 180th antimeridian in OpenLayers using extended Web Mercator coordinates and world wrapping.

What this example shows
On a global OpenStreetMap view centred on Kraków’s meridian, two rectangles spanning right across the 180° antimeridian—one over Kamchatka and the Bering Sea, another across the North Pacific—plus a reference line directly along 180° render as unbroken shapes repeated cleanly across every visible copy of Earth.
When you need it
Trans-Pacific flight corridors, maritime shipping zones, satellite swath footprints and territories such as Alaska, Chukotka or Fiji cross the ±180° dateline.
Splitting antimeridian polygons at ±180° often introduces an unwanted vertical stroke right down the middle of the feature; extending coordinates seamlessly past the projection edge lets OpenLayers draw each polygon whole.
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.
polygon-wrapping.tsimport { ChangeDetectionStrategy, Component } from '@angular/core';
import {
CollectionCoordinatesComponent,
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
FeatureComponent,
GeometryPolygonComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
ViewComponent,
} from 'cc-openlayers';
const edge = 20037508.342789244;
/**
* Two rectangles that cross the antimeridian, one past -180° and one past 180°, and a zero-width one along it, over
* OpenStreetMap: OpenLayers draws each of them whole in every world the map repeats.
*/
@Component({
selector: 'app-polygon-wrapping',
imports: [
CollectionCoordinatesComponent,
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
FeatureComponent,
GeometryPolygonComponent,
LayerTileComponent,
LayerVectorComponent,
MapComponent,
SourceOsmComponent,
SourceVectorComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="1">
<aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
</aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
<aol-layer-vector [updateWhileAnimating]="true" [updateWhileInteracting]="true">
<aol-source-vector>
@for (ring of rings; track $index) {
<aol-feature>
<aol-geometry-polygon><aol-collection-coordinates [coordinates]="[ring]" /></aol-geometry-polygon>
</aol-feature>
}
</aol-source-vector>
</aol-layer-vector>
</aol-map>
`,
})
export class PolygonWrapping {
protected readonly rings = [
box(-edge, -15000000, -edge, 15000000),
box(-edge - 2000000, 4500000, -edge + 4000000, 6500000),
box(edge - 4000000, 7500000, edge + 2000000, 9500000),
];
}
/** The closed ring of an extent. */
function box(minX: number, minY: number, maxX: number, maxY: number): number[][] {
return [
[minX, minY],
[minX, maxY],
[maxX, maxY],
[maxX, minY],
[minX, minY],
];
} 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.
polygon-wrapping.react.tsximport {
CollectionCoordinates,
Coordinate,
DefaultControls,
DefaultInteractions,
Feature,
Map,
OSMSource,
PolygonGeometry,
TileLayer,
VectorLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
const edge = 20037508.342789244;
/** The closed ring of an extent. */
function box(minX: number, minY: number, maxX: number, maxY: number): number[][] {
return [
[minX, minY],
[minX, maxY],
[maxX, maxY],
[maxX, minY],
[minX, minY],
];
}
const rings = [
box(-edge, -15000000, -edge, 15000000),
box(-edge - 2000000, 4500000, -edge + 4000000, 6500000),
box(edge - 4000000, 7500000, edge + 2000000, 9500000),
];
/** Each ring as the coordinates of a one-ring polygon. */
const polygons = rings.map((ring) => [ring]);
/**
* Two rectangles that cross the antimeridian, one past -180° and one past 180°, and a zero-width one along it, over
* OpenStreetMap: OpenLayers draws each of them whole in every world the map repeats.
*/
export function PolygonWrapping() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={1}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
<VectorLayer updateWhileAnimating={true} updateWhileInteracting={true}>
<VectorSource>
{polygons.map((polygon, index) => (
<Feature key={index}>
<PolygonGeometry>
<CollectionCoordinates coordinates={polygon} />
</PolygonGeometry>
</Feature>
))}
</VectorSource>
</VectorLayer>
</Map>
);
}How the React version works
Rectangles that cross the antimeridian, drawn whole in every repeated world.
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-layer-vector [updateWhileAnimating] [updateWhileInteracting]> | <VectorLayer updateWhileAnimating updateWhileInteracting> |
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
Taking edge as 180° in Web Mercator (20,037,508 metres), the two trans-dateline rectangles extend 2,000 projection km past +edge and −edge respectively (built as closed rings via box and rendered with @for), while a zero-width third feature marks the meridian itself.
Default VectorSource world wrapping repeats every polygon in each visible world copy, and enabling [updateWhileAnimating] and [updateWhileInteracting] keeps wrapped copies smoothly redrawn during pans and zooms.
How it works
edgemarks the 180° Web Mercator boundary (20,037,508 m), with two rectangles extending 2,000 projection km beyond each end and a zero-width feature along the line.- Default vector source wrapping draws complete copies of each trans-meridian polygon in every repeated world.
[updateWhileAnimating]and[updateWhileInteracting]keep wrapped geometries synced mid-pan and mid-zoom.- Closed coordinate rings generated by
boxmount declaratively via@for.
Pitfalls
- RFC 7946 GeoJSON recommends splitting antimeridian-crossing geometries into MultiPolygons at ±180°, which paints a visible seam down the dateline—keep coordinates continuous past ±180° for seamless OpenLayers display and split only when exporting to strict RFC 7946 APIs.
- A degenerate zero-width rectangle encloses zero area: it renders visually as a stroke line and never matches point-in-polygon interior tests.
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.