source: src/django_gheat/wlheatmap/nodelist.py@ 11406

Last change on this file since 11406 was 9819, checked in by rick, 13 years ago

Correct annoying typo in naming of the acces*s* point.

File size: 1.6 KB
RevLine 
[9177]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
[9186]10from django.core import serializers
[9177]11from gheat.models import *
[9201]12from gheat import gmerc
[9177]13
[9201]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
[9196]36def make_list(zoom,lat,lon):
[9177]37
[9201]38 maxlat, maxlon, minlat, minlon = get_bounds(zoom,lat,lon)
[9196]39
[9186]40 filter = {}
41 filter.update({
[9596]42 'organization__name__startswith' : 'Wireless',
[9196]43 'meting__latitude__lt' : maxlat,
44 'meting__longitude__lt' : maxlon,
45 'meting__latitude__gt' : minlat,
46 'meting__longitude__gt' : minlon
[9186]47 })
48
[9819]49 objquery = Accesspoint.objects.filter(**filter).distinct()
[9196]50 nodelist = serializers.serialize('json', objquery, fields=('fields','ssid'))
[9186]51
[9196]52 return nodelist
[9186]53
[9201]54
[9196]55def serve_nodelist(request,zoom,lat,lon,):
[9201]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.