Ignore:
Timestamp:
May 13, 2011, 12:23:52 PM (14 years ago)
Author:
dennisw
Message:

Having doubts about the way the query is being serialized.

Location:
src/django_gheat/website
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/website/nodelist.py

    r9186 r9196  
    1616import tempfile
    1717
    18 def make_list(swlat,swlon,nelat,nelon):
    19   import simplejson
     18def make_list(zoom,lat,lon):
     19
     20  maxlat = (lat + 0.01)
     21  maxlon = (lon + 0.01)
     22  minlat = (lat - 0.01)
     23  minlon = (lon - 0.01)
    2024
    2125  filter = {}
    2226  filter.update({
    23     'accespoint__ssid__contains' : 'WirelessLeiden',
    24     'latitude__lt' : swlat,
    25     'longitude__lt' : swlon,
    26     'latitude__gt' : nelat,
    27     'longitude__gt' : nelon
     27    'ssid__contains' : 'WirelessLeiden',
     28    'meting__latitude__lt' : maxlat,
     29    'meting__longitude__lt' : maxlon,
     30    'meting__latitude__gt' : minlat,
     31    'meting__longitude__gt' : minlon
    2832  })
    2933
    30   html = Meting.objects.filter(**filter).values('accespoint__ssid').distinct()
    31   nodelist = simplejson.dumps(list(html))
    32   return HttpResponse(nodelist, content_type = 'application/javascript; charset=utf8')
     34  objquery = Accespoint.objects.filter(**filter).distinct()
     35  nodelist = serializers.serialize('json', objquery, fields=('fields','ssid'))
    3336
    34 def serve_nodelist(request,swlat,swlon,nelat,nelon):
    35   html = make_list(float(swlat),float(swlon),float(nelat),float(nelon))
    36   return HttpResponse(html)
     37  return nodelist
    3738
     39def serve_nodelist(request,zoom,lat,lon,):
     40  html = make_list(int(zoom), float(lat), float(lon))
     41  return HttpResponse(html, content_type = 'application/javascript; charset=utf8')
     42
  • src/django_gheat/website/static/heatmap.js

    r9190 r9196  
    2121        map.events.register('click', map, GetMousePos);
    2222        function GetMousePos(pos) {
    23                 var pixbuffer = 100;
    24                 var sw = map.getLonLatFromPixel(new OpenLayers.Pixel(pos.xy.x+pixbuffer,pos.xy.y-pixbuffer));
    25                 var ne = map.getLonLatFromPixel(new OpenLayers.Pixel(pos.xy.x-pixbuffer,pos.xy.y+pixbuffer));
    26                 var pointsw = OpenLayers.Layer.SphericalMercator.inverseMercator(sw.lon, sw.lat);
    27                 var pointne = OpenLayers.Layer.SphericalMercator.inverseMercator(ne.lon, ne.lat);
    28                 getNodeList(pointsw, pointne);
     23                var pix = map.getLonLatFromPixel(new OpenLayers.Pixel(pos.xy.x,pos.xy.y));
     24                var mousepos = OpenLayers.Layer.SphericalMercator.inverseMercator(pix.lon, pix.lat);
     25                var zoomlevel = map.getZoom();
     26                getNodeList(zoom, mousepos);
    2927        }
    3028
     
    4947}
    5048
    51 function getNodeList(sw, ne){
     49function getNodeList(zoomlevel, mousepos){
    5250  var nodelist;
    5351  if (window.XMLHttpRequest){
     
    6260  nodelist.onreadystatechange=function(){
    6361    if (nodelist.readyState==4 && nodelist.status==200){
    64       txt=nodelist.responseText
     62      txt=nodelist.responseText;
    6563      document.getElementById('nodelist').innerHTML=txt;
    6664    }
    6765  }
    6866
    69   nodelist.open("GET","/website/nodelist/" + sw.lat + "," + sw.lon + "," + ne.lat + "," + ne.lon,true);
     67  nodelist.open("GET","/website/nodelist/" + zoomlevel + "," + mousepos.lat + "," + mousepos.lon,true);
    7068  nodelist.send();
    7169}
  • src/django_gheat/website/urls.py

    r9189 r9196  
    3131urlpatterns += patterns('website.nodelist',
    3232    url(
    33         regex = r'^nodelist/(?P<swlat>[0-9.]+),(?P<swlon>[0-9.]+),(?P<nelat>[0-9.]+),(?P<nelon>[0-9.]+)$',
     33        regex = r'^nodelist/(?P<zoom>\d+),(?P<lat>[0-9.]+),(?P<lon>[0-9.]+)$',
    3434        view = 'serve_nodelist',
    3535        name = 'serve_nodelist',
Note: See TracChangeset for help on using the changeset viewer.