Display a Globe with an Atmosphere in Maptoolkit Maps JS
Adding an atmosphere to a globe projection in Maptoolkit Maps JS is done by calling map.setFog() with color, high-color, space-color, and horizon-blend parameters. These values control the haze near the horizon and the transition into the space background. Use this when building an overview globe, a geopolitical visualization, or any map where a full-planet perspective is part of the visual experience.
const API_KEY = 'YOUR_API_KEY';
const map = new maptoolkit.Map({
container: 'map',
apiKey: API_KEY,
style: `https://styles.maptoolkit.net/maptoolkit/maptoolkit.summer.json?api_key=${API_KEY}`,
center: [13.0, 47.5],
zoom: 2,
attributionControl: { compact: false }
});
map.addControl(new maptoolkit.NavigationControl(), 'top-right');
map.on('style.load', () => {
map.setProjection({ type: 'globe' });
map.setFog({
color: 'rgb(186, 210, 235)',
'high-color': 'rgb(36, 92, 223)',
'horizon-blend': 0.02,
'space-color': 'rgb(11, 11, 25)',
'star-intensity': 0.6
});
});<!DOCTYPE html>
<html lang="en">
<head>
<title>Display a Globe with an Atmosphere - Maptoolkit Maps JS</title>
<meta property="og:description" content="Render a globe with an atmospheric sky effect using fog." />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/@maptoolkit/maps@11.0.0-beta.3/dist/maptoolkit.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@maptoolkit/maps@11.0.0-beta.3/dist/maptoolkit.css" />
<style>
html, body { width: 100%; height: 100%; margin: 0; padding: 0; background: #111; }
#map { width: 100%; height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
const API_KEY = 'YOUR_API_KEY';
const map = new maptoolkit.Map({
container: 'map',
apiKey: API_KEY,
style: `https://styles.maptoolkit.net/maptoolkit/maptoolkit.summer.json?api_key=${API_KEY}`,
center: [13.0, 47.5],
zoom: 2,
attributionControl: { compact: false }
});
map.addControl(new maptoolkit.NavigationControl(), 'top-right');
map.on('style.load', () => {
map.setProjection({ type: 'globe' });
map.setFog({
color: 'rgb(186, 210, 235)',
'high-color': 'rgb(36, 92, 223)',
'horizon-blend': 0.02,
'space-color': 'rgb(11, 11, 25)',
'star-intensity': 0.6
});
});
</script>
</body>
</html>Use the prompt below with any LLM to get the same result. Make sure the Maptoolkit MCP server is connected first — check out AI Integration & MCP to get started.
How it works
setFog does the atmosphere, and despite the name it is not ground fog: on a globe it
renders the halo and the space around the sphere.
The parameters split into three jobs. color and high-color are the atmosphere near the
horizon and higher up, so the gradient you see at the planet’s edge comes from the pair
rather than either alone. space-color fills everything outside the sphere.
horizon-blend controls how sharply atmosphere fades into space, where a low value like
0.02 gives a crisp edge and higher values a soft glow. star-intensity fades stars in
against the space colour.
Both setProjection and setFog are inside map.on('style.load'), because both attach to
a style.
Next steps
The fog parameters are the dials worth playing with: the horizon blend and the two atmosphere colours between them cover everything from a thin daylight halo to a deep twilight edge, and star intensity only reads against a dark space colour, which pairs with the Dark style rather than a light one.
Once the sphere looks right, the point is what you put on it. Global data is what justifies the projection, and an atmosphere over an empty globe is a screensaver rather than a map.