How to display a map with custom projections
This example shows how to configure Equal Earth and Equirectangular projections using the SDK JS preview build.
Warning
The features demonstrated here rely on a preview build of the JS SDK.
You can choose between pure projections (applied at all zoom levels) and presets (which automatically transition to Mercator on deep zoom). Set the type property to "equal" or "geodetic" for the adaptive presets, or use "equal-earth" and "equirectangular" for the pure projections.
NPM module setup
npm install --save @maptiler/sdk@4.0.3-projection.alpha.1
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';
config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
container: 'map',
style: MapStyle.STREETS,
center: [0, 20],
zoom: 1.5
});
map.on("style.load", () => {
// 'equal', 'equal-earth', 'geodetic', 'equirectangular'
map.setProjection({ type: 'equal' });
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Map projections</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div id="map"></div>
<script type="module" src="./main.js"></script>
</body>
</html>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
Related examples
Switch between “mercator” and “globe”
ExamplesProgrammatically switch between Mercator and globe map projections.
Projection control (globe)
TutorialsToggle between Mercator and globe projections using map controls.