Add a custom milkyway, stars and halo background to the globe
Customize the map background to create a red Milky Way effect and create a “toxic” halo around the Earth.
This option only takes effect when used in conjunction with the projection: 'globe' parameter.
In this example, we’ll use a Milky Way background, we will change the color of the stars to red and add a custom halo to create a toxic atmosphere effect.
NPM module setup
npm install --save @maptiler/sdk
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', // container's id or the HTML element in which the SDK will render the map
style: MapStyle.SATELLITE,
projection: "globe",
center: [83, 30.8],
zoom: 0,
halo: {
scale: 1,
stops: [
[0.0, "rgba(77,51,15,1)"],
[0.5, "rgba(255,111,0,0.5)"],
[0.75, "rgba(250,0,0,0.0)"],
],
},
space: {
color: "#ff0000",
preset: "milkyway-bright",
}
});
map.on('load', () => {
map.flyTo({ //zoom out the map so that the background of the stars can be seen better.
zoom: -1,
essential: true
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Add a custom milkyway, stars and halo background to the globe | NPM example</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%;
}
Learn more
For space customization and options, check the CubemapLayerConstructorOptions.
Related examples
Projection control (globe)
TutorialsToggle between Mercator and globe projections using map controls.