import wx from tilemanager import TileCoord class MapCoord: def __init__(self, lat, lon, zoom): self.lat = lat self.lon = lon self.zoom = zoom class MapManager: def __init__(self, tilemanager): self.tilemanager = tilemanager # The center of the map self.mappos = MapCoord(0.0, 0.0, 4.0) def tilecoords(self, lat, lon, zoom): '''Return the tile x and y positions as floats''' return 0., 0. def integerzoom(self): '''Choose the largest integer zoom level available at origo that is below/equal to the float''' sorted = list(self.tilemanager.zoomlevels) sorted.sort(reverse = True) # Largest first for zoomlevel in sorted: # It's better to scale up than down if zoomlevel > self.mappos.zoom: continue tilex, tiley = self.tilecoords(self.mappos.lat, self.mappos.lon, zoomlevel) if self.tilemanager.has_tile(TileCoord(tilex, tiley, zoomlevel)): return zoomlevel else: return 1 def makemap(self, width, height): izoom = self.integerzoom() zoomratio = (2 ** self.mappos.zoom) / (2 ** izoom) canvas = wx.EmptyImage(width * zoomratio, height * zoomratio) return canvas.scale(width, height)