-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapping_tools.py
36 lines (32 loc) · 1.38 KB
/
mapping_tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import folium
from geopy import distance
def calcDist(stationLoc, userLoc):
try:
return int(distance.distance((stationLoc[0], stationLoc[1]),(userLoc[0], userLoc[1])).meters)
except:
return 0
def plotRoute(routeResponse, map):
mls = routeResponse.json()['features'][0]['geometry']['coordinates']
points = [(i[1], i[0]) for i in mls[0]]
folium.PolyLine(points, weight=5, opacity=1).add_to(map)
def toMarker(location, type, map):
match type:
case "bikes":
html = """{0}<br><br>Available bikes: {1}""".format(location.name, location.bikes)
iconType = "bicycle"
color = "darkblue"
case "docks":
html = """{0}<br><br>Available docks: {1}""".format(location.name, location.docks)
iconType = "charging-station"
color = "lightred"
case "start":
html = """Your location:<br>{0}<br>""".format(location.name)
iconType = "user-circle"
color = "green"
case "destination":
html = """Your destination:<br>{0}<br>""".format(location.name)
iconType = "map-pin"
color = "green"
iframe = folium.IFrame(html, figsize=(3,2))
popup = folium.Popup(iframe, max_width=200)
folium.Marker(location=location.coordinates, popup=popup, icon=folium.Icon(color=color, prefix='fa', icon=iconType)).add_to(map)