Permalink
Browse files

Completed support for bitmaps in Sandwich layer source with global ti…

…ling
  • Loading branch information...
1 parent 0fb152e commit 7c2f3c08a6926450bf0cff2c61c3bd686528b1b3 @migurski migurski committed Sep 18, 2012
Showing with 28 additions and 2 deletions.
  1. +28 −2 TileStache/Sandwich.py
View
30 TileStache/Sandwich.py
@@ -20,6 +20,12 @@
{"src": "layer-name"}
+Bitmap images can also be referenced by local filename or URL, and will be
+tiled seamlessly, assuming 256x256 parent tiles:
+
+ {"src": "image.png"}
+ {"src": "http://example.com/image.png"}
+
Layers can be limited to appear at certain zoom levels, given either as a range
or as a single number:
@@ -113,6 +119,7 @@
"""
from re import search
from StringIO import StringIO
+from itertools import product
from urlparse import urljoin
from urllib import urlopen
@@ -240,8 +247,27 @@ def local_bitmap(source, config, coord):
address = urljoin(config.dirpath, source)
bytes = urlopen(address).read()
image = Image.open(StringIO(bytes)).convert('RGBA')
-
- return Blit.Bitmap(image)
+
+ coord = coord.zoomBy(8)
+ w, h, col, row = image.size[0], image.size[1], int(coord.column), int(coord.row)
+
+ x = w * (col / w) - col
+ y = h * (row / h) - row
+
+ output = Image.new('RGBA', (256, 256))
+
+ for (x, y) in product(range(x, 256, w), range(y, 256, h)):
+ # crop the top-left if needed
+ xmin = 0 if x > 0 else -x
+ ymin = 0 if y > 0 else -y
+
+ # don't paste up and to the left
+ x = x if x >= 0 else 0
+ y = y if y >= 0 else 0
+
+ output.paste(image.crop((xmin, ymin, w, h)), (x, y))
+
+ return Blit.Bitmap(output)
def layer_bitmap(layer, coord):
""" Return Blit.Bitmap representation of tile from a given layer.

0 comments on commit 7c2f3c0

Please sign in to comment.