-
Notifications
You must be signed in to change notification settings - Fork 0
/
getlayers.js
29 lines (20 loc) · 922 Bytes
/
getlayers.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
const xpath = require('xpath')
, dom = require('xmldom').DOMParser
, fetch = require('node-fetch')
, fs = require('fs');
async function main() {
let response= await fetch('https://services.datafordeler.dk/DKtopokort/dtk_1000/1.0.0/WMS??service=WMS&version=1.3.0&request=GetCapabilities&username=KEXVKJDPAA&password=DAFTest777!')
let text= await response.text();
var doc = new dom().parseFromString(text);
//var select = xpath.useNamespaces({"ns": "http://www.opengis.net/wmts/1.0"}); //WMS
var select = xpath.useNamespaces({"ns": "http://www.opengis.net/wms"}); //WMS
var nodes = select("//ns:Layer/ns:Layer/ns:Name/text()", doc)
let layers= [];
for (let i= 0; i<nodes.length; i++) {
layers.push(nodes[i].toString());
}
layers= layers.sort();
let layertekst= JSON.stringify(layers);
fs.writeFileSync('WMSdtk1000layers.js',layertekst);
}
main();