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

Last change on this file since 9207 was 9201, checked in by dennisw, 14 years ago

Better mousebounds with nodelist. Some delay with mouseposition though.

File size: 1.7 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.db.models import Max
10from django.http import HttpResponse
11from django.core import serializers
12from gheat.models import *
13from gheat import gmerc
14import logging
15import pygame
16import sys
17import tempfile
18
19def get_bounds(zoom,lat,lon):
20
21 # Getting max radius for zoomlevel. Note that it will make a square using this, not a circle.
22 SIZE = 250
23 tile_height = float(40008000) / (2 ** zoom)
24 meters_per_pixel = float(tile_height) / SIZE
25 radius = 150 / meters_per_pixel
26
27 # Getting pixel location for mouseposition
28 mouse_x, mouse_y = gmerc.ll2px(lat,lon,zoom)
29
30 max_x = int(mouse_x + radius)
31 max_y = int(mouse_y + radius)
32 min_x = int(mouse_x - radius)
33 min_y = int(mouse_y - radius)
34
35 max_lat, max_lon = gmerc.px2ll(max_x, min_y, zoom)
36 min_lat, min_lon = gmerc.px2ll(min_x, max_y, zoom)
37
38 return (max_lat, max_lon, min_lat, min_lon)
39
40
41def make_list(zoom,lat,lon):
42
43 maxlat, maxlon, minlat, minlon = get_bounds(zoom,lat,lon)
44
45 filter = {}
46 filter.update({
47 'ssid__contains' : 'WirelessLeiden',
48 'meting__latitude__lt' : maxlat,
49 'meting__longitude__lt' : maxlon,
50 'meting__latitude__gt' : minlat,
51 'meting__longitude__gt' : minlon
52 })
53
54 objquery = Accespoint.objects.filter(**filter).distinct()
55 nodelist = serializers.serialize('json', objquery, fields=('fields','ssid'))
56
57 return nodelist
58
59
60def serve_nodelist(request,zoom,lat,lon,):
61 nodelist = make_list(int(zoom), float(lat), float(lon))
62 return HttpResponse(nodelist, content_type = 'application/javascript; charset=utf8')
Note: See TracBrowser for help on using the repository browser.