From 5fb589507e8446e277faf7e205f2ef4e1baf2989 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Mon, 15 Jan 2024 11:00:56 -0600 Subject: [PATCH] Add markers to map. --- api_app.py | 26 +++++++++++++++++++++++++- templates/map.html | 5 ++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/api_app.py b/api_app.py index 4769f8d..a0ca74c 100644 --- a/api_app.py +++ b/api_app.py @@ -122,7 +122,31 @@ def index(): @api_app.route('/map') def map(): - return render_template('map.html') + + # Get the default list of frames from the API + frames = json.loads(requests.get(config['Settings']['base_url']+"/packets").text)['data'] + + # Make markers for all the frames + id_counter = 0 + markers = '' + for frame in frames: + if frame['latitude'] != None: + # Create unique ID for each marker + idd = 'frame' + str(id_counter) + id_counter += 1 + + # Create the marker and its pop-up for each shop + markers += "var {idd} = L.marker([{latitude}, {longitude}]);\ + {idd}.addTo(map).bindPopup('{from_ssid}');".format(idd=idd, latitude=frame['latitude'],\ + longitude=frame['longitude'], + from_ssid=frame['from'], + created=frame['created']) + + + return render_template('map.html', + station_lat = config['Settings']['station_lat'], + station_lon = config['Settings']['station_lon'], + markers = markers) class Packets(Resource): def get(self): diff --git a/templates/map.html b/templates/map.html index 824ddbd..87fe6d2 100644 --- a/templates/map.html +++ b/templates/map.html @@ -16,8 +16,11 @@
\ No newline at end of file