From ab4f60de868b01a3173e94df6e488a50509be4a0 Mon Sep 17 00:00:00 2001
From: pjaudiomv <34245618+pjaudiomv@users.noreply.github.com>
Date: Wed, 18 Oct 2023 10:56:54 -0400
Subject: [PATCH] Add support for KML (#2)
---
.gitignore | 1 +
README.md | 3 +-
assets/js/main.js | 160 +++-
index.html | 10 +-
package-lock.json | 2236 +++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 2389 insertions(+), 21 deletions(-)
create mode 100644 package-lock.json
diff --git a/.gitignore b/.gitignore
index f26db73..d6bfd79 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
build/
node_modules/
pages/
+scratch.html
diff --git a/README.md b/README.md
index 55738a5..c6d7a06 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
# BMLT Data Converter
-* Converts BMLT meeting data from a JSON endpoint to CSV
+* Converts BMLT meeting data from a JSON endpoint to CSV or KML
+ * Note that export of KML is only supported with GetSearchResults.
\ No newline at end of file
diff --git a/assets/js/main.js b/assets/js/main.js
index 14085ab..735bf52 100644
--- a/assets/js/main.js
+++ b/assets/js/main.js
@@ -1,18 +1,35 @@
-function fetchMeetings(query, callback) {
+let isProcessingCSV = false;
+let isProcessingKML = false;
+
+const fetchMeetings = (query, callback, isCSV, isKML) => {
const script = document.createElement("script");
- script.src = query + "&callback=" + callback.name;
+ script.src = `${query}&callback=${callback.name}`;
document.body.appendChild(script);
-}
+ isProcessingCSV = isCSV;
+ isProcessingKML = isKML;
+};
+
+const handleMeetingsData = (meetings) => {
+ if (isProcessingCSV) {
+ const csvContent = `data:text/csv;charset=utf-8,${encodeURIComponent(
+ convertToCSV(meetings)
+ )}`;
+ const downloadLink = document.getElementById("downloadLink");
+ downloadLink.href = csvContent;
+ downloadLink.style.display = "block";
+ }
-function handleMeetingsData(meetings) {
- const csvContent =
- "data:text/csv;charset=utf-8," + encodeURIComponent(convertToCSV(meetings));
- const downloadLink = document.getElementById("downloadLink");
- downloadLink.href = csvContent;
- downloadLink.style.display = "block";
-}
+ if (isProcessingKML) {
+ const kmlContent = `data:text/xml;charset=utf-8,${encodeURIComponent(
+ convertToKML(meetings)
+ )}`;
+ const kmlDownloadLink = document.getElementById("kmlDownloadLink");
+ kmlDownloadLink.href = kmlContent;
+ kmlDownloadLink.style.display = "block";
+ }
+};
-function convertToCSV(data) {
+const convertToCSV = (data) => {
const csvRows = [];
const keys = Object.keys(data[0]);
@@ -35,14 +52,127 @@ function convertToCSV(data) {
});
return csvRows.join("\n");
-}
+};
+
+const convertToKML = (data) => {
+ const kmlHeader = `
+
+