Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #11810 -- Fixed typo and errors that prevented `modifia…

…ble` 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
  • Loading branch information...
commit be167b804d53ef4b14ae7e368724176168a64b6c 1 parent f6b6e0f
Justin Bronn authored April 16, 2010
8  django/contrib/gis/admin/options.py
@@ -64,7 +64,7 @@ def formfield_for_dbfield(self, db_field, **kwargs):
64 64
     def get_map_widget(self, db_field):
65 65
         """
66 66
         Returns a subclass of the OpenLayersWidget (or whatever was specified
67  
-        in the `widget` attribute) using the settings from the attributes set 
  67
+        in the `widget` attribute) using the settings from the attributes set
68 68
         in this class.
69 69
         """
70 70
         is_collection = db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION')
@@ -111,12 +111,6 @@ class OLMap(self.widget):
111 111
                       }
112 112
         return OLMap
113 113
 
114  
-# Using the Beta OSM in the admin requires the following:
115  
-#  (1) The Google Maps Mercator projection needs to be added
116  
-#      to your `spatial_ref_sys` table.  You'll need at least GDAL 1.5:
117  
-#      >>> from django.contrib.gis.gdal import SpatialReference
118  
-#      >>> from django.contrib.gis.utils import add_postgis_srs
119  
-#      >>> add_postgis_srs(SpatialReference(900913)) # Adding the Google Projection 
120 114
 from django.contrib.gis import gdal
121 115
 if gdal.HAS_GDAL:
122 116
     class OSMGeoAdmin(GeoModelAdmin):
37  django/contrib/gis/templates/gis/admin/openlayers.js
... ...
@@ -1,6 +1,7 @@
1 1
 {# Author: Justin Bronn, Travis Pinney & Dane Springmeyer #}
2 2
 {% block vars %}var {{ module }} = {};
3  
-{{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\d+;(.+)", "i"); {{ module }}.layers = {}; 
  3
+{{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\d+;(.+)", "i"); {{ module }}.layers = {};
  4
+{{ module }}.modifiable = {{ modifiable|yesno:"true,false" }};
4 5
 {{ module }}.wkt_f = new OpenLayers.Format.WKT();
5 6
 {{ module }}.is_collection = {{ is_collection|yesno:"true,false" }};
6 7
 {{ module }}.collection_type = '{{ collection_type }}';
@@ -43,10 +44,10 @@
43 44
 {{ module }}.modify_wkt = function(event){
44 45
   if ({{ module }}.is_collection){
45 46
     if ({{ module }}.is_point){
46  
-      {{ module }}.add_wkt(event); 
  47
+      {{ module }}.add_wkt(event);
47 48
       return;
48 49
     } else {
49  
-      // When modifying the selected components are added to the 
  50
+      // When modifying the selected components are added to the
50 51
       // vector layer so we only increment to the `num_geom` value.
51 52
       var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}());
52 53
       for (var i = 0; i < {{ module }}.num_geom; i++){
@@ -69,7 +70,7 @@
69 70
   {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }});
70 71
 }
71 72
 // Add Select control
72  
-{{ module }}.addSelectControl = function(){   
  73
+{{ module }}.addSelectControl = function(){
73 74
   var select = new OpenLayers.Control.SelectFeature({{ module }}.layers.vector, {'toggle' : true, 'clickout' : true});
74 75
   {{ module }}.map.addControl(select);
75 76
   select.activate();
@@ -88,16 +89,20 @@
88 89
   } else if ({{ module }}.is_point){
89 90
     draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'});
90 91
   }
91  
-  {% if modifiable %}
92  
-  var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'});
93  
-  {{ module }}.controls = [nav, draw_ctl, mod];
94  
-  {% else %}
95  
-  {{ module }}.controls = [nav, darw_ctl];
96  
-  {% endif %}  
  92
+  if ({{ module }}.modifiable){
  93
+    var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'});
  94
+    {{ module }}.controls = [nav, draw_ctl, mod];
  95
+  } else {
  96
+    if(!lyr.features.length){
  97
+      {{ module }}.controls = [nav, draw_ctl];
  98
+    } else {
  99
+      {{ module }}.controls = [nav];
  100
+    }
  101
+  }
97 102
 }
98 103
 {{ module }}.init = function(){
99 104
     {% block map_options %}// The options hash, w/ zoom, resolution, and projection settings.
100  
-    var options = { 
  105
+    var options = {
101 106
 {% autoescape off %}{% for item in map_options.items %}      '{{ item.0 }}' : {{ item.1 }}{% if not forloop.last %},{% endif %}
102 107
 {% endfor %}{% endautoescape %}    };{% endblock %}
103 108
     // The admin map for this geometry field.
@@ -112,7 +117,7 @@
112 117
     // Read WKT from the text field.
113 118
     var wkt = document.getElementById('{{ id }}').value;
114 119
     if (wkt){
115  
-      // After reading into geometry, immediately write back to 
  120
+      // After reading into geometry, immediately write back to
116 121
       // WKT <textarea> as EWKT (so that SRID is included).
117 122
       var admin_geom = {{ module }}.read_wkt(wkt);
118 123
       {{ module }}.write_wkt(admin_geom);
@@ -128,14 +133,14 @@
128 133
       // Zooming to the bounds.
129 134
       {{ module }}.map.zoomToExtent(admin_geom.geometry.getBounds());
130 135
       if ({{ module }}.is_point){
131  
-          {{ module }}.map.zoomTo({{ point_zoom }}); 
  136
+          {{ module }}.map.zoomTo({{ point_zoom }});
132 137
       }
133 138
     } else {
134 139
       {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }});
135 140
     }
136 141
     // This allows editing of the geographic fields -- the modified WKT is
137 142
     // written back to the content field (as EWKT, so that the ORM will know
138  
-    // to transform back to original SRID). 
  143
+    // to transform back to original SRID).
139 144
     {{ module }}.layers.vector.events.on({"featuremodified" : {{ module }}.modify_wkt});
140 145
     {{ module }}.layers.vector.events.on({"featureadded" : {{ module }}.add_wkt});
141 146
     {% block controls %}
@@ -153,7 +158,9 @@
153 158
     {% if not scrollable %}{{ module }}.map.getControlsByClass('OpenLayers.Control.Navigation')[0].disableZoomWheel();{% endif %}
154 159
     {% endblock %}
155 160
     if (wkt){
156  
-      {{ module }}.enableEditing();
  161
+      if ({{ module }}.modifiable){
  162
+        {{ module }}.enableEditing();
  163
+      }
157 164
     } else {
158 165
       {{ module }}.enableDrawing();
159 166
     }

0 notes on commit be167b8

Please sign in to comment.
Something went wrong with that request. Please try again.