import wx from cStringIO import StringIO from tiledownloader import DownloadRequest, TileDownloader from tilecache import TileCoord, TileCache class GoogleTileCache(TileCache): downloader = None tilesize = (256,256) def validateCoords(self, coords): if coords.x < 0 or coords.y < 0: return False if coords.zoom < 0 or coords.zoom > 17: return False divs = 2 ** coords.zoom if coords.x >= divs or coords.y >= divs: return False return True def loadTile(self, coords, block): if not self.downloader: self.downloader = TileDownloader(["mt0.google.com", "mt1.google.com", "mt2.google.com", "mt3.google.com"]) path = "/mt?x=%d&y=%d&zoom=%d" % (coords.x, coords.y, 17 - coords.zoom) request = DownloadRequest(path) if self.validateCoords(coords): request = self.downloader.download(request, block) if not request: return None if not request.data: self.addTile(coords, self.emptytile) return self.emptytile buf = StringIO(request.data) image = wx.ImageFromStream(buf) self.addTile(coords, image) return image if __name__ == "__main__": import time tilecache = GoogleTileCache() image = False while not image: image = tilecache.getTile(TileCoord(1,1,16)) print image time.sleep(0.01)