asweigart

generatePolylineJS.py - SF Muni Google Map

Feb 10th, 2014
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. import munipaths # get the path data we previously grabbed
  2. import random
  3.  
  4. COLORS = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', '#FF00FF', '#800000', '#008000', '#000080', '#808000', '#008080', '#800080']
  5.  
  6. fo = open('polylineJS.js', 'w')
  7.  
  8. for route in munipaths.munipaths.keys():
  9.     routeColor = random.choice(COLORS) # choose a random color for this route's paths
  10.  
  11.     for path in munipaths.munipaths[route]:
  12.         latlngJavaScript = []
  13.         for point in path:
  14.             latlngJavaScript.append('new google.maps.LatLng(%s, %s)' % (point['lat'], point['lon']))
  15.         latlngJavaScript = ', '.join(latlngJavaScript)
  16.  
  17.         polylineJavaScript = """var routePath = new google.maps.Polyline({
  18.    path: [%s],
  19.    strokeColor: '%s',
  20.    strokeOpacity: 1.0,
  21.    strokeWeight: 2
  22.  });
  23. routePath.setMap(map);
  24.  
  25. """ % (latlngJavaScript, routeColor)
  26.  
  27.         fo.write(polylineJavaScript)
  28. fo.close()
Add Comment
Please, Sign In to add comment