原文链接及内容

运行界面

此示例使用npm包ol-stac,它为OpenLayers添加了STAC支持。例如,它可以将SpatioTemporal Asset CatalogSTACItems中的几何图形和资产显示为图层组。更多示例请访问:https://m-mohr.github.io/ol-stac/en/latest/examples/

main.js代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import Map from 'ol/Map.js';
import OSM from 'ol/source/OSM.js';
import STAC from 'ol-stac';
import TileLayer from 'ol/layer/WebGLTile.js';
import View from 'ol/View.js';
import proj4 from 'proj4';
import {register} from 'ol/proj/proj4.js';

register(proj4); // required to support source reprojection

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代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!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>