diff options
| author | Justin Bronn <jbronn@gmail.com> | 2010-04-16 16:45:59 +0000 |
|---|---|---|
| committer | Justin Bronn <jbronn@gmail.com> | 2010-04-16 16:45:59 +0000 |
| commit | be167b804d53ef4b14ae7e368724176168a64b6c (patch) | |
| tree | c25448ac072494714475953a9ad487ec3cff708f | |
| parent | f6b6e0f1d9c4440d848c71a933fbe4ecf67ce106 (diff) | |
[1.1.X] Fixed #11810 -- Fixed typo and errors that prevented `modifiable` from working in the geographic admin. Thanks to Rob Coup for the bug report. Refs #12504.
Backport of r12995 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12996 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/contrib/gis/admin/options.py | 8 | ||||
| -rw-r--r-- | django/contrib/gis/templates/gis/admin/openlayers.js | 37 |
2 files changed, 23 insertions, 22 deletions
diff --git a/django/contrib/gis/admin/options.py b/django/contrib/gis/admin/options.py index fff1cb20a6..a1da28108d 100644 --- a/django/contrib/gis/admin/options.py +++ b/django/contrib/gis/admin/options.py @@ -64,7 +64,7 @@ class GeoModelAdmin(ModelAdmin): def get_map_widget(self, db_field): """ Returns a subclass of the OpenLayersWidget (or whatever was specified - in the `widget` attribute) using the settings from the attributes set + in the `widget` attribute) using the settings from the attributes set in this class. """ is_collection = db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION') @@ -111,12 +111,6 @@ class GeoModelAdmin(ModelAdmin): } return OLMap -# Using the Beta OSM in the admin requires the following: -# (1) The Google Maps Mercator projection needs to be added -# to your `spatial_ref_sys` table. You'll need at least GDAL 1.5: -# >>> from django.contrib.gis.gdal import SpatialReference -# >>> from django.contrib.gis.utils import add_postgis_srs -# >>> add_postgis_srs(SpatialReference(900913)) # Adding the Google Projection from django.contrib.gis import gdal if gdal.HAS_GDAL: class OSMGeoAdmin(GeoModelAdmin): diff --git a/django/contrib/gis/templates/gis/admin/openlayers.js b/django/contrib/gis/templates/gis/admin/openlayers.js index 93286cc464..4324693c78 100644 --- a/django/contrib/gis/templates/gis/admin/openlayers.js +++ b/django/contrib/gis/templates/gis/admin/openlayers.js @@ -1,6 +1,7 @@ {# Author: Justin Bronn, Travis Pinney & Dane Springmeyer #} {% block vars %}var {{ module }} = {}; -{{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\d+;(.+)", "i"); {{ module }}.layers = {}; +{{ 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 }}'; @@ -43,10 +44,10 @@ {{ module }}.modify_wkt = function(event){ if ({{ module }}.is_collection){ if ({{ module }}.is_point){ - {{ module }}.add_wkt(event); + {{ module }}.add_wkt(event); return; } else { - // When modifying the selected components are added to the + // 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++){ @@ -69,7 +70,7 @@ {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }}); } // Add Select control -{{ module }}.addSelectControl = function(){ +{{ module }}.addSelectControl = function(){ var select = new OpenLayers.Control.SelectFeature({{ module }}.layers.vector, {'toggle' : true, 'clickout' : true}); {{ module }}.map.addControl(select); select.activate(); @@ -88,16 +89,20 @@ } else if ({{ module }}.is_point){ draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}); } - {% if modifiable %} - var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'}); - {{ module }}.controls = [nav, draw_ctl, mod]; - {% else %} - {{ module }}.controls = [nav, darw_ctl]; - {% endif %} + 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 = { + 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. @@ -112,7 +117,7 @@ // Read WKT from the text field. var wkt = document.getElementById('{{ id }}').value; if (wkt){ - // After reading into geometry, immediately write back to + // After reading into geometry, immediately write back to // WKT <textarea> as EWKT (so that SRID is included). var admin_geom = {{ module }}.read_wkt(wkt); {{ module }}.write_wkt(admin_geom); @@ -128,14 +133,14 @@ // Zooming to the bounds. {{ module }}.map.zoomToExtent(admin_geom.geometry.getBounds()); if ({{ module }}.is_point){ - {{ module }}.map.zoomTo({{ point_zoom }}); + {{ module }}.map.zoomTo({{ point_zoom }}); } } else { {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }}); } // This allows editing of the geographic fields -- the modified WKT is // written back to the content field (as EWKT, so that the ORM will know - // to transform back to original SRID). + // to transform back to original SRID). {{ module }}.layers.vector.events.on({"featuremodified" : {{ module }}.modify_wkt}); {{ module }}.layers.vector.events.on({"featureadded" : {{ module }}.add_wkt}); {% block controls %} @@ -153,7 +158,9 @@ {% if not scrollable %}{{ module }}.map.getControlsByClass('OpenLayers.Control.Navigation')[0].disableZoomWheel();{% endif %} {% endblock %} if (wkt){ - {{ module }}.enableEditing(); + if ({{ module }}.modifiable){ + {{ module }}.enableEditing(); + } } else { {{ module }}.enableDrawing(); } |
