Skip to content
yourcelf edited this page Sep 13, 2010 · 3 revisions

olwidgets is a javascript library to replace textareas containing WKT (Well Known Text) geometry data with an editable map interface. This is designed to provide the functionality of Django’s GIS GeoAdmin interface, but outside of Django Admin sites.

An initial django widget is provided, in addition to the javascript implementation.

Using the django widget takes a few steps: copy or link the media files under your site’s MEDIA_URL, under the name “olwidget” (or specify an
alternate path in settings.OLWIDGET_MEDIA_URL). Add “olwidget” to your installed apps in settings.

When creating a form, specify the widget like so:

from django import forms from olwidget.widgets import OLWidget class MyForm(forms.Form): geom_field = forms.CharField(widget=OLWidget())

When using the form, you’ll have to include {{form.media}} at some point (probably in the

) in your template before displaying the form.

There are lots of options for customizing the map — see the list of “map_option_defaults” in the constructor for OLWidget for examples. Most of the options are passed on as JSON to the constructor for the javascript olwidget.Map instance. If you want to use google or yahoo layers, you need to put the appropriate API keys under “settings.GOOGLE_API_KEY” or “settings.YAHOO_APP_ID” respectively, and
then pass an option the likes of “layers=[‘google.streets’, ‘yahoo’]” to the constructor for the OLWidget.

Clone this wiki locally