From 67b0914512d840774604e8c5580955de3d384bbd Mon Sep 17 00:00:00 2001 From: sstent Date: Mon, 3 Jun 2024 16:14:20 -0400 Subject: [PATCH] Update index.html --- index.html | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index f7ef0e2f61..5de01387ed 100644 --- a/index.html +++ b/index.html @@ -88,14 +88,37 @@ } // Fetch KML file metadata to get the update time - fetch(kmlUrl) + fetch(kmlURL) .then(response => response.text()) .then(data => { var parser = new DOMParser(); - var kmlDoc = parser.parseFromString(data, 'text/xml'); - var updateTime = kmlDoc.querySelector('updated').textContent; - var timeDifference = getTimeDifference(updateTime); - document.getElementById('banner').innerText = `Last updated: ${timeDifference} minutes ago`; + var kmlDoc = parser.parseFromString(data, 'application/xml'); + + // Try to find the update time + var updateTime; + var timeStamp = kmlDoc.querySelector('TimeStamp > when'); + if (timeStamp) { + updateTime = timeStamp.textContent; + } else { + var updated = kmlDoc.querySelector('updated'); + if (updated) { + updateTime = updated.textContent; + } + } + + if (updateTime) { + var timeDifference = getTimeDifference(updateTime); + document.getElementById('banner').innerText = `Last updated: ${timeDifference} minutes ago`; + } else { + document.getElementById('banner').innerText = 'Update time not found in KML file'; + } + + var kmlLayer = new L.KML(data); + map.addLayer(kmlLayer); + + // Adjust the map to fit the KML layer + var bounds = kmlLayer.getBounds(); + map.fitBounds(bounds); }) .catch(error => console.error('Error fetching KML:', error));