Class Structure of Map

This commit is contained in:
Miupro
2021-10-31 00:27:31 +02:00
parent ae0eecbea0
commit 2f9382eb2b
3 changed files with 138 additions and 21 deletions

View File

@@ -1,26 +1,30 @@
import folium
from folium import plugins
import json
#OpenStreetMap
m = folium.Map(location=[46.8132, 8.2242], tiles='CartoDB', zoom_start=7.6, min_zoom = 6, max_zoom = 12)
class SwissMap:
def __init__(self) -> None:
self.m = folium.Map(location=[46.8132, 8.2242], tiles='OpenStreetMap', zoom_start=7.6, min_zoom = 6, max_zoom = 12)
# Returns travel map of customer as html string
def customer_map(self, customer_id, location_list):
local_m = self.m
for place, coordinates in location_list:
folium.Marker(
location=coordinates, # coordinates for the marker
popup=place, # pop-up label for the marker
icon=folium.Icon(color="red")#, icon_color = 'red', icon="fa-map-marker-alt", prefix='fa')
).add_to(local_m)
local_m.save(f'static/swissmap_customer={customer_id}.html')
return(f'static/swissmap_customer={customer_id}.html')
# Working example
"""
# Hard coded location list
location_list = [('Center of Switzerland' , [46.8132, 8.2242]), ('Zermatt', [46.11654, 7.445683])]
customer_id = 235
for place, coordinates in location_list:
folium.Marker(
location=coordinates, # coordinates for the marker
popup=place, # pop-up label for the marker
icon=folium.Icon(color="red")#, icon_color = 'red', icon="fa-map-marker-alt", prefix='fa')
).add_to(m)
m.save('foliummap.html')
html_string = m.get_root().render()
print(html_string)
print('finish')
return html_string
cmap = SwissMap()
cmap.customer_map(customer_id, location_list)
"""

View File

@@ -36,7 +36,7 @@ header_dict = {'api_key' : '814d86a3ffc49c350bb7dcc48cac69b3'}
response = requests.get('https://journey-maps.api.sbb.ch:443', headers=header_dict)
print(response.text)
"""
"""