source: src/django_gheat/website/nodelist.py@ 9267

Last change on this file since 9267 was 9244, checked in by dennisw, 13 years ago

Renamed foo_filter to serve_filters.
Fixed display of nodes in nodelist.

File size: 1.6 KB
Line 
1#!/usr/bin/env python
2#
3# View serving available WirelessLeiden Nodes in list on mouseover.
4#
5# Dennis Wagenaar
6# d.wagenaar@gmail.com
7
8from django.core.management import setup_environ
9from django.http import HttpResponse
10from django.core import serializers
11from gheat.models import *
12from gheat import gmerc
13
14def get_bounds(zoom,lat,lon):
15
16 # Getting max radius for zoomlevel. Note that it will make a square using this, not a circle.
17 SIZE = 250
18 tile_height = float(40008000) / (2 ** zoom)
19 meters_per_pixel = float(tile_height) / SIZE
20 radius = 150 / meters_per_pixel
21
22 # Getting pixel location for mouseposition
23 mouse_x, mouse_y = gmerc.ll2px(lat,lon,zoom)
24
25 max_x = int(mouse_x + radius)
26 max_y = int(mouse_y + radius)
27 min_x = int(mouse_x - radius)
28 min_y = int(mouse_y - radius)
29
30 max_lat, max_lon = gmerc.px2ll(max_x, min_y, zoom)
31 min_lat, min_lon = gmerc.px2ll(min_x, max_y, zoom)
32
33 return (max_lat, max_lon, min_lat, min_lon)
34
35
36def make_list(zoom,lat,lon):
37
38 maxlat, maxlon, minlat, minlon = get_bounds(zoom,lat,lon)
39
40 filter = {}
41 filter.update({
42 'ssid__contains' : 'WirelessLeiden',
43 'meting__latitude__lt' : maxlat,
44 'meting__longitude__lt' : maxlon,
45 'meting__latitude__gt' : minlat,
46 'meting__longitude__gt' : minlon
47 })
48
49 objquery = Accespoint.objects.filter(**filter).distinct()
50 nodelist = serializers.serialize('json', objquery, fields=('fields','ssid'))
51
52 return nodelist
53
54
55def serve_nodelist(request,zoom,lat,lon,):
56 nodelist = make_list(int(zoom), float(lat), float(lon))
57 return HttpResponse(nodelist, content_type = 'application/javascript; charset=utf8')
Note: See TracBrowser for help on using the repository browser.