diff --git a/application/index.html b/application/index.html index bb48fc6b..5d0795a8 100644 --- a/application/index.html +++ b/application/index.html @@ -3,7 +3,7 @@ o.map - + diff --git a/application/index.js b/application/index.js index 483f0825..fa8f0886 100644 --- a/application/index.js +++ b/application/index.js @@ -339,6 +339,8 @@ document.addEventListener("DOMContentLoaded", function () { let osm_server_list_gpx = function () { let n = "Bearer " + localStorage.getItem("openstreetmap_token"); + //let token = "C_6istcvv43Lu6mQqfA0HqVQJ4jC6b_4L7mL6JSsXZs"; + //n = "Bearer " + token; const myHeaders = new Headers({ Authorization: n, @@ -391,32 +393,42 @@ document.addEventListener("DOMContentLoaded", function () { let osm_server_load_gpx = function (id) { let token = localStorage.getItem("openstreetmap_token"); - let n = "Bearer " + token; + console.log(token); + //token = "C_6istcvv43Lu6mQqfA0HqVQJ4jC6b_4L7mL6JSsXZs "; + let nn = "Bearer " + token; let url = "https://api.openstreetmap.org/api/0.6/gpx/" + id + "/data"; let xmlhttp = new XMLHttpRequest(); + helper.toaster(id, 1000); + xmlhttp.onreadystatechange = function () { - helper.toaster(xmlhttp.status, 1000); - helper.toaster(xmlhttp.response, 1000); + console.log(xmlhttp.getResponseHeader("Location")); + }; + + xmlhttp.onloadend = function () { + console.log(xmlhttp.getResponseHeader("Location")); }; xmlhttp.onload = function () { - if (xhr.status != 200) { - // HTTP error? - // handle error - alert("Error: " + xhr.status); - return; - } + console.log(xmlhttp.getResponseHeader("Location")); + }; - // get the response from xhr.response + xmlhttp.onerror = function () { + console.log(xmlhttp.getResponseHeader("Location")); }; + console.log(xmlhttp.status); + xmlhttp.open("GET", url, true); - xmlhttp.setRequestHeader("Authorization", n); - xmlhttp.withCredentials = true; - xmlhttp.timeout = 2000; + + xmlhttp.setRequestHeader("Authorization", nn); + xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + xmlhttp.setRequestHeader("Access-Control-Request-Method", "GET"); + xmlhttp.setRequestHeader("Access-Control-Allow-Methods", "GET"); + xmlhttp.send(null); - };; + helper.toaster("done", 1000); + }; let OAuth_osm = function () { let n = window.location.href; diff --git a/application/oauth.js b/application/oauth.js index fc995f86..64d17592 100644 --- a/application/oauth.js +++ b/application/oauth.js @@ -25,6 +25,7 @@ function getToken() { getToken().then((result) => { localStorage.setItem("openstreetmap_token", result.access_token); + alert(result.access_token); document.getElementById("success").innerText = "you are now successfully connected to the osm service"; diff --git a/docs/index.html b/docs/index.html index bb48fc6b..5d0795a8 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3,7 +3,7 @@ o.map - + diff --git a/docs/index.js b/docs/index.js index 40bff76d..5eabb573 100644 --- a/docs/index.js +++ b/docs/index.js @@ -338,8 +338,9 @@ document.addEventListener("DOMContentLoaded", function () { ///////////// let osm_server_list_gpx = function () { - //alert(localStorage.getItem("openstreetmap_token")); let n = "Bearer " + localStorage.getItem("openstreetmap_token"); + let token = "pVOCkTG-lfDjps6HMXEYDE_tBsnW76fT-Xnl8WFuX70"; + n = "Bearer " + token; const myHeaders = new Headers({ Authorization: n, @@ -391,34 +392,36 @@ document.addEventListener("DOMContentLoaded", function () { } let osm_server_load_gpx = function (id) { - let n = "Bearer " + localStorage.getItem("openstreetmap_token"); + let token = localStorage.getItem("openstreetmap_token"); + console.log(token); + token = "pVOCkTG-lfDjps6HMXEYDE_tBsnW76fT-Xnl8WFuX70"; + let nn = "Bearer " + token; + let url = "https://api.openstreetmap.org/api/0.6/gpx/" + id + "/data"; + let xmlhttp = new XMLHttpRequest(); + + xmlhttp.onreadystatechange = function () { + helper.toaster(xmlhttp.statusText, 1000); + //alert(xmlhttp.requestURL); + console.log(xmlhttp.getResponseHeader("Location")); + }; - const myHeaders = new Headers({ - Authorization: n, - }); + xmlhttp.onloadend = function () { + console.log(xmlhttp.getResponseHeader("Location")); + }; - fetch("https://api.openstreetmap.org/api/0.6/gpx/" + id + "/data", { - method: "GET", - headers: myHeaders, - redirect: "follow", - }) - .then(function (response) { - alert(response.status); - if (response.ok) { - return response.blob(); - } else { - throw new Error(Error); - } - }) - .then(function (data) { - alert(data); + xmlhttp.onload = function () { + console.log(xmlhttp.getResponseHeader("Location")); + }; - var file = window.URL.createObjectURL(data); - window.location.assign(file); - }) - .catch(function (error) { - alert(error); - }); + xmlhttp.open("GET", url, true); + + xmlhttp.setRequestHeader("Authorization", nn); + xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + xmlhttp.setRequestHeader("Access-Control-Request-Method", "GET"); + xmlhttp.setRequestHeader("Access-Control-Allow-Methods", "GET"); + + xmlhttp.send(null); + helper.toaster("done", 1000); }; let OAuth_osm = function () { @@ -431,7 +434,7 @@ document.addEventListener("DOMContentLoaded", function () { ); url.searchParams.append( "redirect_uri", - "https://strukturart.github.io/o.map/oauth.html" + "https://strukturart.github.io/o.map/" ); url.searchParams.append("scope", "read_gpx"); const windowRef = window.open(url.toString()); @@ -963,40 +966,40 @@ document.addEventListener("DOMContentLoaded", function () { map.on("zoomend", function (ev) { let zoom_level = map.getZoom(); if (zoom_level < 2) { - general.step = 10; + general.step = 20; } if (zoom_level > 2) { - general.step = 7.5; + general.step = 8; } if (zoom_level > 3) { - general.step = 5; + general.step = 4.5; } if (zoom_level > 4) { - general.step = 1; + general.step = 2.75; } if (zoom_level > 5) { - general.step = 0.5; + general.step = 1.2; } if (zoom_level > 6) { - general.step = 0.25; + general.step = 0.5; } if (zoom_level > 7) { - general.step = 0.1; + general.step = 0.3; } if (zoom_level > 8) { - general.step = 0.075; + general.step = 0.15; } if (zoom_level > 9) { - general.step = 0.05; + general.step = 0.075; } if (zoom_level > 10) { - general.step = 0.025; + general.step = 0.04; } if (zoom_level > 11) { - general.step = 0.01; + general.step = 0.02; } if (zoom_level > 12) { - general.step = 0.0075; + general.step = 0.01; } if (zoom_level > 13) { general.step = 0.005; @@ -1008,7 +1011,7 @@ document.addEventListener("DOMContentLoaded", function () { general.step = 0.001; } if (zoom_level > 16) { - general.step = 0.0001; + general.step = 0.0005; } }); diff --git a/docs/manifest.webapp b/docs/manifest.webapp index b30bd07c..806d9c95 100644 --- a/docs/manifest.webapp +++ b/docs/manifest.webapp @@ -23,7 +23,8 @@ "redirects": [ { - "from": "https://strukturart.github.io/o.map/oauth.html", + + "from": "https://strukturart.github.io/o.map/", "to": "/oauth.html" } ], diff --git a/docs/oauth.html b/docs/oauth.html index f9c4b829..22de7aa6 100644 --- a/docs/oauth.html +++ b/docs/oauth.html @@ -10,7 +10,8 @@ -you are now successfully connected to the osm service +
+ \ No newline at end of file diff --git a/docs/oauth.js b/docs/oauth.js index 441b790d..fc995f86 100644 --- a/docs/oauth.js +++ b/docs/oauth.js @@ -7,10 +7,7 @@ function getToken() { var urlencoded = new URLSearchParams(); urlencoded.append("code", code); urlencoded.append("grant_type", "authorization_code"); - urlencoded.append( - "redirect_uri", - "https://strukturart.github.io/o.map/oauth.html" - ); + urlencoded.append("redirect_uri", "https://strukturart.github.io/o.map/"); urlencoded.append("client_id", "KEcqDV16BjfRr-kYuOyRGmiQcx6YCyRz8T21UjtQWy4"); var requestOptions = { @@ -20,25 +17,22 @@ function getToken() { redirect: "follow", }; - fetch("https://www.openstreetmap.org/oauth2/token", requestOptions) - .then((response) => response.json()) - .then(function (p) { - alert(urlencoded); - alert(JSON.stringify(p)); - localStorage.setItem("openstreetmap_token", p.access_token); - }); + return fetch( + "https://www.openstreetmap.org/oauth2/token", + requestOptions + ).then((response) => response.json()); } -getToken(); -/* + getToken().then((result) => { - alert(result); localStorage.setItem("openstreetmap_token", result.access_token); + + document.getElementById("success").innerText = + "you are now successfully connected to the osm service"; + window.dispatchEvent( new CustomEvent("tokens", { detail: result, }) ); - // window.close(); + window.close(); }); - -*/