Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created December 4, 2012 00:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/4199233 to your computer and use it in GitHub Desktop.
Save tmcw/4199233 to your computer and use it in GitHub Desktop.
ModestMaps-py Tiling with MapBox
# Requires ModestMaps to be installed
# Don't do this unless you have a very good reason, and a MapBox account,
# and you replace the 'examples' tileset with a tileset in your account.
import ModestMaps as MM
from ModestMaps.Geo import MercatorProjection, deriveTransformation
from ModestMaps.Providers import IMapProvider
from math import pi
class MapBox(IMapProvider):
def __init__(self):
t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1)
self.projection = MercatorProjection(0, t)
def tileWidth(self):
return 256
def tileHeight(self):
return 256
def getTileUrls(self, coordinate):
return ('http://api.tiles.mapbox.com/v3/examples.map-vyofok3q/%d/%d/%d.png' % (coordinate.zoom, coordinate.column, coordinate.row),)
m = MM.mapByCenterZoom(MapBox(), MM.Geo.Location(37.8, -78), 13, MM.Core.Point(1200, 600))
m.draw().save('map.png')
@wboykinm
Copy link

I think of MM as a js library. What do you mean by "Installed"? Are there py bindings?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment