From db77a165b47c017f0f8de3975b03f045c1efaf3b Mon Sep 17 00:00:00 2001 From: KF7EEL Date: Fri, 26 Feb 2021 21:17:06 -0800 Subject: [PATCH] add map to dashboard --- README.md | 4 +++- requirements.txt | 3 +-- scripts/dashboard/dashboard.py | 23 +++++++++++++++++++ .../dashboard/dashboard_settings-SAMPLE.py | 4 ++++ scripts/dashboard/templates/header.html | 1 + scripts/dashboard/templates/map.html | 7 ++++++ 6 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 scripts/dashboard/templates/map.html diff --git a/README.md b/README.md index 054ed62..bac95ce 100755 --- a/README.md +++ b/README.md @@ -15,8 +15,10 @@ Files modified from original master branch of HBLink3: #### Optional Modules * Flask - Required for dashboard -* smtplib - Required for sending email. If pip fails to install module, it may already be installed as most Linux distrobutions have this module by default. +* smtplib - Required for sending email. If pip fails to install module, it may already be installed as most Linux distributions have this module by default. +* traceback - If pip fails to install module, it may already be installed as most Linux distrobutions have this module by default. * slixmpp - Required for upcoming XMPP gateway. +* folium - Required for mapping on dashboard. This should work for DMR radios that send location data as a UTF-8 NMEA sentence. I am hopping to add support for more radios in the future. diff --git a/requirements.txt b/requirements.txt index 5f54024..5fb5b78 100755 --- a/requirements.txt +++ b/requirements.txt @@ -4,8 +4,7 @@ Twisted>=16.3.0 dmr_utils3>=0.1.19 configparser>=3.0.0 aprslib>=0.6.42 -traceback pynmea2 maidenhead flask -smtplib +folium diff --git a/scripts/dashboard/dashboard.py b/scripts/dashboard/dashboard.py index dca65d8..2ac5e1c 100644 --- a/scripts/dashboard/dashboard.py +++ b/scripts/dashboard/dashboard.py @@ -24,6 +24,8 @@ This is a web dashboard for the GPS/Data application. from flask import Flask, render_template import ast, os from dashboard_settings import * +import folium +import re app = Flask(__name__) @@ -101,6 +103,10 @@ def get_bb_data(): return str('

Bulletin Board

' + tbl_hdr + bb_hdr + tmp_bb + tbl_ftr) except: return str('

No data

') +def aprs_to_latlon(x): + degrees = int(x) // 100 + minutes = x - 100*degrees + return degrees + minutes/60 @app.route('/') def index(): @@ -125,6 +131,23 @@ def help(): def about(): #return get_data() return render_template('about.html', title = dashboard_title, logo = logo, contact_name = contact_name, contact_call = contact_call, contact_email = contact_email, contact_website = contact_website) +@app.route('/view_map/') +def view_map(): + user_loc = ast.literal_eval(os.popen('cat /tmp/gps_data_user_loc.txt').read()) + #map_center = (47.9540700, -120.7360300) + folium_map = folium.Map(location=map_center, zoom_start=int(zoom_level)) + for user_coord in user_loc: + user_lat = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lat']))) + user_lon = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lon']))) + if 'S' in user_coord['lat']: + user_lat = -user_lat + if 'W' in user_coord['lon']: + user_lon = -user_lon + folium.Marker([user_lat, user_lon], popup="" + '' + str(user_coord['call']) + '' + '\n' + user_coord['time'] + "", tooltip=str(user_coord['call'])).add_to(folium_map) + return folium_map._repr_html_() +@app.route('/map/') +def map(): + return render_template('map.html', title = dashboard_title, logo = logo) if __name__ == '__main__': app.run(debug = True, port=dash_port, host=dash_host) diff --git a/scripts/dashboard/dashboard_settings-SAMPLE.py b/scripts/dashboard/dashboard_settings-SAMPLE.py index 1eb2b6b..1c36c8e 100644 --- a/scripts/dashboard/dashboard_settings-SAMPLE.py +++ b/scripts/dashboard/dashboard_settings-SAMPLE.py @@ -47,3 +47,7 @@ contact_name = 'your name' contact_call = 'N0CALL' contact_email = 'email@example.org' contact_website = 'https://hbl.ink' + +# Center dashboard map over these coordinates +map_center = (47.00, -120.00) +zoom_level = 7 diff --git a/scripts/dashboard/templates/header.html b/scripts/dashboard/templates/header.html index f76936a..0913a88 100644 --- a/scripts/dashboard/templates/header.html +++ b/scripts/dashboard/templates/header.html @@ -5,6 +5,7 @@ + diff --git a/scripts/dashboard/templates/map.html b/scripts/dashboard/templates/map.html new file mode 100644 index 0000000..0c5bdae --- /dev/null +++ b/scripts/dashboard/templates/map.html @@ -0,0 +1,7 @@ +{% include 'page.html' %} +{% include 'header.html' %} +{{description}} +

+

 

+{% include 'footer.html' %} +