Skip to content

Add a COG raster source

Add an external Cloud Optimized Geotiff (COG) as source.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Add a COG raster source</title>
    <meta property="og:description" content="Add an external Cloud Optimized Geotiff (COG) as source." />
    <meta charset='utf-8'>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/trackasia-gl.css" />
    <script src="https://unpkg.com/[email protected]/dist/trackasia-gl.js"></script>
    <style>
        body { margin: 0; padding: 0; }
        html, body, #map { height: 100%; }
    </style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/@geomatico/[email protected]/dist/index.js"></script>
<script>
    trackasiagl.addProtocol('cog', MaplibreCOGProtocol.cogProtocol);

    const map = new trackasiagl.Map({
        container: 'map',
        style: 'https://static.track-asia.com/demotiles/styles/osm-bright-gl-style/style.json',
        center: [11.39831, 47.26244],
        zoom: 14
    });

    map.on('load', () => {
        map.addSource('cogSource', {
            type: 'raster',
            url: 'cog://https://docs.track-asia.com/assets/cog.tif',
            tileSize: 256
        });

        map.addLayer({
            id: 'cogLayer',
            source: 'cogSource',
            type: 'raster'
        });
    });
</script>
</body>
</html>