Add a raster tile source
Add a third-party raster source to the map.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Add a raster tile source</title>
<meta property="og:description" content="Add a third-party raster source to the map." />
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet' href='https://unpkg.com/maplibre-gl@5.9.0/dist/maplibre-gl.css' />
<script src='https://unpkg.com/maplibre-gl@5.9.0/dist/maplibre-gl.js'></script>
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
const map = new maplibregl.Map({
container: 'map', // container id
style: {
'version': 8,
'sources': {
'raster-tiles': {
'type': 'raster',
'tiles': ['https://tile.openstreetmap.org/{z}/{x}/{y}.png'],
'tileSize': 256,
'minzoom': 0,
'maxzoom': 19
}
},
'layers': [
{
'id': 'simple-tiles',
'type': 'raster',
'source': 'raster-tiles',
'attribution': "© OpenStreetMap contributors",
}
],
'id': 'blank'
},
center: [0, 0], // starting position
zoom: 0 // starting zoom
});
</script>
</body>
</html>