55import osmnx as ox
66import networkx as nx
77import folium
8+ import base64
9+ from folium import IFrame
810ox .config (log_console = True , use_cache = True )
911try :
1012 conn = pymongo .
MongoClient (
'mongodb+srv://aditya:[email protected] /test' )
@@ -55,15 +57,74 @@ def distance():
5557 orig_node ,
5658 dest_node ,
5759 weight = optimizer )
58- print (shortest_route )
59- shortest_route_map = ox .plot_route_folium (graph , shortest_route , tiles = 'openstreetmap' )
60- start_latlng = (start_latlng [0 ], start_latlng [1 ])
61- end_latlng = (end_latlng [0 ], end_latlng [1 ])
62- start_marker = folium .Marker (location = start_latlng ,icon = folium .Icon (color = 'green' ))
63- end_marker = folium .Marker (location = end_latlng ,icon = folium .Icon (color = 'red' ))
60+ le = nx .shortest_path_length (graph ,orig_node ,dest_node , method = 'dijkstra' ,weight = optimizer )
61+ if optimizer == 'time' :
62+ Info = 'It will take you ' + str (le )+ ' minutes'
63+ elif optimizer == 'length' :
64+ Info = 'The distance between your source and target ' + str (le )+ ' meters'
65+ else :
66+ Info = 'Please select your source and target'
67+
68+ shortest_route_map = ox .plot_route_folium (graph , shortest_route , tiles = 'openstreetmap' ,tooptip = 'This tooltip will appear' )
69+ # Add Marker
70+ if source == 'Tech Park' :
71+ encoded = base64 .b64encode (open ('website/techpark.jpg' , 'rb' ).read ())
72+ html = '<img src="data:image/png;base64,{}">' .format
73+ iframe = IFrame (html (encoded .decode ('UTF-8' )), width = 400 , height = 350 )
74+ popup = folium .Popup (iframe , max_width = 400 )
75+ start_latlng = (start_latlng [0 ], start_latlng [1 ])
76+ start_marker = folium .Marker (location = start_latlng , icon = folium .Icon (color = 'green' ), popup = popup ,
77+ tooltip = source )
78+ elif source == 'BIO-Tech Block' :
79+ encoded = base64 .b64encode (open ('website/BioTech.jpg' , 'rb' ).read ())
80+ html = '<img src="data:image/png;base64,{}">' .format
81+ iframe = IFrame (html (encoded .decode ('UTF-8' )), width = 400 , height = 350 )
82+ popup = folium .Popup (iframe , max_width = 400 )
83+ start_latlng = (start_latlng [0 ], start_latlng [1 ])
84+ start_marker = folium .Marker (location = start_latlng , icon = folium .Icon (color = 'green' ), popup = popup ,
85+ tooltip = html )
86+ elif source == 'SRM University Building' :
87+ encoded = base64 .b64encode (open ('website/ub.jpg' , 'rb' ).read ())
88+ html = '<img src="data:image/png;base64,{}">' .format
89+ iframe = IFrame (html (encoded .decode ('UTF-8' )), width = 400 , height = 350 )
90+ popup = folium .Popup (iframe , max_width = 400 )
91+ start_latlng = (start_latlng [0 ], start_latlng [1 ])
92+ start_marker = folium .Marker (location = start_latlng , icon = folium .Icon (color = 'green' ), popup = popup ,
93+ tooltip = html )
94+ else :
95+ start_latlng = (start_latlng [0 ], start_latlng [1 ])
96+ start_marker = folium .Marker (location = start_latlng , icon = folium .Icon (color = 'green' ), popup = source ,
97+ tooltip = source )
98+ if target == 'Tech Park' :
99+ encoded_t = base64 .b64encode (open ('website/techpark.jpg' , 'rb' ).read ())
100+ html_t = '<img src="data:image/png;base64,{}">' .format
101+ iframe_t = IFrame (html_t (encoded_t .decode ('UTF-8' )), width = 400 , height = 350 )
102+ popup_t = folium .Popup (iframe_t , max_width = 400 )
103+ end_latlng = (end_latlng [0 ], end_latlng [1 ])
104+ end_marker = folium .Marker (location = end_latlng , icon = folium .Icon (color = 'red' ), popup = popup_t ,tooltip = html_t )
105+ elif target == 'BIO-Tech Block' :
106+ encoded_t = base64 .b64encode (open ('website/BioTech.jpg' , 'rb' ).read ())
107+ html_t = '<img src="data:image/png;base64,{}">' .format
108+ iframe_t = IFrame (html_t (encoded_t .decode ('UTF-8' )), width = 400 , height = 350 )
109+ popup_t = folium .Popup (iframe_t , max_width = 400 )
110+ end_latlng = (end_latlng [0 ], end_latlng [1 ])
111+ end_marker = folium .Marker (location = end_latlng , icon = folium .Icon (color = 'red' ), popup = popup_t ,
112+ tooltip = html_t )
113+ elif target == 'SRM University Building' :
114+ encoded_t = base64 .b64encode (open ('website/ub.jpg' , 'rb' ).read ())
115+ html_t = '<img src="data:image/png;base64,{}">' .format
116+ iframe_t = IFrame (html_t (encoded_t .decode ('UTF-8' )), width = 400 , height = 350 )
117+ popup_t = folium .Popup (iframe_t , max_width = 400 )
118+ end_latlng = (end_latlng [0 ], end_latlng [1 ])
119+ end_marker = folium .Marker (location = end_latlng , icon = folium .Icon (color = 'red' ), popup = popup_t ,
120+ tooltip = html_t )
121+ else :
122+ end_latlng = (end_latlng [0 ], end_latlng [1 ])
123+ end_marker = folium .Marker (location = end_latlng , icon = folium .Icon (color = 'red' ), popup = target ,
124+ tooltip = target )
64125 # add the circle marker to the map
65126 start_marker .add_to (shortest_route_map )
66127 end_marker .add_to (shortest_route_map )
67128 shortest_route_map .save ('website/static/Destination_map.html' )
68- return render_template ('distance.html' , landmarks = landmark ,final_map = 'static/Destination_map.html' ,modes = ['walk' ,'bike' ,'drive' ],optims = ['length' ,'time' ])
69- return render_template ('distance.html' ,landmarks = landmark ,final_map = 'static/Destination_map.html' ,modes = ['walk' ,'bike' ,'drive' ],optims = ['length' ,'time' ])
129+ return render_template ('distance.html' , landmarks = landmark ,final_map = 'static/Destination_map.html' ,modes = ['walk' ,'bike' ,'drive' ],optims = ['length' ,'time' ], Info = Info )
130+ return render_template ('distance.html' ,landmarks = landmark ,final_map = 'static/Destination_map.html' ,modes = ['walk' ,'bike' ,'drive' ],optims = ['length' ,'time' ], Info = 'Please select your source and target' )
0 commit comments