Skip to content

Instantly share code, notes, and snippets.

@feesta
Created August 7, 2012 22:05
Show Gist options
  • Save feesta/3289831 to your computer and use it in GitHub Desktop.
Save feesta/3289831 to your computer and use it in GitHub Desktop.
Loads random tiles in the US with links to slippy maps at that location.
#!/usr/bin/env python
import cgi
import ModestMaps
import random
print "Content-type: text/html"
print
print """
<style>
img {height:64px; width:64px; background-color:#eee;}
</style>
"""
def get_tiles(num_of_places):
tiles = []
lat_bounds = [32,41.5]
lng_bounds = [-116.5,-80]
for i in range(num_of_places):
# Using bounds for the United States
lat = random.uniform(lat_bounds[0], lat_bounds[1])
lon = random.uniform(lng_bounds[0], lng_bounds[1])
zoom = round(random.uniform(12,18))
provider = ModestMaps.OpenStreetMap.Provider()
location = ModestMaps.Geo.Location(lat, lon)
coord = provider.locationCoordinate(location).zoomTo(zoom).container()
if coord.__dict__ is not None:
tiles.append(coord)
mm_url = "http://tile.stamen.com/watercolor/preview.html#" + str(zoom) + "/" + str(lat) + "/" + str(lon)
img = "<img src='http://tile.stamen.com/watercolor/%(zoom)d/%(column)d/%(row)d.jpg'>" % coord.__dict__
print "<a href='" + mm_url + "'>" + img + "</a>"
return tiles
if __name__ == "__main__":
tiles = get_tiles(256)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment