From 27ead42619bdfd442e7798e2a4b2c5955e3bdb13 Mon Sep 17 00:00:00 2001 From: Priyansh Date: Wed, 17 Nov 2021 00:18:24 -0500 Subject: Rendering map using leaflet instead of folium --- dashboard/app.py | 29 ++++++++------- dashboard/templates/index.html | 82 +++++++++++++++++++++++++++++++----------- 2 files changed, 77 insertions(+), 34 deletions(-) diff --git a/dashboard/app.py b/dashboard/app.py index 7c0518e..0f45788 100644 --- a/dashboard/app.py +++ b/dashboard/app.py @@ -4,7 +4,6 @@ import folium import sqlite3 as sql from sqlite3 import Error import pandas as pd -import os app = Flask(__name__) @@ -17,26 +16,30 @@ def execute_sql_statement(sql_statement, conn): return rows +def get_list_of_dict(keys, list_of_tuples): + list_of_dict = [dict(zip(keys, values)) for values in list_of_tuples] + return list_of_dict + def get_cities_list(): conn = sql.connect("./database_files/pythonproject.db") - sql_statement = 'SELECT Country_Name FROM country_table' - df=pd.read_sql_query(sql_statement, conn) - return df[['Country_Name']] + sql_statement = 'SELECT DISTINCT(City_Name) as City_Name, Lat, Long FROM City_table join Loc_Table on City_Table.City_Id = Loc_table.City_Id' + df=pd.read_sql_query(sql_statement, conn).to_records(index=False) + return df @app.route("/") @app.route("/index") def index(): cities_list = get_cities_list() - print(cities_list) - - start_coords = (42.9974521, -78.7907883) - folium_map = folium.Map(location=start_coords, zoom_start=14) - _ = folium_map._repr_html_() - map_div = Markup(folium_map.get_root().html.render()) - hdr_txt = Markup(folium_map.get_root().header.render()) - script_txt = Markup(folium_map.get_root().script.render()) - return render_template("index.html", map_div=map_div, hdr_txt=hdr_txt, script_txt=script_txt) + keys = ("city", "latitude", "longitude") + cities_list = get_list_of_dict(keys, cities_list) + # start_coords = (42.9974521, -78.7907883) + # folium_map = folium.Map(location=start_coords, zoom_start=14) + # _ = folium_map._repr_html_() + # map_div = Markup(folium_map.get_root().html.render()) + # hdr_txt = Markup(folium_map.get_root().header.render()) + # script_txt = Markup(folium_map.get_root().script.render()) + return render_template("index.html", cities_list=cities_list) if __name__ == '__main__': diff --git a/dashboard/templates/index.html b/dashboard/templates/index.html index 820b756..229405c 100644 --- a/dashboard/templates/index.html +++ b/dashboard/templates/index.html @@ -7,9 +7,20 @@ Analyzing Climate Change using Earth Surface Temperature Visualization - {{ hdr_txt }} + + + +
@@ -17,27 +28,16 @@ class="bg-gray-800 text-gray-100 w-1/6 space-y-6 pt-6 px-0 absolute inset-y-0 left-0 transform md:relative md:translate-x-0 transition duration-200 ease-in-out md:flex md:flex-col md:justify-between overflow-y-auto" data-dev-hint="sidebar; px-0 for frameless; px-2 for visually inset the navigation">
- Analyzing Climate Change using Earth Surface Temperature Visualization - +

- \ No newline at end of file -- cgit v1.2.3