def fit_bounds(cls, bounds): """Fit bounds to tiles matching tileswide and tileshigh. Returns corner tiles as a tuple.""" for zoom in range(tilesetcls.maxzoom, tilesetcls.minzoom-1, -1): tl, br = tilesetcls.bounds2cornertiles(bounds, zoom) tw,th = tilesetcls.cornertiles2tiledims(tl, br) if tw > cls.tileswide or th > cls.tileshigh: continue else: break #tl, br = cls.fit_width(tl, br) #tl, br = cls.fit_height(tl, br) return (tl, br)
def fit_height(cls, tl, br): """Adjust corner tiles to fit target height.""" tw, th = tilesetcls.cornertiles2tiledims(tl, br) zoom = tl.zoom for g in range(th, cls.tileshigh): if g % 2 : if tl.ytile > 0: tl.ytile = tl.ytile - 1 elif(br.ytile < 2**zoom-1): br.ytile = br.ytile + 1 else: break else: if(br.ytile < 2**zoom-1): br.ytile = br.ytile + 1 elif tl.ytile > 0: tl.ytile = tl.ytile - 1 else: break return (tl, br)
def fit_width(cls, tl, br): """Takes corner tiles and adjusts to fit target width of base map image.""" tw, th = tilesetcls.cornertiles2tiledims(tl, br) zoom = tl.zoom for g in range(tw, cls.tileswide): if g % 2 : if tl.xtile > 0: tl.xtile = tl.xtile - 1 elif(br.xtile < 2**zoom-1): br.xtile = br.xtile + 1 else: break else: if(br.xtile < 2**zoom-1): br.xtile = br.xtile + 1 elif tl.xtile > 0: tl.xtile = tl.xtile - 1 else: break return (tl, br)