|
Last change
on this file since 9347 was 9192, checked in by rick, 15 years ago |
|
Forgot to include actual osm_proxy caching code.
|
|
File size:
601 bytes
|
| Line | |
|---|
| 1 | #
|
|---|
| 2 | # Hack to cache OSM tile images locally, using file based django caching
|
|---|
| 3 | #
|
|---|
| 4 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
|---|
| 5 | #
|
|---|
| 6 | from django.views.decorators.cache import cache_page
|
|---|
| 7 | from django.http import HttpResponse
|
|---|
| 8 |
|
|---|
| 9 | import settings
|
|---|
| 10 | import random
|
|---|
| 11 | import urllib
|
|---|
| 12 |
|
|---|
| 13 | # Create your views here.
|
|---|
| 14 | @cache_page(cache=settings.OSM_CACHE)
|
|---|
| 15 | def osm_proxy(request,zoom,x,y):
|
|---|
| 16 | mirror = random.choice(['a','b','c'])
|
|---|
| 17 | url = 'http://%s.tile.openstreetmap.org/%s/%s/%s.png' % (mirror, zoom, x, y)
|
|---|
| 18 | data = urllib.urlopen(url).read()
|
|---|
| 19 | response = HttpResponse(mimetype="image/png")
|
|---|
| 20 | response.write(data)
|
|---|
| 21 | return response
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.