equal
deleted
inserted
replaced
125 </div> |
125 </div> |
126 </div> |
126 </div> |
127 </div> |
127 </div> |
128 |
128 |
129 <script type="text/javascript"> |
129 <script type="text/javascript"> |
130 var tile_source = new Source("%(tile_url)s", %(tile_width)d, %(tile_height)d, -4, 0, %(img_width)d, %(img_height)d); |
130 var tile_source = new Source("%(tile_url)s", %(tile_width)d, %(tile_height)d, 0, 4, %(img_width)d, %(img_height)d); |
131 var main = new Viewport(tile_source, "viewport"); |
131 var main = new Viewport(tile_source, "viewport"); |
132 </script> |
132 </script> |
133 </body> |
133 </body> |
134 </html>""" % dict( |
134 </html>""" % dict( |
135 title = name, |
135 title = name, |
148 CACHE_THRESHOLD = 512 * 512 |
148 CACHE_THRESHOLD = 512 * 512 |
149 |
149 |
150 def scale_by_zoom (val, zoom) : |
150 def scale_by_zoom (val, zoom) : |
151 """ |
151 """ |
152 Scale dimension by zoom factor |
152 Scale dimension by zoom factor |
|
153 |
|
154 zl > 0 -> bigger |
|
155 zl < 0 -> smaller |
153 """ |
156 """ |
154 |
157 |
155 if zoom > 0 : |
158 if zoom > 0 : |
156 return val << zoom |
159 return val << zoom |
157 |
160 |
165 def check_cache_threshold (width, height, zl) : |
168 def check_cache_threshold (width, height, zl) : |
166 """ |
169 """ |
167 Checks if a tile with the given dimensions should be cached |
170 Checks if a tile with the given dimensions should be cached |
168 """ |
171 """ |
169 |
172 |
170 return (scale_by_zoom(width, -zl) * scale_by_zoom(height, -zl)) > CACHE_THRESHOLD |
173 return (scale_by_zoom(width, zl) * scale_by_zoom(height, zl)) > CACHE_THRESHOLD |
171 |
174 |
172 def render_raw (image, width, height, x, y, zl) : |
175 def render_raw (image, width, height, x, y, zl) : |
173 """ |
176 """ |
174 Render and return tile |
177 Render and return tile |
175 """ |
178 """ |
211 """ |
214 """ |
212 Render given tile, returning PNG data |
215 Render given tile, returning PNG data |
213 """ |
216 """ |
214 |
217 |
215 # remap coordinates by zoom |
218 # remap coordinates by zoom |
216 x = scale_by_zoom(x, -zoom) |
219 x = scale_by_zoom(x, zoom) |
217 y = scale_by_zoom(y, -zoom) |
220 y = scale_by_zoom(y, zoom) |
218 |
221 |
219 # do we want to cache this? |
222 # do we want to cache this? |
220 if check_cache_threshold(TILE_WIDTH, TILE_HEIGHT, zoom) : |
223 if check_cache_threshold(TILE_WIDTH, TILE_HEIGHT, zoom) : |
221 # go via the cache |
224 # go via the cache |
222 return render_cache(cache, image, TILE_WIDTH, TILE_HEIGHT, x, y, zoom) |
225 return render_cache(cache, image, TILE_WIDTH, TILE_HEIGHT, x, y, zoom) |
228 def img_png_region (image, cx, cy, zoom, width, height, cache) : |
231 def img_png_region (image, cx, cy, zoom, width, height, cache) : |
229 """ |
232 """ |
230 Render arbitrary tile, returning PNG data |
233 Render arbitrary tile, returning PNG data |
231 """ |
234 """ |
232 |
235 |
233 x = scale_by_zoom(cx - width / 2, -zoom) |
236 x = scale_by_zoom(cx - width / 2, zoom) |
234 y = scale_by_zoom(cy - height / 2, -zoom) |
237 y = scale_by_zoom(cy - height / 2, zoom) |
235 |
238 |
236 # safely limit |
239 # safely limit |
237 if width * height > MAX_PIXELS : |
240 if width * height > MAX_PIXELS : |
238 raise ValueError("Image size: %d * %d > %d" % (width, height, MAX_PIXELS)) |
241 raise ValueError("Image size: %d * %d > %d" % (width, height, MAX_PIXELS)) |
239 |
242 |