Add a COG raster source
A Cloud Optimized GeoTIFF (COG) is one image file laid out so the browser can read just the tiles it draws. A .tif URL on a raster source is all it takes: maplibre-yaml reads the file with the COG protocol, so there is no tile server and no page JavaScript. Here one COG is the imagery, and a second holds elevation, which shades the hills and lifts the map into 3D.
The complete document
Section titled “The complete document”# Cloud Optimized GeoTIFFs — YAML only. A .tif file name is the only# hint: imagery on a raster source, elevation on a raster-dem source (it# drives the hillshade layer and the 3D terrain). fitTo frames the imagery# file's own extent.# Synthetic, public-domain data (a fictional island).type: mapid: add-a-cog-raster-sourceconfig: center: [10.2, 42.15] zoom: 9 pitch: 50 mapStyle: "https://tiles.openfreemap.org/styles/positron" fitTo: { source: imagery, padding: 20 }legend: title: The islandsources: imagery: type: raster url: /gallery-assets/cloud-native/imagery.cog.tif elevation: type: raster-dem url: /gallery-assets/cloud-native/elevation.cog.tifterrain: source: elevation exaggeration: 1.5layers: - id: imagery type: raster source: imagery legend: { label: Imagery, color: "#789c5c", shape: square } - id: hills type: hillshade source: elevation paint: { hillshade-exaggeration: 0.5 } legend: { label: Hillshade, color: "#7f7f7f", shape: square }What to notice
Section titled “What to notice”type: rasterstays the MapLibre source type; the.tiffile name tells maplibre-yaml to read it as a COG. For a URL without the extension, addformat: cog.type: raster-demreads the same kind of file as elevation: it feeds thehillshadelayer andterrain:. Noencoding:ortileSize:is needed; maplibre-yaml sets what the COG reader produces.fitToframes the imagery file’s own extent, read from the file.- COGs must be in Web Mercator (EPSG:3857). A file in another projection is refused with the
gdalwarpcommand that converts it. - The files are read with HTTP range requests, so they need a host that supports them (GitHub Pages, Netlify, S3, R2; not
python -m http.server). - Data: synthetic and public domain (a fictional island), generated by
scripts/fixtures/cog.py.
More: Cloud Optimized GeoTIFF (COG) — single-band colour ramps, making a COG with GDAL, sizes, hosting, and what the map says when a file can’t be read.