-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplot.py
49 lines (44 loc) · 1.23 KB
/
plot.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
37
38
39
40
41
42
43
44
45
46
47
48
49
import csv
import polyline
import sys
import settings
from gmplot import GoogleMapPlotter
key = settings.GOOGLE_MAPS_KEY
colors = [
'darkblue',
'darkcyan',
'darkgoldenrod',
'darkgray',
'darkgreen',
'darkkhaki',
'darkmagenta',
'darkolivegreen',
'darkorange',
'darkorchid',
'darksalmon',
'darkseagreen'
]
lat,lng = GoogleMapPlotter.geocode(settings.DEFAULT_MAP_SETTING,apikey=key)
if lat and lng:
gmap = GoogleMapPlotter(lat,lng,zoom=13,apikey=key)
else:
print("Google maps call failed. Try again")
def draw_locations(locations):
global gmap
for i,loc in enumerate(locations):
if i==0:
gmap.marker(float(loc['Lat']),float(loc['Lon']),color='yellow',label=loc['Id'],title=loc['Address'],info_window="Depot")
else:
gmap.marker(float(loc['Lat']),float(loc['Lon']),color="salmon",label=loc['Id'],title=loc['Address'])
def draw_map(locations,paths,file):
global gmap
draw_locations(locations)
for i,path in enumerate(paths):
x,y = zip(*polyline.decode(path))
gmap.plot(x,y,colors[i%10], edge_width=4)
gmap.draw(file)
if __name__ == '__main__':
filename = sys.argv[1]
with open(filename,'r') as file:
reader = csv.DictReader(file)
draw_map(reader,[],'input.html')