Edit

GeoTIFF tile pyramid

cog13 tilepyramid1 stac2

Rendering a COG tile pyramid as layer group.

Data from a Cloud Optimized GeoTIFF (COG) tile pyramid can be rendered as a set of layers. In this example, a pyramid of 3-band GeoTIFFs is used to render RGB data. The ol/source.sourcesFromTileGrid helper function creates sources from this pyramid on demand. The GeoTIFFs used by those sources have a resolution range that matches the range of a single z of the pyramid tile grid.

main.js
import GeoTIFF from 'ol/source/GeoTIFF.js';
import Map from 'ol/Map.js';
import TileGrid from 'ol/tilegrid/TileGrid.js';
import View from 'ol/View.js';
import WebGLTileLayer from 'ol/layer/WebGLTile.js';
import {sourcesFromTileGrid} from 'ol/source.js';

// Metadata from https://s2downloads.eox.at/demo/EOxCloudless/2019/rgb/2019_EOxCloudless_rgb.json

// Tile grid of the GeoTIFF pyramid layout
const tileGrid = new TileGrid({
  extent: [-180, -90, 180, 90],
  resolutions: [0.703125, 0.3515625, 0.17578125, 8.7890625e-2, 4.39453125e-2],
  tileSizes: [
    [512, 256],
    [1024, 512],
    [2048, 1024],
    [4096, 2048],
    [4096, 4096],
  ],
});

const pyramid = new WebGLTileLayer({
  sources: sourcesFromTileGrid(
    tileGrid,
    ([z, x, y]) =>
      new GeoTIFF({
        sources: [
          {
            url: `https://s2downloads.eox.at/demo/EOxCloudless/2019/rgb/${z}/${y}/${x}.tif`,
          },
        ],
      }),
  ),
});

const map = new Map({
  target: 'map',
  layers: [pyramid],
  view: new View({
    projection: 'EPSG:4326',
    center: [0, 0],
    zoom: 0,
    showFullExtent: true,
  }),
});
index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>GeoTIFF tile pyramid</title>
    <link rel="stylesheet" href="node_modules/ol/ol.css">
    <style>
      .map {
        width: 100%;
        height: 400px;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map"></div>

    <script type="module" src="main.js"></script>
  </body>
</html>
package.json
{
  "name": "cog-pyramid",
  "dependencies": {
    "ol": "9.1.0"
  },
  "devDependencies": {
    "vite": "^3.2.3"
  },
  "scripts": {
    "start": "vite",
    "build": "vite build"
  }
}