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.

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.tsimport 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.tsimport { 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);
});
}
} 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.
sphere-mollweide.react.tsximport { useEffect, useState } from 'react';
import GeoJSON from 'ol/format/GeoJSON.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
Map,
VectorLayer,
VectorSource,
View,
} from 'cc-openlayers/react';
import { Graticule } from 'cc-openlayers/react/graticule';
import { loadProj4, registerProjectionDefinitions } from 'cc-openlayers/core';
import { COUNTRY_STYLE, createMollweideProjection, MOLLWEIDE_DEFINITION } from './sphere-mollweide.shared';
const FORMAT = new GeoJSON();
/**
* 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.
*/
export function SphereMollweide() {
/** True once ESRI:53009 is known to OpenLayers, which the view needs when it is created. */
const [ready, setReady] = useState(false);
const [projection] = useState(createMollweideProjection);
useEffect(() => {
void loadProj4().then((proj4) => {
registerProjectionDefinitions(proj4, { 'ESRI:53009': MOLLWEIDE_DEFINITION });
setReady(true);
});
}, []);
if (!ready) return null;
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View projection={projection} zoom={3}>
<Coordinate x={19.9373} y={50.0617} srid="EPSG:4326" />
</View>
{/* White around the countries, as on the original page. */}
<VectorLayer background="#ffffff" style={COUNTRY_STYLE}>
<VectorSource url="assets/world/countries.geojson" format={FORMAT} attributions="Countries: Natural Earth" />
</VectorLayer>
<Graticule />
</Map>
);
}sphere-mollweide.shared.tsimport 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],
});
}How the React version works
The world's countries in the equal-area Sphere Mollweide projection, ESRI:53009, defined through proj4, with a graticule, starting over Kraków.
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. Both versions import the proj4 definition, the country style and createMollweideProjection, the projection with the extents the graticule needs from the example's .shared.ts file, so the logic exists once.
From Angular to React
| Angular | React |
|---|---|
ready signal set inside PendingTasks.run and @if (ready()) | useState(false) set after loadProj4() resolves, and return null until then |
| the projection in a class field | useState(createMollweideProjection), so it is made once |
<aol-graticule /> | <Graticule /> |
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. loadProj4 and the registration of ESRI:53009 run in a useEffect with no dependencies; the component renders nothing until a state flag says the projection is known, as @if (ready()) does around PendingTasks.run in Angular. Under StrictMode the effect runs twice and registers the same definition twice, which changes nothing.
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
projectioncreatesnew Projection({forESRI:53009with both elliptical and world extents, paired withregisterProjectionDefinitions(+proj=moll +lon_0=0).<aol-graticule />relies on bothworldExtentand projectedextentto draw curved meridians and straight parallels.- Countries load from
assets/world/countries.geojson(new GeoJSON()) styled via'match'onmapcoloroverbackground="#ffffff". - Starting at
[zoom]="3"over Kraków highlights gentle central meridian curvature alongside equal-area country sizing.
Pitfalls
- Registering
+proj=mollviaproj4without constructing aProjectioncarrying explicitextentandworldExtentleaves<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.
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.