Source

django-leaflet-storage / README.rst

Django-Leaflet-Storage

Provide collaborative maps for your Django project.

Django-Leaflet-Storage is a backend for Leaflet.Storage, built on top of Geodjango and Leaflet.

It's in "molto alpha" stage, but already usable for proof-of-concept projects. Demo here

Goals:

  • plugable
  • extendable
  • light
  • edit in place

Supported features (others are planned: Circle, etc.):

  • Marker
  • Polyline
  • Polygon

Screenshots:

http://i.imgur.com/IL1I7.jpg http://i.imgur.com/cSJmN.jpg

Installation

Note

You will need a geo aware database. See Geodjango doc for backend installation.

Note

You will need Leaflet, Leaflet.Draw, Leaflet.Hash and Leaflet.Storage. They are submodules of this module, but pip will not fetch them automatically (will be the case in future version of pip).

Then you can pip install the rep, only from its repo for now:

pip install git+git://github.com/yohanboniface/django-leaflet-storage.git

Add leaflet_storage to you apps:

INSTALLED_APPS = (
    ...
    "leaflet_storage",
)

Include leaflet_storage urls:

(r'', include('leaflet_storage.urls')),

Create tables:

python manage.py syncdb

Basic usage

From the Django admin (for now), you need to create at least:

  • one TileLayer instance
  • one Map instance
  • one Category instance

Then, go to the map front page (something like http://localhost:8017/map/my-map-slug), and you will be able to add features (Marker, Polygon...).

Advanced configuration

Use your own models

Sometimes, you will need to add specific properties to the Marker, Polyline or Polygon. Its easy to do so with leaflet_storage.

Create a model that inherit from AbstractMarker (for Marker example):

from leaflet_storage.base_models import AbstractMarker


class MyMarker(AbstractMarker):
    # your fields here

Then, in your settings, add:

LEAFLET_STORAGE_MODELS = {
    "Marker": ('my_app', 'MyModel'),
}

Warning

Of course, you will need to do this before running the initial syncdb.

Decide which features are editable

For now, only Marker, Polyline and Polygon features are supported. Maybe you just want for example the Marker to be editable. For this, you will need to override the map configuration in JavaScript. You will have to explicity prevent the Polyline and Polygon editing, doing so:

<script>
    // create map_settings like the default template does
    map_settings.editOptions = {
            "polyline": null,
            "polygon": null
        }
    // Create the map like the default template does
</script>

Disabling totally inplace editing

Again, this have to be done in JavaScript:

<script>
    map_settings.allowEdit = false;
</script>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.