Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5ee569ca03 | ||
![]() |
c2858fa0fa | ||
![]() |
6a6b3af7d3 | ||
![]() |
fb46c3e18f |
@ -2,6 +2,12 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
0.2.0
|
||||
================
|
||||
- add custom radius handling
|
||||
- made accuracy and radius optional
|
||||
- new parameters: alt, search2/3, slider2/3, checkboxes
|
||||
|
||||
0.1.1 - March 4 2009
|
||||
====================
|
||||
- fix packaging issues
|
||||
|
2
README
2
README
@ -5,7 +5,7 @@ Django generic view for making `Layar <http://layar.com>`_ endpoints.
|
||||
|
||||
Provides abstract class that responds to Layar API requests in the appropriate format. By implementing two small functions it is possible to add a layer to the Layar augmented reality application for Android and iPhone.
|
||||
|
||||
django-layar is a project of Sunlight Labs (c) 2009.
|
||||
django-layar is a project of Sunlight Labs (c) 2010.
|
||||
Written by James Turk <jturk@sunlightfoundation.com>
|
||||
|
||||
Source: http://github.com/sunlightlabs/django-layar/
|
||||
|
6
conf.py
6
conf.py
@ -42,16 +42,16 @@ master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'django-layar'
|
||||
copyright = u'2009, James Turk'
|
||||
copyright = u'2010, James Turk'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '0.1.0'
|
||||
version = '0.2.0'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '0.1.0'
|
||||
release = '0.2.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
@ -36,15 +36,28 @@ class POI(object):
|
||||
additional lines of detail (use special token %distance% to
|
||||
display distance to POI) (<= 35 chars)
|
||||
``type``
|
||||
numerical type (0-3), can set meaning when publishing Layar
|
||||
numerical type, can set meaning when publishing Layar
|
||||
``attribution``
|
||||
bottom line of display, shown in small font (<= 45 chars)
|
||||
``dimension``
|
||||
changes how POI is displayed (defaults to 1)
|
||||
1 - point marker (default)
|
||||
2 - image used for POI
|
||||
3 - 3d object used for POI
|
||||
``alt``
|
||||
Real altitude of object in meters.
|
||||
``relative_alt``
|
||||
Relative altitude (in meters) of object with respect to user.
|
||||
``actions``
|
||||
list of dictionaries with 'label' and 'uri' keys
|
||||
list of dictionaries with ``label`` and ``uri`` keys
|
||||
as of Layar v3 the dictionaries may optionally include
|
||||
``autoTriggerOnly`` and ``autoTriggerOnly``
|
||||
'''
|
||||
|
||||
def __init__(self, id, lat, lon, title, actions=None, image_url=None,
|
||||
line2=None, line3=None, line4=None, type=0, attribution=None):
|
||||
line2=None, line3=None, line4=None, type=0, attribution=None,
|
||||
dimension=1, alt=None, transform=None, object_detail=None,
|
||||
relative_alt=None):
|
||||
self.id = str(id)
|
||||
self.lat = lat
|
||||
self.lon = lon
|
||||
@ -53,13 +66,24 @@ class POI(object):
|
||||
self.line2 = line2 # recommended max len 35
|
||||
self.line3 = line3
|
||||
self.line4 = line4
|
||||
self.type = type # must be 0..3
|
||||
self.type = type
|
||||
self.attribution = attribution # recommended max len 45
|
||||
self.dimension = dimension
|
||||
self.alt = alt
|
||||
self.transform = transform
|
||||
self.object = object_detail
|
||||
self.relativeAlt = relative_alt
|
||||
self.actions = actions
|
||||
|
||||
def to_dict(self):
|
||||
d = dict(self.__dict__)
|
||||
|
||||
# don't include optional attributes if not set
|
||||
remove_if_none = ('alt', 'transform', 'object', 'relativeAlt')
|
||||
for k in remove_if_none:
|
||||
if not d[k]:
|
||||
del d[k]
|
||||
|
||||
# do lat/long conversion
|
||||
if isinstance(self.lat, (float, Decimal)):
|
||||
d['lat'] = int(self.lat*1000000)
|
||||
@ -108,10 +132,13 @@ class LayarView(object):
|
||||
controls the maximum number of results across all pages (default: 50)
|
||||
``verify_hash``
|
||||
set to False to disable hash verification (useful for testing)
|
||||
``default_radius``
|
||||
radius to use if a radius is not passed
|
||||
'''
|
||||
|
||||
results_per_page = 15
|
||||
max_results = 50
|
||||
default_radius = 1000
|
||||
verify_hash = True
|
||||
|
||||
def __init__(self):
|
||||
@ -119,6 +146,9 @@ class LayarView(object):
|
||||
|
||||
def __call__(self, request):
|
||||
try:
|
||||
# parameters from http://layar.pbworks.com/GetPointsOfInterest
|
||||
|
||||
# required parameters
|
||||
user_id = request.GET['userId']
|
||||
developer_id = request.GET['developerId']
|
||||
developer_hash = request.GET['developerHash']
|
||||
@ -126,12 +156,31 @@ class LayarView(object):
|
||||
layer_name = request.GET['layerName']
|
||||
lat = float(request.GET['lat'])
|
||||
lon = float(request.GET['lon'])
|
||||
accuracy = int(request.GET['accuracy'])
|
||||
radius = int(request.GET['radius'])
|
||||
|
||||
# optional
|
||||
accuracy = request.GET.get('accuracy')
|
||||
if accuracy:
|
||||
accuracy = int(accuracy)
|
||||
radius = request.GET.get('radius')
|
||||
if radius:
|
||||
radius = int(radius)
|
||||
alt = request.GET.get('alt')
|
||||
if alt:
|
||||
alt = int(alt)
|
||||
page = int(request.GET.get('pageKey', 0))
|
||||
|
||||
# user defined UI elements
|
||||
radio_option = request.GET.get('RADIOLIST')
|
||||
search = request.GET.get('SEARCHBOX')
|
||||
search2 = request.GET.get('SEARCHBOX_2')
|
||||
search3 = request.GET.get('SEARCHBOX_3')
|
||||
slider = request.GET.get('CUSTOM_SLIDER')
|
||||
page = int(request.GET.get('pageKey', 0))
|
||||
slider2 = request.GET.get('CUSTOM_SLIDER_2')
|
||||
slider3 = request.GET.get('CUSTOM_SLIDER_3')
|
||||
checkboxes = request.GET.get('CHECKBOXLIST')
|
||||
if checkboxes:
|
||||
checkboxes = checkboxes.split(',')
|
||||
|
||||
except KeyError, e:
|
||||
return HttpResponseBadRequest('missing required parameter: %s' % e)
|
||||
|
||||
@ -154,7 +203,10 @@ class LayarView(object):
|
||||
|
||||
qs = qs_func(latitude=lat, longitude=lon, radius=radius,
|
||||
radio_option=radio_option, search_query=search,
|
||||
slider_value=slider)[:self.max_results]
|
||||
search_query2=search2, search_query3=search3,
|
||||
slider_value=slider, slider_value2=slider2,
|
||||
slider_value3=slider3, checkboxes=checkboxes)
|
||||
qs = qs[:self.max_results]
|
||||
|
||||
# do pagination if results_per_page is set
|
||||
if self.results_per_page:
|
||||
@ -177,6 +229,10 @@ class LayarView(object):
|
||||
pois = [poi_func(item) for item in qs]
|
||||
layar_response['hotspots'] = [poi.to_dict() for poi in pois]
|
||||
|
||||
# if radius wasn't sent pass back the radius used
|
||||
if not radius:
|
||||
layar_response['radius'] = self.default_radius
|
||||
|
||||
except LayarException, e:
|
||||
layar_response['errorCode'] = e.code
|
||||
layar_response['errorString'] = e.message
|
||||
|
Loading…
Reference in New Issue
Block a user