-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwmts.js
More file actions
29 lines (25 loc) · 964 Bytes
/
wmts.js
File metadata and controls
29 lines (25 loc) · 964 Bytes
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
import TileLayer from "ol/layer/Tile";
import WMTSCapabilities from "ol/format/WMTSCapabilities";
import WMTS, { optionsFromCapabilities } from "ol/source/WMTS";
// Helper function to get a WMTS layer from theMapCloud
const getWMTSLayer = async (layerName) => {
// The first step is to fetch the GetCapabilities document
const response = await fetch("https://api.themapcloud.com/maps/wmts?" + new URLSearchParams({
request: "GetCapabilities",
service: "WMTS",
token: import.meta.env.VITE_TMC_TOKEN,
}));
// We then parse this...
const parser = new WMTSCapabilities();
const capabilities = parser.read(await response.text());
//...so that OL can create a WMTS Options object to configure the layer
const options = optionsFromCapabilities(capabilities, {
layer: layerName,
});
// Create the WMTS layer
const wmtsLayer = new TileLayer({
source: new WMTS(options),
});
return wmtsLayer;
};
export default getWMTSLayer;