Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '2.0' of file:///home/git/repositories/farmsubsidy into 2.0

Conflicts:
	web/data/models.py
	web/data/templates/heatmap.html
  • Loading branch information...
commit afa3319afdc74009798f1331485c6696f555ebc3 2 parents abb232b + 472445d
Simon Roe authored
View
2  web/data/models.py
@@ -110,7 +110,7 @@ class GeoRecipient(geo_models.Model):
recipient = models.ForeignKey(Recipient, primary_key=True)
location = geo_models.PointField()
- #objects = geo_models.GeoManager()
+ objects = geo_models.GeoManager()
def __unicode__(self):
return self.pk
View
2  web/data/templates/heatmap.html
@@ -20,7 +20,7 @@
heatmap = new GTileLayer(copyrights, 10, 0);
heatmap.getTileUrl = function (tile, zoom) {
- base = '/gheat/';
+ base = '/tiles/';
color_scheme = 'firetrans';
url = base + color_scheme +'/'+ zoom +'/'
url += tile.x +','+ tile.y +'.png';
View
4 web/data/urls.py
@@ -46,4 +46,8 @@ def country_url(pattern, *args, **kwargs):
url(r'^heatmap$', 'heatmap', name='heatmap'),
+ url(r'^tiles/(?P<color_scheme>\w+)/(?P<zoom>\d+)/(?P<x>\d+),(?P<y>\d+).png$','serve_tile', name='serve_tile',),
+
+
+
)
View
35 web/data/views.py
@@ -415,4 +415,37 @@ def heatmap(request):
},
context_instance=RequestContext(request)
)
-
+
+
+
+from django.http import HttpResponse, HttpResponseBadRequest
+from gheat import dots, renderer, StorageBackend, color_schemes
+# from gheat_demo.tweetmap.models import TweetPoint
+
+def serve_tile(request,color_scheme,zoom,x,y):
+ # Check arguments
+ print "serving"
+ try:
+ assert color_scheme in color_schemes, ( "bad color_scheme: "
+ + color_scheme
+ )
+ assert zoom.isdigit() and x.isdigit() and y.isdigit(), "not digits"
+ zoom = int(zoom)
+ x = int(x)
+ y = int(y)
+ assert 0 <= zoom <= 30, "bad zoom: %d" % zoom
+ except AssertionError, err:
+ return HttpResponseBadRequest()
+
+ # Get image and storage backends
+ tile = renderer.Tile(models.GeoRecipient.objects.all(), color_scheme, dots, zoom, x, y, point_field='location')
+ storage_backend = StorageBackend()
+
+ # Grab the raw image data
+ if tile.is_empty():
+ bytes = storage_backend.get_emptytile_bytes(tile)
+ else: # tile.is_stale() or ALWAYS_BUILD:
+ bytes = storage_backend.get_tile_bytes(tile, 'farm')
+
+ # Write the bytes out to the HttpResponse
+ return HttpResponse(bytes, content_type="image/png")
View
3  web/global_settings.py
@@ -169,5 +169,6 @@
FILE_CACHE_PATH = ROOT_PATH + "/data/cache"
# GHEAT_ALWAYS_BUILD = False
-GHEAT_MEDIA_ROOT = MEDIA_ROOT + "heatmap/tiles/"
+GHEAT_FILESYSTEM_STORAGE_DIR = MEDIA_ROOT + "heatmap/tiles/"
GHEAT_BUILD_EMPTIES = False
+GHEAT_STORAGE_BACKEND = 1
Please sign in to comment.
Something went wrong with that request. Please try again.