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

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

Better mousebounds with nodelist. Some delay with mouseposition though.

File size: 1.7 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.db.models import Max
10from django.http import HttpResponse
[9186]11from django.core import serializers
[9177]12from gheat.models import *
[9201]13from gheat import gmerc
[9177]14import logging
15import pygame
16import sys
17import tempfile
18
[9201]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
[9196]41def make_list(zoom,lat,lon):
[9177]42
[9201]43 maxlat, maxlon, minlat, minlon = get_bounds(zoom,lat,lon)
[9196]44
[9186]45 filter = {}
46 filter.update({
[9196]47 'ssid__contains' : 'WirelessLeiden',
48 'meting__latitude__lt' : maxlat,
49 'meting__longitude__lt' : maxlon,
50 'meting__latitude__gt' : minlat,
51 'meting__longitude__gt' : minlon
[9186]52 })
53
[9196]54 objquery = Accespoint.objects.filter(**filter).distinct()
55 nodelist = serializers.serialize('json', objquery, fields=('fields','ssid'))
[9186]56
[9196]57 return nodelist
[9186]58
[9201]59
[9196]60def serve_nodelist(request,zoom,lat,lon,):
[9201]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.