Skip to main content

helper for publishing data to Layar augmented reality browser from Django

Project description

============
django-layar
============

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.
Written by James Turk <jturk@sunlightfoundation.com>

Source: http://github.com/sunlightlabs/django-layar/

Requirements
============

python >= 2.4

django >= 1.0

Installation
============

To install run

``python setup.py install``

which will install the application into the site-packages directory.

Usage
=====

Layar Developer Key
--------------------

If you haven't already, it is necessary to `sign up with Layar <http://dev.layar.com>`_ to obtain an API key.

Set ``LAYAR_DEVELOPER_KEY='<YOUR_KEY>'`` in settings.py


Creating a ``LayarView`` subclass
---------------------------------

django-layar provides a class-based generic view at :class:`layar.LayarView`. In order to provide your own layers
it is necessary to inherit from this view and implement two simple functions (per layer).

The required functions are :func:`get_LAYERNAME_queryset` and :func:`poi_from_LAYERNAME_item`.

It is possible to serve as many layers as you desire from a single Layar endpoint, just make sure that the name of your functions matches the name you provide when registering your layers with Layar.com

:func:`get_LAYERNAME_queryset` is passed a number of arguments (see :class:`layar.LayarView` for detail)
and should return a queryset of the objects for :class:`LayarView` to paginate and return.

:func:`poi_from_LAYERNAME_item` is called on each item being returned, and should convert items
into :class:`POI` objects.

It is usually best to then create an instance of your derived class in your application's ``views.py``

Example::

# views.py

from django.contrib.gis.geos import Point
from myapp.models import BusStop
from layar import LayarView, POI

class BusStopLayar(LayarView):

# make sure to accept **kwargs
def get_busstop_queryset(self, latitude, longitude, radius, **kwargs):
return BusStop.objects.filter(location__distance_lt=(Point(longitude, latitude), radius))

def poi_from_recoverygov_item(self, item):
return POI(id=item.id, lat=item.location.y, lon=item.location.x, title=item.name,
line2=item.route_name, line3='Distance: %distance%')

# create an instance of BusStopLayar
busstop_layar = BusStopLayar()

In urls.py it is then necessary to map a URL directly to ``busstop_layar``::

# urls.py

from django.conf.urls.defaults import *

urlpatterns = patterns('',
url(r'^layar_endpoint/$', 'myapp.views.busstop_layar'),
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-layar-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file django-layar-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django-layar-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a3a4f72b30fc8cdf3653bd82c765101c9ca49b64bc20d2776005b8f74efaea7b
MD5 e28adddc602ca4923f8ef33a9aaffa16
BLAKE2b-256 0891c08347c2fa24bb6b6126d34253769ac7a9dabfc12bf9332f32ba1387b440

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page