diff --git a/qsomap.py b/qsomap.py index a29b1b8..960854d 100644 --- a/qsomap.py +++ b/qsomap.py @@ -570,7 +570,7 @@ def render(ref_lat, ref_lon, output_stream, adif_stream): .marker_label { fill: blue; - font-size: 2px; + font-size: 8px; font-family: sans-serif; text-anchor: middle; } diff --git a/static/map.js b/static/map.js index ae966f3..434bbd0 100644 --- a/static/map.js +++ b/static/map.js @@ -4,15 +4,12 @@ function update_map(event) document.getElementById("svgcontainer").innerHTML = '

Generating, please wait…

'; - var lat = document.getElementById('lat').value; - var lon = document.getElementById('lon').value; - - request_url = new URL("/render/map.svg", document.URL); - request_url.searchParams.append("lat", lat); - request_url.searchParams.append("lon", lon); + var formdata = new FormData(document.getElementById('mapinfo')); var request = new XMLHttpRequest(); - request.open("GET", request_url); + + 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) { @@ -31,11 +28,11 @@ function update_map(event) link.innerHTML = "Download this map."; link_container.appendChild(link); // Or append it whereever you want - URL.revokeObjectURL(blobUrl); + //URL.revokeObjectURL(blobUrl); } else { console.warn(request.statusText, request.responseText); } }); - request.send(); + request.send(formdata); } diff --git a/static/style.css b/static/style.css index 6b555bc..5508706 100644 --- a/static/style.css +++ b/static/style.css @@ -31,6 +31,11 @@ div.form * input[type=text] { text-align: right; } +div.form * input[type=file] { + flex: 3; + margin-left: 1em; +} + div.form * input[type=submit] { flex: 1; } diff --git a/views/index.tpl b/views/index.tpl index 8039449..361d617 100644 --- a/views/index.tpl +++ b/views/index.tpl @@ -12,10 +12,11 @@

QSOMap: Azimuthal-equidistant SVG map generator

Here you can generate a map in azimuthal-equidistant projection for any point on Earth. You get a map where the specified coordinate is in the center, and all other locations are projected such that locations with the same physical distance from the given coordinate are also the same distance from the center on the map.

+

You can optionally upload an ADIF file. All QSOs that have a QTH locator attached are then marked on the map.

The generated output is a Scalable Vector Graphics (SVG) image that can be edited as needed. I recommend Inkscape as an SVG editor.

Please note: It may take a few seconds to generate the map. Please give it some time. The map will appear below the form along with a download link. If you have JavaScript disabled, the map will replace this page.

-
+
@@ -24,6 +25,10 @@
+
+ + +
diff --git a/web.py b/web.py index d8e6eb8..f9afa2c 100755 --- a/web.py +++ b/web.py @@ -1,15 +1,38 @@ #!/usr/bin/env python3 from bottle import Bottle, request, response, template, static_file -from io import StringIO +from io import StringIO, BytesIO import qsomap app = application = Bottle() -@app.route('/render/map.svg') +@app.get('/render/map.svg') +@app.post('/render/map.svg') def render(): svg_stream = StringIO() - qsomap.render(float(request.query.lat), float(request.query.lon), svg_stream, None) + + adiffile = request.files.get('adif') + if adiffile and len(adiffile.filename) > 0: + if adiffile.filename[-4:] not in ['.adi', '.adf'] and adiffile.filename[-5:] not in ['.adif']: + return "File extension not allowed." + + if adiffile.content_length > 1024 * 1024: + return "Maximum allowed ADIF file size: 1 MiB." + + # parse ADIF data as UTF-8 + adif_bytes = adiffile.file.read() + adif_unicode = adif_bytes.decode('utf-8') + + print("==========================================") + print(adif_unicode) + print("==========================================") + + adif_stream = StringIO(adif_unicode) + + qsomap.render(float(request.params.lat), float(request.params.lon), svg_stream, adif_stream) + else: + qsomap.render(float(request.params.lat), float(request.params.lon), svg_stream, None) + response.content_type = 'image/svg+xml' return svg_stream.getvalue() @@ -25,4 +48,4 @@ def send_static(filename): return static_file(filename, root='./static') if __name__ == "__main__": - app.run(host='localhost', port=8080) + app.run(host='localhost', port=8080, debug=True)