diff -r bf6f4f1df989 django/contrib/gis/admin/options.py
a
|
b
|
|
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') |
… |
… |
|
96 | 96 | 'units' : self.units, #likely shoud get from object |
97 | 97 | 'max_resolution' : self.max_resolution, |
98 | 98 | 'max_extent' : self.max_extent, |
99 | | 'modifiable' : self.modifiable, |
| 99 | 'modifiable' : self.modifiable or db_field.name not in self.readonly_fields, |
100 | 100 | 'mouse_position' : self.mouse_position, |
101 | 101 | 'scale_text' : self.scale_text, |
102 | 102 | 'map_width' : self.map_width, |
… |
… |
|
116 | 116 | # to your `spatial_ref_sys` table. You'll need at least GDAL 1.5: |
117 | 117 | # >>> from django.contrib.gis.gdal import SpatialReference |
118 | 118 | # >>> from django.contrib.gis.utils import add_postgis_srs |
119 | | # >>> add_postgis_srs(SpatialReference(900913)) # Adding the Google Projection |
| 119 | # >>> add_postgis_srs(SpatialReference(900913)) # Adding the Google Projection |
120 | 120 | from django.contrib.gis import gdal |
121 | 121 | if gdal.HAS_GDAL: |
122 | 122 | class OSMGeoAdmin(GeoModelAdmin): |
diff -r bf6f4f1df989 django/contrib/gis/templates/gis/admin/openlayers.js
a
|
b
|
|
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 | 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 | 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 | 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 | 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 | 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 | 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 | } |