[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 |
|
---|
| 8 | from django.core.management import setup_environ
|
---|
| 9 | from django.http import HttpResponse
|
---|
[9186] | 10 | from django.core import serializers
|
---|
[9177] | 11 | from gheat.models import *
|
---|
[9201] | 12 | from gheat import gmerc
|
---|
[9177] | 13 |
|
---|
[9201] | 14 | def 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] | 36 | def 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({
|
---|
[9196] | 42 | 'ssid__contains' : 'WirelessLeiden',
|
---|
| 43 | 'meting__latitude__lt' : maxlat,
|
---|
| 44 | 'meting__longitude__lt' : maxlon,
|
---|
| 45 | 'meting__latitude__gt' : minlat,
|
---|
| 46 | 'meting__longitude__gt' : minlon
|
---|
[9186] | 47 | })
|
---|
| 48 |
|
---|
[9196] | 49 | objquery = Accespoint.objects.filter(**filter).distinct()
|
---|
| 50 | nodelist = serializers.serialize('json', objquery, fields=('fields','ssid'))
|
---|
[9186] | 51 |
|
---|
[9196] | 52 | return nodelist
|
---|
[9186] | 53 |
|
---|
[9201] | 54 |
|
---|
[9196] | 55 | def 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')
|
---|