diff options
Diffstat (limited to 'chimere/views.py')
| -rw-r--r-- | chimere/views.py | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/chimere/views.py b/chimere/views.py index fdc4da0..835848a 100644 --- a/chimere/views.py +++ b/chimere/views.py @@ -29,6 +29,9 @@ from itertools import groupby import re from django.conf import settings +from django.contrib.gis.geos import GEOSGeometry +from django.contrib.gis.gdal.error import OGRException +from django.contrib.gis.measure import D from django.core import serializers from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse @@ -716,9 +719,40 @@ def route(request, area_name, lon1, lat1, lonlat_steps, lon2, lat2, jsonencoder = simplejson.JSONEncoder() total = jsonencoder.encode(total) desc = jsonencoder.encode(desc) + + # get associated POIs + try: + route = GEOSGeometry(jsons[0]) + except OGRException: + return HttpResponse(_(u"Bad geometry"), status=500) + cats = SubCategory.objects.filter(routing_warn=True, routing_available=True) + message = '' + if cats.count(): + points = [(m.point, m.categories.all()[0].icon) + for m in list(Marker.objects.filter(status='A', + categories__in=cats, point__distance_lte=(route, D(m=15)) + ).all())] + routes = Route.objects.filter(status='A', categories__in=cats, + route__crosses=route) + for rout in routes.intersection(route): + rt = rout.intersection + points.append((rt, rout.categories.all()[0].icon)) + for pt, icon in points: + st = '{"type":"Feature", "geometry":{ "type": "Point", '\ + '"coordinates": [ %f, %f ] }, "properties":{"icon_path":"%s",'\ + '"icon_width":%d, "icon_height":%d}}' % (pt.x, pt.y, + icon.image.url, icon.image.width, icon.image.height) + jsons.append(st) + if points: + message = getattr(settings, 'CHIMERE_ROUTING_WARN_MESSAGE', '') + if message: + message = ', "message":%s' % jsonencoder.encode( + "<p>%s</p>" % _(message)) + else: + message = '' data = '{"properties":{"total":%s, "description":%s}, '\ - '"type": "FeatureCollection", "features":[%s]}' % (total, desc, - ",".join(jsons)) + '"type": "FeatureCollection", "features":[%s]%s}' % (total, desc, + ",".join(jsons), message) return HttpResponse(data) def rss(request, area_name=''): |
