From 11eadcbaa80c99839ccc455203aa0cc52b87c1f1 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 9 Jun 2012 23:45:50 +0530 Subject: [PATCH] first commit --- fabfile.py | 46 +++++ openmumbai/__init__.py | 0 openmumbai/base/__init__.py | 0 openmumbai/base/models.py | 18 ++ openmumbai/base/tests.py | 23 +++ openmumbai/base/views.py | 1 + openmumbai/manage.py | 25 +++ openmumbai/places/__init__.py | 0 openmumbai/places/admin.py | 29 +++ openmumbai/places/import_csv.py | 24 +++ openmumbai/places/models.py | 18 ++ openmumbai/places/tests.py | 16 ++ openmumbai/places/views.py | 1 + openmumbai/settings.py | 179 ++++++++++++++++++ openmumbai/templates/gis/admin/google.html | 4 + openmumbai/templates/gis/admin/google.js | 11 ++ .../templates/gis/admin/openlayers.html | 38 ++++ openmumbai/templates/gis/admin/openlayers.js | 172 +++++++++++++++++ openmumbai/templates/gis/admin/osm.html | 2 + openmumbai/templates/gis/admin/osm.js | 2 + .../templates/gis/google/google-map.html | 12 ++ openmumbai/templates/gis/google/google-map.js | 37 ++++ .../templates/gis/google/google-multi.js | 8 + .../templates/gis/google/google-single.js | 2 + openmumbai/templates/gis/kml/base.kml | 6 + openmumbai/templates/gis/kml/placemarks.kml | 8 + .../templates/gis/sitemaps/geo_sitemap.xml | 17 ++ openmumbai/urls.py | 18 ++ requirements.txt | 4 + 29 files changed, 721 insertions(+) create mode 100644 fabfile.py create mode 100644 openmumbai/__init__.py create mode 100644 openmumbai/base/__init__.py create mode 100644 openmumbai/base/models.py create mode 100644 openmumbai/base/tests.py create mode 100644 openmumbai/base/views.py create mode 100644 openmumbai/manage.py create mode 100644 openmumbai/places/__init__.py create mode 100644 openmumbai/places/admin.py create mode 100644 openmumbai/places/import_csv.py create mode 100644 openmumbai/places/models.py create mode 100644 openmumbai/places/tests.py create mode 100644 openmumbai/places/views.py create mode 100644 openmumbai/settings.py create mode 100644 openmumbai/templates/gis/admin/google.html create mode 100644 openmumbai/templates/gis/admin/google.js create mode 100644 openmumbai/templates/gis/admin/openlayers.html create mode 100644 openmumbai/templates/gis/admin/openlayers.js create mode 100644 openmumbai/templates/gis/admin/osm.html create mode 100644 openmumbai/templates/gis/admin/osm.js create mode 100644 openmumbai/templates/gis/google/google-map.html create mode 100644 openmumbai/templates/gis/google/google-map.js create mode 100644 openmumbai/templates/gis/google/google-multi.js create mode 100644 openmumbai/templates/gis/google/google-single.js create mode 100644 openmumbai/templates/gis/kml/base.kml create mode 100644 openmumbai/templates/gis/kml/placemarks.kml create mode 100644 openmumbai/templates/gis/sitemaps/geo_sitemap.xml create mode 100644 openmumbai/urls.py create mode 100644 requirements.txt diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 0000000..414c29a --- /dev/null +++ b/fabfile.py @@ -0,0 +1,46 @@ +#this is a fabfile, use it with fab from http://fabfile.org/ +# +# initial setup: +# fab production setup +# +# deploy changes: +# fab production deploy +# + +from os.path import join +from fabric.api import run, local, sudo, put, env + +env.project_name = 'openmumbai' + +def production(): + env.hosts = ['%(project_name)s@topomancy.com'%env, ] + env.project_root = '/srv/%(project_name)s'%env + +def bzr_push(): + local('bzr push bzr+ssh://%(project_name)s@%(host)s%(project_root)s'%env) + +def bzr_update(): + run('cd %(project_root)s;bzr update'%env) + +def virtual_run(cmd, *a, **kw): + cmd = 'cd %s; source bin/activate; %s' % (env.project_root, cmd) + run(cmd, *a, **kw) + +def update_requirements(): + run('pip -E %(project_root)s install -r %(project_root)s/requirements.txt'%env) + +def setup(): + """ + Setup a fresh virtualenv + """ + local('bzr push --use-existing-dir bzr+ssh://%(project_name)s@%(host)s%(project_root)s'%env) + run('cd %(project_root)s; test -e .bzr/checkout || bzr checkout'%env) + run('virtualenv %(project_root)s'%env) + put(join('settings', '%(host)s.py'%env), join(env.project_root, env.project_name, 'local_settings.py')) + update_requirements() + +def deploy(): +# bzr_push() + bzr_update() + # virtual_run('python %(project_root)s/%(project_name)s/manage.py syncdb;python %(project_root)s/%(project_name)s/manage.py migrate'%env) + run('touch %(project_root)s/wsgi/django.wsgi'%env) diff --git a/openmumbai/__init__.py b/openmumbai/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openmumbai/base/__init__.py b/openmumbai/base/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openmumbai/base/models.py b/openmumbai/base/models.py new file mode 100644 index 0000000..c6cbb48 --- /dev/null +++ b/openmumbai/base/models.py @@ -0,0 +1,18 @@ +from django.contrib.gis.db import models +import datetime + +class BaseModel(models.Model): + changed = models.DateTimeField(null=True, editable=False) + created = models.DateTimeField(null=True, editable=False) + + def save(self, *args, **kwargs): + if not self.id: + self.created = datetime.datetime.today() + self.changed = datetime.datetime.today() + if self.created == None: + self.created = self.changed + super(BaseModel, self).save(*args, **kwargs) + + class Meta: + abstract = True + diff --git a/openmumbai/base/tests.py b/openmumbai/base/tests.py new file mode 100644 index 0000000..2247054 --- /dev/null +++ b/openmumbai/base/tests.py @@ -0,0 +1,23 @@ +""" +This file demonstrates two different styles of tests (one doctest and one +unittest). These will both pass when you run "manage.py test". + +Replace these with more appropriate tests for your application. +""" + +from django.test import TestCase + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.failUnlessEqual(1 + 1, 2) + +__test__ = {"doctest": """ +Another way to test that 1 + 1 is equal to 2. + +>>> 1 + 1 == 2 +True +"""} + diff --git a/openmumbai/base/views.py b/openmumbai/base/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/openmumbai/base/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/openmumbai/manage.py b/openmumbai/manage.py new file mode 100644 index 0000000..bed50ab --- /dev/null +++ b/openmumbai/manage.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +#!/usr/bin/env python +import os + +root_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) +os.chdir(root_dir) + +#using virtualenv's activate_this.py to reorder sys.path +activate_this = os.path.join(root_dir, '..', 'bin', 'activate_this.py') +execfile(activate_this, dict(__file__=activate_this)) + + +from django.core.management import execute_manager +import imp +try: + imp.find_module('settings') # Assumed to be in the same directory. +except ImportError: + import sys + sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__) + sys.exit(1) + +import settings + +if __name__ == "__main__": + execute_manager(settings) diff --git a/openmumbai/places/__init__.py b/openmumbai/places/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openmumbai/places/admin.py b/openmumbai/places/admin.py new file mode 100644 index 0000000..4f45f24 --- /dev/null +++ b/openmumbai/places/admin.py @@ -0,0 +1,29 @@ +from django.contrib.gis import admin +from models import * +# from forms import BaseRelationsFormSet +#from django import forms +#from django.contrib.admin import SimpleListFilter +#from ajax_select.fields import AutoCompleteSelectMultipleField, AutoCompleteSelectField + + + +class PlaceAdmin(admin.OSMGeoAdmin): +# fields = ('preferred_name', 'feature_type', 'admin1', 'admin2', 'geometry', 'url', 'authority_record', 'time_frame', 'is_primary',) + search_fields = ['name', 'location'] +# list_filter = ('feature_type',) +# inlines = [FeatureNamesInline] +# list_display = ('__unicode__', 'feature_type_name', 'admin1', 'admin2', 'time_start', 'time_end',) +# list_per_page = 30 +# list_filter = (FeatureTypeFilter,) + openlayers_url = 'http://openlayers.org/dev/OpenLayers.js' + openlayers_img_path = None +# form = featuresForm +# readonly_fields = ['geometry'] +# map_template = 'gis/admin/osm.html' +# default_lon = 72.855211097628413 +# default_lat = 19.415775291486027 +# default_zoom = 4 +# extra_js = ['http://openstreetmap.org/openlayers/OpenStreetMap.js', 'http://openlayers.org/dev/OpenLayers.js'] + +admin.site.register(Place, PlaceAdmin) + diff --git a/openmumbai/places/import_csv.py b/openmumbai/places/import_csv.py new file mode 100644 index 0000000..0001b94 --- /dev/null +++ b/openmumbai/places/import_csv.py @@ -0,0 +1,24 @@ +import csv +from models import * +from decimal import Decimal + +def do(filename): + CsvFile = csv.reader(open(filename), delimiter="\t") + for row in CsvFile: + p = Place() + p.ward = row[0].strip() + p.reservation = row[1].strip() + try: + p.pk_serial = int(row[2].strip()) + except: + p.pk_serial = None + p.occupied = (row[3].strip() == '*') + p.name = row[4] + p.address = row[5] + p.cts = row[6] + try: + p.area = Decimal(row[7].strip()) + except: + p.area = 0.0 + p.save() + print "%s saved" % p.name diff --git a/openmumbai/places/models.py b/openmumbai/places/models.py new file mode 100644 index 0000000..77e5a24 --- /dev/null +++ b/openmumbai/places/models.py @@ -0,0 +1,18 @@ +from base.models import BaseModel +from django.contrib.gis.db import models + +class Place(BaseModel): + ward = models.CharField(max_length=4, blank=True) + reservation = models.CharField(max_length=16, blank=True) + pk_serial = models.IntegerField(null=True, blank=True) #serial acc to PK Das excel sheets + occupied = models.BooleanField(default=False) + name = models.CharField(max_length=1024, blank=True) + address = models.TextField() + cts = models.CharField(max_length=512, null=True, blank=True) + area = models.DecimalField(max_digits=15, decimal_places=3) + geometry = models.GeometryField(null=True, blank=True) + + def __unicode__(self): + return "%s %s %s" % (self.ward, self.reservation, self.name,) + +# Create your models here. diff --git a/openmumbai/places/tests.py b/openmumbai/places/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/openmumbai/places/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/openmumbai/places/views.py b/openmumbai/places/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/openmumbai/places/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/openmumbai/settings.py b/openmumbai/settings.py new file mode 100644 index 0000000..d627d7f --- /dev/null +++ b/openmumbai/settings.py @@ -0,0 +1,179 @@ +# Django settings for openmumbai project. +import os +from os.path import join + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +JSON_DEBUG = False +APPEND_SLASH = True +#XSENDFILE = False + +ADMINS = ( + ('Sanjay Bhangar', 'b@pad.ma'), + # ('Your Name', 'your_email@example.com'), +) + +MANAGERS = ADMINS + +PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__)) + +DATABASES = { + 'default': { + 'ENGINE': 'django.contrib.gis.db.backends.postgis', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. + 'NAME': 'openmumbai', # Or path to database file if using sqlite3. + 'USER': '', # Not used with sqlite3. + 'PASSWORD': '', # Not used with sqlite3. + 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. + 'PORT': '', # Set to empty string for default. Not used with sqlite3. + } +} + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# On Unix systems, a value of None will cause Django to use the same +# timezone as the operating system. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'America/Chicago' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'en-us' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True + +# If you set this to False, Django will not format dates, numbers and +# calendars according to the current locale +USE_L10N = True + +# Absolute filesystem path to the directory that will hold user-uploaded files. +# Example: "/home/media/media.lawrence.com/media/" +MEDIA_ROOT = '' + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash. +# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" +MEDIA_URL = '' + +# Absolute path to the directory static files should be collected to. +# Don't put anything in this directory yourself; store your static files +# in apps' "static/" subdirectories and in STATICFILES_DIRS. +# Example: "/home/media/media.lawrence.com/static/" +STATIC_ROOT = join(PROJECT_ROOT, 'static') + +# URL prefix for static files. +# Example: "http://media.lawrence.com/static/" +STATIC_URL = '/static/' + +# URL prefix for admin static files -- CSS, JavaScript and images. +# Make sure to use a trailing slash. +# Examples: "http://foo.com/static/admin/", "/static/admin/". +ADMIN_MEDIA_PREFIX = '/static/admin/' + +# Additional locations of static files +STATICFILES_DIRS = ( + # Put strings here, like "/home/html/static" or "C:/www/django/static". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. +) + +# List of finder classes that know how to find static files in +# various locations. +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', +# 'django.contrib.staticfiles.finders.DefaultStorageFinder', +) + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + 'django.template.loaders.eggs.Loader', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', +# 'debug_toolbar.middleware.DebugToolbarMiddleware', +) + +ROOT_URLCONF = 'openmumbai.urls' + +TEMPLATE_DIRS = ( + join(PROJECT_ROOT, 'templates') + # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. +) + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.messages', + 'django.contrib.staticfiles', + # Uncomment the next line to enable the admin: + 'django.contrib.admin', + # Uncomment the next line to enable admin documentation: + 'django.contrib.admindocs', + 'django_extensions', + 'places', +# 'debug_toolbar', +) + +# A sample logging configuration. The only tangible logging +# performed by this configuration is to send an email to +# the site admins on every HTTP 500 error. +# See http://docs.djangoproject.com/en/dev/topics/logging for +# more details on how to customize your logging configuration. +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'mail_admins': { + 'level': 'ERROR', + 'class': 'django.utils.log.AdminEmailHandler' + } + }, + 'loggers': { + 'django.request': { + 'handlers': ['mail_admins'], + 'level': 'ERROR', + 'propagate': True, + }, + } +} + +#overwrite default settings with local settings +try: + from local_settings import * +except ImportError: + pass + +# Make this unique, creates random key first at first time. +try: + SECRET_KEY +except NameError: + SECRET_FILE = os.path.join(PROJECT_ROOT, 'secret.txt') + try: + SECRET_KEY = open(SECRET_FILE).read().strip() + except IOError: + try: + from random import choice + SECRET_KEY = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) + secret = file(SECRET_FILE, 'w') + secret.write(SECRET_KEY) + secret.close() + except IOError: + Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE) diff --git a/openmumbai/templates/gis/admin/google.html b/openmumbai/templates/gis/admin/google.html new file mode 100644 index 0000000..1134839 --- /dev/null +++ b/openmumbai/templates/gis/admin/google.html @@ -0,0 +1,4 @@ +{% extends "gis/admin/openlayers.html" %} +{% block openlayers %} +{% include "gis/admin/google.js" %} +{% endblock %} diff --git a/openmumbai/templates/gis/admin/google.js b/openmumbai/templates/gis/admin/google.js new file mode 100644 index 0000000..ed9090d --- /dev/null +++ b/openmumbai/templates/gis/admin/google.js @@ -0,0 +1,11 @@ +{% extends "gis/admin/openlayers.js" %} +{% block base_layer %} +new OpenLayers.Layer.Google("Google Terrain", {type: G_PHYSICAL_MAP, 'sphericalMercator': true}); +{% endblock %} + +{% block extra_layers %} + {{ module }}.layers.overlay = new OpenLayers.Layer.OSM.Mapnik("OpenStreetMap (Mapnik)"); + {{ module }}.map.addLayer({{ module }}.layers.overlay); +{% endblock %} + + diff --git a/openmumbai/templates/gis/admin/openlayers.html b/openmumbai/templates/gis/admin/openlayers.html new file mode 100644 index 0000000..a61b689 --- /dev/null +++ b/openmumbai/templates/gis/admin/openlayers.html @@ -0,0 +1,38 @@ +{% block extrastyle %} +{% load static %} + + +{% endblock %} + + +
+Delete all Features +{% if display_wkt %}

WKT debugging window:

{% endif %} + + +
diff --git a/openmumbai/templates/gis/admin/openlayers.js b/openmumbai/templates/gis/admin/openlayers.js new file mode 100644 index 0000000..adca203 --- /dev/null +++ b/openmumbai/templates/gis/admin/openlayers.js @@ -0,0 +1,172 @@ +{% load l10n %}{# Author: Justin Bronn, Travis Pinney & Dane Springmeyer #} +OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.SphericalMercator.projectForward); +{% block vars %}var {{ module }} = {}; +{{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\\d+;(.+)", "i"); {{ module }}.layers = {}; +{{ module }}.modifiable = {{ modifiable|yesno:"true,false" }}; +{{ module }}.wkt_f = new OpenLayers.Format.WKT(); +{{ module }}.is_collection = {{ is_collection|yesno:"true,false" }}; +{{ module }}.collection_type = '{{ collection_type }}'; +{{ module }}.is_linestring = {{ is_linestring|yesno:"true,false" }}; +{{ module }}.is_polygon = {{ is_polygon|yesno:"true,false" }}; +{{ module }}.is_point = {{ is_point|yesno:"true,false" }}; +{% endblock %} +{{ module }}.get_ewkt = function(feat){return 'SRID={{ srid }};' + {{ module }}.wkt_f.write(feat);} +{{ module }}.read_wkt = function(wkt){ + // OpenLayers cannot handle EWKT -- we make sure to strip it out. + // EWKT is only exposed to OL if there's a validation error in the admin. + var match = {{ module }}.re.exec(wkt); + if (match){wkt = match[1];} + return {{ module }}.wkt_f.read(wkt); +} +{{ module }}.write_wkt = function(feat){ + if ({{ module }}.is_collection){ {{ module }}.num_geom = feat.geometry.components.length;} + else { {{ module }}.num_geom = 1;} + document.getElementById('{{ id }}').value = {{ module }}.get_ewkt(feat); +} +{{ module }}.add_wkt = function(event){ + // This function will sync the contents of the `vector` layer with the + // WKT in the text field. + if ({{ module }}.is_collection){ + var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); + for (var i = 0; i < {{ module }}.layers.vector.features.length; i++){ + feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]); + } + {{ module }}.write_wkt(feat); + } else { + // Make sure to remove any previously added features. + if ({{ module }}.layers.vector.features.length > 1){ + old_feats = [{{ module }}.layers.vector.features[0]]; + {{ module }}.layers.vector.removeFeatures(old_feats); + {{ module }}.layers.vector.destroyFeatures(old_feats); + } + {{ module }}.write_wkt(event.feature); + } +} +{{ module }}.modify_wkt = function(event){ + if ({{ module }}.is_collection){ + if ({{ module }}.is_point){ + {{ module }}.add_wkt(event); + return; + } else { + // When modifying the selected components are added to the + // vector layer so we only increment to the `num_geom` value. + var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); + for (var i = 0; i < {{ module }}.num_geom; i++){ + feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]); + } + {{ module }}.write_wkt(feat); + } + } else { + {{ module }}.write_wkt(event.feature); + } +} +// Function to clear vector features and purge wkt from div +{{ module }}.deleteFeatures = function(){ + {{ module }}.layers.vector.removeFeatures({{ module }}.layers.vector.features); + {{ module }}.layers.vector.destroyFeatures(); +} +{{ module }}.clearFeatures = function (){ + {{ module }}.deleteFeatures(); + document.getElementById('{{ id }}').value = ''; + {% localize off %} + {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }}); + {% endlocalize %} +} +// Add Select control +{{ module }}.addSelectControl = function(){ + var select = new OpenLayers.Control.SelectFeature({{ module }}.layers.vector, {'toggle' : true, 'clickout' : true}); + {{ module }}.map.addControl(select); + select.activate(); +} +{{ module }}.enableDrawing = function(){ {{ module }}.map.getControlsByClass('OpenLayers.Control.DrawFeature')[0].activate();} +{{ module }}.enableEditing = function(){ {{ module }}.map.getControlsByClass('OpenLayers.Control.ModifyFeature')[0].activate();} +// Create an array of controls based on geometry type +{{ module }}.getControls = function(lyr){ + {{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'}); + var nav = new OpenLayers.Control.Navigation(); + var draw_ctl; + if ({{ module }}.is_linestring){ + draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'}); + } else if ({{ module }}.is_polygon){ + draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'}); + } else if ({{ module }}.is_point){ + draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}); + } + if ({{ module }}.modifiable){ + var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'}); + {{ module }}.controls = [nav, draw_ctl, mod]; + } else { + if(!lyr.features.length){ + {{ module }}.controls = [nav, draw_ctl]; + } else { + {{ module }}.controls = [nav]; + } + } +} +{{ module }}.init = function(){ + {% block map_options %}// The options hash, w/ zoom, resolution, and projection settings. + var options = { +{% autoescape off %}{% for item in map_options.items %} '{{ item.0 }}' : {{ item.1 }}{% if not forloop.last %},{% endif %} +{% endfor %}{% endautoescape %} };{% endblock %} + // The admin map for this geometry field. + {{ module }}.map = new OpenLayers.Map('{{ id }}_map', options); + // Base Layer + {{ module }}.layers.base = {% block base_layer %}new OpenLayers.Layer.WMS( "{{ wms_name }}", "{{ wms_url }}", {layers: '{{ wms_layer }}'} );{% endblock %} + {{ module }}.map.addLayer({{ module }}.layers.base); + {% block extra_layers %}{% endblock %} + {% if is_linestring %}OpenLayers.Feature.Vector.style["default"]["strokeWidth"] = 3; // Default too thin for linestrings. {% endif %} + {{ module }}.layers.vector = new OpenLayers.Layer.Vector(" {{ field_name }}"); + {{ module }}.map.addLayer({{ module }}.layers.vector); + // Read WKT from the text field. + var wkt = document.getElementById('{{ id }}').value; + if (wkt){ + // After reading into geometry, immediately write back to + // WKT