Skip to content
This repository
Browse code

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

…ling
  • Loading branch information...
commit 7c2f3c08a6926450bf0cff2c61c3bd686528b1b3 1 parent 0fb152e
migurski authored September 18, 2012

Showing 1 changed file with 28 additions and 2 deletions. Show diff stats Hide diff stats

  1. 30  TileStache/Sandwich.py
30  TileStache/Sandwich.py
@@ -20,6 +20,12 @@
20 20
 
21 21
     {"src": "layer-name"}
22 22
 
  23
+Bitmap images can also be referenced by local filename or URL, and will be
  24
+tiled seamlessly, assuming 256x256 parent tiles:
  25
+
  26
+    {"src": "image.png"}
  27
+    {"src": "http://example.com/image.png"}
  28
+
23 29
 Layers can be limited to appear at certain zoom levels, given either as a range
24 30
 or as a single number:
25 31
 
@@ -113,6 +119,7 @@
113 119
 """
114 120
 from re import search
115 121
 from StringIO import StringIO
  122
+from itertools import product
116 123
 from urlparse import urljoin
117 124
 from urllib import urlopen
118 125
 
@@ -240,8 +247,27 @@ def local_bitmap(source, config, coord):
240 247
     address = urljoin(config.dirpath, source)
241 248
     bytes = urlopen(address).read()
242 249
     image = Image.open(StringIO(bytes)).convert('RGBA')
243  
-
244  
-    return Blit.Bitmap(image)
  250
+    
  251
+    coord = coord.zoomBy(8)
  252
+    w, h, col, row = image.size[0], image.size[1], int(coord.column), int(coord.row)
  253
+    
  254
+    x = w * (col / w) - col
  255
+    y = h * (row / h) - row
  256
+    
  257
+    output = Image.new('RGBA', (256, 256))
  258
+    
  259
+    for (x, y) in product(range(x, 256, w), range(y, 256, h)):
  260
+        # crop the top-left if needed
  261
+        xmin = 0 if x > 0 else -x
  262
+        ymin = 0 if y > 0 else -y
  263
+        
  264
+        # don't paste up and to the left
  265
+        x = x if x >= 0 else 0
  266
+        y = y if y >= 0 else 0
  267
+        
  268
+        output.paste(image.crop((xmin, ymin, w, h)), (x, y))
  269
+    
  270
+    return Blit.Bitmap(output)
245 271
 
246 272
 def layer_bitmap(layer, coord):
247 273
     """ Return Blit.Bitmap representation of tile from a given layer.

0 notes on commit 7c2f3c0

Please sign in to comment.
Something went wrong with that request. Please try again.