Permalink
Browse files

cleanup

  • Loading branch information...
1 parent daa459b commit 3d80f63a333578cd7d97a24086725c781039e9d3 @jrasky jrasky committed May 23, 2012
Showing with 63 additions and 0 deletions.
  1. +1 −0 example/urls.py
  2. +55 −0 geocamLayer/static/geocamLayer/quad_tree_test.js
  3. +7 −0 geocamLayer/views.py
View
@@ -29,6 +29,7 @@
)
urlpatterns += patterns('geocamLayer',
(r'^points/(?P<zoom>[-.0-9]*)/(?P<x>[-.0-9]*)/(?P<y>[-.0-9]*)', 'views.points', {'objects':objects}),
+ (r'^quad/(?P<zoom>[-.0-9]*)/(?P<x>[-.0-9]*)/(?P<y>[-.0-9]*)', 'views.quadTree', {}),
(r'^$', 'views.main', {})
)
@@ -4,6 +4,8 @@ function initialize() {
window.points = new Array();
window.bboxes = new Object();
window.currentZoom = null;
+ window.currentX = new Array();
+ window.currentY = new Array();
// Try W3C Geolocation (Preferred)
if(navigator.geolocation) {
@@ -40,8 +42,61 @@ function initialize() {
}
map.setCenter(initialLocation);
}
+
+ // load initial data set
+ clearPoints();
+ boundsChanged();
+}
+
+function clearPoints() {
+ console.log("clearing points");
+ for (p=0;p<points.length;p++)
+ points[p].setVisible(false);
+ points = new Array();
+ bboxes = new Object();
+ currentX = new Array();
+ currentY = new Array();
}
function boundsChanged() {
console.log("bounds changed");
+ if (typeof(map.getBounds()) == 'undefined') return;
+ bounds = map.getBounds();
+ south = bounds.getSouthWest().lat();
+ west = bounds.getSouthWest().lng();
+ north = bounds.getNorthEast().lat();
+ east = bounds.getNorthEast().lng();
+ size = Math.max(south-north, east-west);
+
+ zoom = Math.ceil(Math.log(360/size)/Math.log(2));
+ if (isNaN(zoom)) zoom = 0;
+ zoom -= 1;
+ if (zoom < 0) zoom = 1;
+ if (zoom > 9) zoom = 9;
+ tile_size = 360/Math.pow(2,zoom);
+
+ center = map.getCenter();
+ x = Math.floor((center.lng()-(-180))/(tile_size/2));
+ y = Math.floor((center.lat()-(-90))/(tile_size/2));
+
+ document.title = "Static Tile HTML Test - Current Tile: "+zoom+"/"+x+"/"+y;
+ console.log("Current Tile: "+zoom+"/"+x+"/"+y);
+
+ if (currentZoom != zoom ||
+ currentX.indexOf(x) == -1 ||
+ currentY.indexOf(y) == -1
+ ) {
+ loadTile(zoom,x,y);
+ currentX[currentX.length] = x;
+ currentY[currentY.length] = y;
+ }
+}
+
+function loadTile(zoom,x,y) {
+ console.log("sending request");
+ $.get("/quad/"+zoom+"/"+x+"/"+y, gotData);
+}
+
+function gotData(data) {
+ console.log("got response");
}
View
@@ -26,6 +26,13 @@
def main(request):
return HttpResponseRedirect('/static/geojsontest.html')
+def quadTree(request, zoom, x, y):
+ top_coords = (0,x,y)
+ top_cell = QuadTreeCell.getCellAtIndex(top_coords)
+ features = Feature.objects.all().filter(cell=top_cell)
+ print "Got %s features (should be %s)" % (len(features), top_cell.count)
+ return HttpResponse('{}');
+
def points(request, zoom, x, y, objects, encoding=None):
zoom, x, y = [float(z) for z in [zoom, x, y]]
south = y - (90/(zoom))

0 comments on commit 3d80f63

Please sign in to comment.