From b61d9c06c979c8fb8f165ca2968540123a883fa3 Mon Sep 17 00:00:00 2001 From: nikilr2 Date: Tue, 21 Apr 2020 18:52:02 -0500 Subject: [PATCH 1/3] Json Parser- using input file method- yet to be fully completed --- jsonparser.html | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 jsonparser.html diff --git a/jsonparser.html b/jsonparser.html new file mode 100644 index 0000000..b66094e --- /dev/null +++ b/jsonparser.html @@ -0,0 +1,54 @@ + + + + + Read Text File + + + + + +
+ + + + + + + From 9dafcc7664cadfdbafce91f2285c7876632036cf Mon Sep 17 00:00:00 2001 From: nikilr2 Date: Mon, 27 Apr 2020 11:06:24 -0500 Subject: [PATCH 2/3] Added Json object to parse through --- index.html | 1865 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 1803 insertions(+), 62 deletions(-) diff --git a/index.html b/index.html index 2697031..99f2d56 100644 --- a/index.html +++ b/index.html @@ -1,85 +1,1826 @@ - + - - - + + + - MyNavigate - + MyNavigate + - - - - + + + + - - - + + + - - - - + + + -

- +

+ + +
+ + - + - \ No newline at end of file + From 105b16cf439fb470575d87e4278877e9f68ad634 Mon Sep 17 00:00:00 2001 From: nikilr2 Date: Mon, 27 Apr 2020 18:34:51 -0500 Subject: [PATCH 3/3] Added code to parse through the Json --- index.html | 90 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/index.html b/index.html index 99f2d56..80a8ade 100644 --- a/index.html +++ b/index.html @@ -1743,53 +1743,65 @@

}; - - - - - - function sendRequest(url) { + function parseJson(json_data) { var lat = []; var long = []; - // setting up XML request - var request = new XMLHttpRequest(); - request.open('GET', url); - request.setRequestHeader('Content-Type', 'application/json'); - request.setRequestHeader('x-api-key', api_key); - var toReturn = undefined; + + for (var i = 0; i < json_data.incidents.length; i++) { + lat.push(json_data.incidents[i].incident_latitude); + long.push(json_data.incidents[i].incident_longitude); + } + // alert(long.length); + // alert(lat.length); + for (var i = 0; i < lat.length; i++) { + marker = new L.marker([lat[i], long[i]]).addTo(map); + } + } + + function sendRequest(url) { + var lat = []; + var long = []; + // setting up XML request + var request = new XMLHttpRequest(); + request.open('GET', url); + request.setRequestHeader('Content-Type', 'application/json'); + request.setRequestHeader('x-api-key', api_key); + + var toReturn = undefined; - // code to handle the response from the request - request.onreadystatechange = function() { - if (this.readyState === 4) { - // alerts and log-printing for convenience temporarily- must use this data properly - // alert("Working") - // alert(this.responseText) - console.log('Status:', this.status); - console.log('Headers:', this.getAllResponseHeaders()); - console.log('Body:', this.responseText); - toReturn = this.responseText; - // alert("OSRC end"); - var toReturn = JSON.parse(this.responseText); - for (var i = 0; i < toReturn.incidents.length; i++) { - lat.push(toReturn.incidents[i].incident_latitude); - long.push(toReturn.incidents[i].incident_longitude); - } - // alert(long.length); - // alert(lat.length); - for (var i = 0; i < lat.length; i++) { - marker = new L.marker([lat[i], long[i]]).addTo(map); - } + // code to handle the response from the request + request.onreadystatechange = function() { + if (this.readyState === 4) { + // alerts and log-printing for convenience temporarily- must use this data properly + // alert("Working") + // alert(this.responseText) + console.log('Status:', this.status); + console.log('Headers:', this.getAllResponseHeaders()); + console.log('Body:', this.responseText); + toReturn = this.responseText; + // alert("OSRC end"); + var toReturn = JSON.parse(this.responseText); + for (var i = 0; i < toReturn.incidents.length; i++) { + lat.push(toReturn.incidents[i].incident_latitude); + long.push(toReturn.incidents[i].incident_longitude); + } + // alert(long.length); + // alert(lat.length); + for (var i = 0; i < lat.length; i++) { + marker = new L.marker([lat[i], long[i]]).addTo(map); } - }; + } + }; - request.send(); - // alert(toReturn + "is toReturn"); + request.send(); + // alert(toReturn + "is toReturn"); - } + } - //var value = sendRequest(url); - // alert(value); + //var value = sendRequest(url); + // alert(value); + parseJson(data);