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.

OpenStreetMap of the whole world with Kraków's meridian in the middle, a rectangle across the antimeridian over Kamchatka and the Bering Sea, another in the North Pacific at both edges of the map, and a line along the antimeridian.
A screenshot of the example. Map data © OpenStreetMap contributors.

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.ts
import { 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],
  ];
}

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

  • edge marks 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 box mount 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.

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.