-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
70 lines (59 loc) · 3.09 KB
/
script.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
document.addEventListener('DOMContentLoaded', function () {
const fetchDataButton = document.getElementById('fetchData');
const getCapabilitiesInput = document.getElementById('getCapabilitiesURL');
const layerInfoContainer = document.getElementById('layerInfo');
fetchDataButton.addEventListener('click', function () {
const getCapabilitiesURL = getCapabilitiesInput.value;
if (getCapabilitiesURL) {
// Create a new XMLHttpRequest object
const xhr = new XMLHttpRequest();
// Configure the request
xhr.open('GET', getCapabilitiesURL, true);
// Define a function to handle the response
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
// Parse the XML response
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xhr.responseText, 'text/xml');
// Extract layer information
const layers = xmlDoc.querySelectorAll('Layer');
let layerInfoHTML = '';
layers.forEach((layer) => {
const idElement = layer.querySelector('Name');
const nameElement = layer.querySelector('Title');
const titleElement = layer.querySelector('Name');
const abstractElement = layer.querySelector('Abstract');
// Check if the elements exist before accessing textContent
const id = idElement ? idElement.textContent : 'N/A';
const name = nameElement ? nameElement.textContent : 'N/A';
const title = titleElement ? titleElement.textContent : 'N/A';
const abstract = abstractElement ? abstractElement.textContent : 'N/A';
// Add the layer information to the HTML
layerInfoHTML += `
<div>
<h2>Layer ID: ${id}</h2>
<p>Layer Name: ${name}</p>
<p>Layer Title: ${title}</p>
<p>Layer Abstract: ${abstract}</p>
</div>
`;
});
// Display the layer information
layerInfoContainer.innerHTML = layerInfoHTML;
} else {
console.error('Failed to retrieve GetCapabilities');
layerInfoContainer.innerHTML = '<p>Error: Failed to retrieve GetCapabilities.</p>';
}
};
// Handle network errors
xhr.onerror = function () {
console.error('Network error occurred');
layerInfoContainer.innerHTML = '<p>Error: Network error occurred.</p>';
};
// Send the request
xhr.send();
} else {
layerInfoContainer.innerHTML = '<p>Please enter a GetCapabilities URL.</p>';
}
});
});