Rendering a STAC Item with geometry and COG.
This example uses the npm package ol-stac
which adds STAC support to OpenLayers.
It can for example show geometries and assets from SpatioTemporal Asset Catalog (STAC) Items as a layer group.
For more examples visit https://m-mohr.github.io/ol-stac/en/latest/examples/.
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());
});
<!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>
{
"name": "stac-item",
"dependencies": {
"ol": "10.2.1",
"ol-stac": "^1.0.0-beta.8",
"proj4": "2.12.1"
},
"devDependencies": {
"vite": "^3.2.3"
},
"scripts": {
"start": "vite",
"build": "vite build"
}
}