39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
function update_map(event)
|
|
{
|
|
event.preventDefault();
|
|
|
|
document.getElementById("svgcontainer").innerHTML = '<p id="loading">Generating, please wait…</p>';
|
|
|
|
var formdata = new FormData(document.getElementById('mapinfo'));
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.open("POST", "/render/map.svg", true);
|
|
//request.setRequestHeader('Content-type', 'multipart/form-data');
|
|
|
|
request.addEventListener('load', function(event) {
|
|
if (request.status >= 200 && request.status < 300) {
|
|
var svgblob = new Blob([request.responseText], { type: "image/svg+xml" });
|
|
|
|
document.getElementById("svgcontainer").innerHTML = request.responseText;
|
|
|
|
link_container = document.getElementById("downloadlink");
|
|
link_container.innerHTML = '';
|
|
|
|
var blobUrl = URL.createObjectURL(svgblob);
|
|
|
|
var link = document.createElement("a"); // Or maybe get it from the current document
|
|
link.href = blobUrl;
|
|
link.download = "map.svg";
|
|
link.innerHTML = "Download this map.";
|
|
link_container.appendChild(link); // Or append it whereever you want
|
|
|
|
//URL.revokeObjectURL(blobUrl);
|
|
} else {
|
|
console.warn(request.statusText, request.responseText);
|
|
}
|
|
});
|
|
|
|
request.send(formdata);
|
|
}
|