Projections · Angular, React and OpenLayers

The world in Sphere Mollweide

Display world countries and a curved meridian graticule in the equal-area Sphere Mollweide projection (ESRI:53009) using proj4 in OpenLayers.

The countries of Europe, North Africa, the Middle East and the North Atlantic in pastel colours on white in the Sphere Mollweide projection, with grey meridians curving towards the edges and straight parallels.
A screenshot of the example. Countries: Natural Earth.

What this example shows

Opening at [zoom]="3" over Kraków across Europe, North Africa, the Middle East and the North Atlantic, world countries from assets/world/countries.geojson render in pastel colours inside the elliptical equal-area Sphere Mollweide projection (ESRI:53009), crossed by curved grey meridians and horizontal parallels (<aol-graticule />).

When you need it

Scientific atlases, oceanography reports and textbook world maps use Mollweide’s classic elliptical silhouette to present global area proportions faithfully within a compact oval frame.

Overlaying <aol-graticule /> makes curved meridians and latitude bands immediately readable despite strong peripheral shape shear.

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.

sphere-mollweide.shared.ts
import Projection from 'ol/proj/Projection.js';
import type { FlatStyle } from 'ol/style/flat.js';

/** The proj4 definition of the Sphere Mollweide projection. */
export const MOLLWEIDE_DEFINITION = '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs';

/** Each country takes one of seven colours, by its `mapcolor`; no two neighbours share one. */
export const COUNTRY_STYLE: FlatStyle = {
  'fill-color': [
    'match',
    ['get', 'mapcolor'],
    1,
    '#fbb4ae',
    2,
    '#b3cde3',
    3,
    '#ccebc5',
    4,
    '#decbe4',
    5,
    '#fed9a6',
    6,
    '#ffffcc',
    7,
    '#e5d8bd',
    '#eee',
  ],
};

/**
 * The Sphere Mollweide projection object with an extent and a world extent, which the graticule requires; its
 * definition must be registered with proj4 before the view is created.
 */
export function createMollweideProjection(): Projection {
  return new Projection({
    code: 'ESRI:53009',
    extent: [-18019909.21177587, -9009954.605703328, 18019909.21177587, 9009954.605703328],
    worldExtent: [-179, -89.99, 179, 89.99],
  });
}
sphere-mollweide.ts
import { ChangeDetectionStrategy, Component, inject, PendingTasks, signal } from '@angular/core';
import GeoJSON from 'ol/format/GeoJSON';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  LayerVectorComponent,
  loadProj4,
  MapComponent,
  registerProjectionDefinitions,
  SourceVectorComponent,
  ViewComponent,
} from 'cc-openlayers';
import { GraticuleComponent } from 'cc-openlayers/graticule';
import { COUNTRY_STYLE, createMollweideProjection, MOLLWEIDE_DEFINITION } from './sphere-mollweide.shared';

/**
 * The world's countries (Natural Earth) in the Sphere Mollweide projection, registered through proj4, with a
 * graticule; the view starts on Kraków. Each country takes one of seven colours no two neighbours share.
 */
@Component({
  selector: 'app-sphere-mollweide',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    GraticuleComponent,
    LayerVectorComponent,
    MapComponent,
    SourceVectorComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    @if (ready()) {
      <aol-map height="480px">
        <aol-interaction-default />
        <aol-control-defaults />
        <aol-view [projection]="projection" [zoom]="3">
          <aol-coordinate [x]="19.9373" [y]="50.0617" srid="EPSG:4326" />
        </aol-view>
        <!-- White around the countries, as on the original page. -->
        <aol-layer-vector background="#ffffff" [style]="style">
          <aol-source-vector
            url="assets/world/countries.geojson"
            [format]="format"
            attributions="Countries: Natural Earth"
          />
        </aol-layer-vector>
        <aol-graticule />
      </aol-map>
    }
  `,
})
export class SphereMollweide {
  /** True once ESRI:53009 is known to OpenLayers, which the view needs when it is created. */
  readonly ready = signal(false);
  protected readonly format = new GeoJSON();
  protected readonly style = COUNTRY_STYLE;
  protected readonly projection = createMollweideProjection();

  constructor() {
    void inject(PendingTasks).run(async () => {
      registerProjectionDefinitions(await loadProj4(), {
        'ESRI:53009': MOLLWEIDE_DEFINITION,
      });
      this.ready.set(true);
    });
  }
}

Architecture and OpenLayers mechanics

projection constructs new Projection({ for ESRI:53009 specifying both the projected elliptical extent and geographic worldExtent ([-179, -89.99, 179, 89.99]), backed by +proj=moll +lon_0=0 on a 6,371 km sphere via registerProjectionDefinitions.

Providing both extents allows <aol-graticule /> to sample geographic meridians/parallels across worldExtent and project them accurately over the countries loaded by new GeoJSON() and styled with a 'match' expression on mapcolor (background="#ffffff").

How it works

  • projection creates new Projection({ for ESRI:53009 with both elliptical and world extents, paired with registerProjectionDefinitions (+proj=moll +lon_0=0).
  • <aol-graticule /> relies on both worldExtent and projected extent to draw curved meridians and straight parallels.
  • Countries load from assets/world/countries.geojson (new GeoJSON()) styled via 'match' on mapcolor over background="#ffffff".
  • Starting at [zoom]="3" over Kraków highlights gentle central meridian curvature alongside equal-area country sizing.

Pitfalls

  • Registering +proj=moll via proj4 without constructing a Projection carrying explicit extent and worldExtent leaves <aol-graticule /> unable to determine meridian bounds and breaks default zoom scaling.
  • Mollweide sacrifices angular conformality near the outer limbs of the ellipse to preserve exact area everywhere—use it for global thematic comparisons rather than regional street navigation.

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.