STAC support
STAC support示例。 stac GeoTIFF COG layergroup
本示例使用 npm 包 ol-stac,它为 OpenLayers 添加了 STAC 支持。 例如,它可以将时空资产目录(STAC)Item 中的几何图形和资产以图层组的形式显示出来。 更多示例请访问 https://moregeo-it.github.io/ol-stac/en/latest/examples/。
main.js
js
import STAC from 'ol-stac';
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/WebGLTile.js';
import {register} from 'ol/proj/proj4.js';
import OSM from 'ol/source/OSM.js';
import proj4 from 'proj4';
register(proj4); // 支持源投影重投影所必需
const layer = new STAC({
url: 'https://s3.us-west-2.amazonaws.com/sentinel-cogs/sentinel-s2-l2a-cogs/10/T/ES/2022/7/S2A_10TES_20220726_0_L2A/S2A_10TES_20220726_0_L2A.json',
});
const background = new TileLayer({
source: new OSM(),
});
const map = new Map({
target: 'map',
layers: [background, layer],
view: new View({
center: [0, 0],
zoom: 0,
}),
});
layer.on('sourceready', () => {
const view = map.getView();
view.fit(layer.getExtent());
});index.html
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>STAC support</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": "stac-item",
"dependencies": {
"ol": "10.11.0",
"ol-stac": "^1.2.0",
"proj4": "2.20.9"
},
"devDependencies": {
"vite": "^8.1.5"
},
"scripts": {
"start": "vite",
"build": "vite build"
}
}