Skip to content

GeoTIFF 瓦片金字塔 ​

GeoTIFF 瓦片金字塔示例。 COG tilepyramid stac

云优化 GeoTIFF(COG)瓦片金字塔中的数据可以作为一组图层进行渲染。在本示例中,使用由 3 波段 GeoTIFF 组成的金字塔来渲染 RGB 数据。ol/source.sourcesFromTileGrid 辅助函数会按需从这个金字塔创建数据源。这些数据源所使用的 GeoTIFF 的分辨率范围与金字塔瓦片网格中单个 z 层级的分辨率范围相匹配。

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

// 元数据来自 https://s2downloads.eox.at/demo/EOxCloudless/2019/rgb/2019_EOxCloudless_rgb.json

// GeoTIFF 金字塔布局的瓦片网格
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
html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>GeoTIFF 瓦片金字塔</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
json
{
  "name": "cog-pyramid",
  "dependencies": {
    "ol": "10.11.0"
  },
  "devDependencies": {
    "vite": "^8.1.5"
  },
  "scripts": {
    "start": "vite",
    "build": "vite build"
  }
}