Skip to content

Add a raster tile source

Add a third-party raster source to the map.

<!DOCTYPE html>
<html lang="en">
    <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='[email protected]/dist/maplibre-gl.css' />
    <script src='[email protected]/dist/maplibre-gl.js'></script>
        body { margin: 0; padding: 0; }
        html, body, #map { height: 100%; }
<div id="map"></div>
    const map = new maplibregl.Map({
        container: 'map', // container id
        style: {
            'version': 8,
            'sources': {
                'raster-tiles': {
                    'type': 'raster',
                    'tiles': [
                        // NOTE: Layers from Stadia Maps do not require an API key for localhost development or most production
                        // web deployments. See for details.
                    'tileSize': 256,
                        'Map tiles by <a target="_blank" href="">Stamen Design</a>; Hosting by <a href="" target="_blank">Stadia Maps</a>. Data &copy; <a href="" target="_blank">OpenStreetMap</a> contributors'
            'layers': [
                    'id': 'simple-tiles',
                    'type': 'raster',
                    'source': 'raster-tiles',
                    'minzoom': 0,
                    'maxzoom': 22
        center: [-74.5, 40], // starting position
        zoom: 2 // starting zoom