Want more features on Pastebin? Sign Up, it's FREE!
Guest

generatePolylineJS.py - SF Muni Google Map

By: asweigart on Feb 10th, 2014  |  syntax: Python  |  size: 0.91 KB  |  views: 106  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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()
clone this paste RAW Paste Data