diff --git a/django/contrib/gis/templates/gis/admin/openlayers.js b/django/contrib/gis/templates/gis/admin/openlayers.js
index 4425fee..232c8c7 100644
a
|
b
|
|
1 | 1 | {% load l10n %} |
2 | 2 | OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.SphericalMercator.projectForward); |
3 | 3 | {% block vars %}var {{ module }} = {}; |
4 | | {{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\\d+;(.+)", "i"); {{ module }}.layers = {}; |
| 4 | {{ module }}.map = null; |
| 5 | {{ module }}.controls = null; |
| 6 | {{ module }}.panel = null; |
| 7 | {{ module }}.re = new RegExp("^SRID=\\d+;(.+)", "i"); |
| 8 | {{ module }}.layers = {}; |
5 | 9 | {{ module }}.modifiable = {{ modifiable|yesno:"true,false" }}; |
6 | 10 | {{ module }}.wkt_f = new OpenLayers.Format.WKT(); |
7 | 11 | {{ module }}.is_collection = {{ is_collection|yesno:"true,false" }}; |
… |
… |
OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
|
11 | 15 | {{ module }}.is_polygon = {{ is_polygon|yesno:"true,false" }}; |
12 | 16 | {{ module }}.is_point = {{ is_point|yesno:"true,false" }}; |
13 | 17 | {% endblock %} |
| 18 | // Patch for http://trac.osgeo.org/openlayers/ticket/2240 |
14 | 19 | {{ module }}.get_ewkt = function(feat){ |
15 | | return 'SRID={{ srid|unlocalize }};' + {{ module }}.wkt_f.write(feat); |
| 20 | if (feat.constructor == Array) { |
| 21 | wkts = []; |
| 22 | for(var i = 0; i < feat.length; i++){ |
| 23 | wkts.push(feat[i].geometry.toString()); |
| 24 | } |
| 25 | return 'SRID={{ srid|unlocalize }};GEOMETRYCOLLECTION(' + wkts.join(', ') + ')'; |
| 26 | } else if (feat.geometry.CLASS_NAME == 'OpenLayers.Geometry.Collection') { |
| 27 | wkts = []; |
| 28 | for (var i=0; i < feat.geometry.components.length; i++){ |
| 29 | wkts.push(feat.geometry.components[i].toString()); |
| 30 | } |
| 31 | return 'SRID={{ srid|unlocalize }};GEOMETRYCOLLECTION(' + wkts.join(', ') + ')'; |
| 32 | } else { |
| 33 | return 'SRID={{ srid|unlocalize }};' + {{ module }}.wkt_f.write(feat); |
| 34 | } |
16 | 35 | }; |
17 | 36 | {{ module }}.read_wkt = function(wkt){ |
18 | 37 | // OpenLayers cannot handle EWKT -- we make sure to strip it out. |
… |
… |
OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
|
22 | 41 | return {{ module }}.wkt_f.read(wkt); |
23 | 42 | }; |
24 | 43 | {{ module }}.write_wkt = function(feat){ |
25 | | if ({{ module }}.is_collection){ {{ module }}.num_geom = feat.geometry.components.length;} |
26 | | else { {{ module }}.num_geom = 1;} |
| 44 | if ({{ module }}.is_collection){ |
| 45 | if (feat.constructor == Array) { |
| 46 | {{ module }}.num_geom = feat.length; |
| 47 | } else { |
| 48 | {{ module }}.num_geom = feat.geometry.components.length; |
| 49 | } |
| 50 | } else { |
| 51 | {{ module }}.num_geom = 1; |
| 52 | } |
27 | 53 | document.getElementById('{{ id }}').value = {{ module }}.get_ewkt(feat); |
28 | 54 | }; |
29 | 55 | {{ module }}.add_wkt = function(event){ |
… |
… |
OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
|
53 | 79 | } else { |
54 | 80 | // When modifying the selected components are added to the |
55 | 81 | // vector layer so we only increment to the `num_geom` value. |
56 | | var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); |
| 82 | if ({{ module }}.collection_type == 'Any') { |
| 83 | var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Collection()); |
| 84 | } else { |
| 85 | var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); |
| 86 | } |
57 | 87 | for (var i = 0; i < {{ module }}.num_geom; i++){ |
58 | 88 | feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]); |
59 | 89 | } |
… |
… |
OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
|
92 | 122 | {{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'}); |
93 | 123 | {{ module }}.controls = [new OpenLayers.Control.Navigation()]; |
94 | 124 | if (!{{ module }}.modifiable && lyr.features.length) return; |
95 | | if ({{ module }}.is_linestring || {{ module }}.is_generic){ |
| 125 | if ({{ module }}.is_linestring || {{ module }}.is_generic || {{ module }}.is_collection){ |
96 | 126 | {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'})); |
97 | 127 | } |
98 | | if ({{ module }}.is_polygon || {{ module }}.is_generic){ |
| 128 | if ({{ module }}.is_polygon || {{ module }}.is_generic || {{ module }}.is_collection){ |
99 | 129 | {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'})); |
100 | 130 | } |
101 | | if ({{ module }}.is_point || {{ module }}.is_generic){ |
| 131 | if ({{ module }}.is_point || {{ module }}.is_generic || {{ module }}.is_collection){ |
102 | 132 | {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'})); |
103 | 133 | } |
104 | 134 | if ({{ module }}.modifiable){ |
… |
… |
OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
|
131 | 161 | if ({{ module }}.is_collection){ |
132 | 162 | // If geometry collection, add each component individually so they may be |
133 | 163 | // edited individually. |
134 | | for (var i = 0; i < {{ module }}.num_geom; i++){ |
135 | | {{ module }}.layers.vector.addFeatures([new OpenLayers.Feature.Vector(admin_geom.geometry.components[i].clone())]); |
| 164 | if ({{ module }}.collection_type == 'Any') { |
| 165 | {{ module }}.layers.vector.addFeatures(admin_geom); |
| 166 | var admin_bounds = new OpenLayers.Bounds(); |
| 167 | for(var i = 0; i < {{ module }}.num_geom; i++){ |
| 168 | admin_bounds.extend(admin_geom[i].geometry.getBounds()); |
| 169 | } |
| 170 | } else { |
| 171 | for (var i = 0; i < {{ module }}.num_geom; i++){ |
| 172 | {{ module }}.layers.vector.addFeatures([new OpenLayers.Feature.Vector(admin_geom.geometry.components[i].clone())]); |
| 173 | } |
| 174 | var admin_bounds = admin_geom.geometry.getBounds(); |
136 | 175 | } |
137 | 176 | } else { |
138 | 177 | {{ module }}.layers.vector.addFeatures([admin_geom]); |
| 178 | var admin_bounds = admin_geom.geometry.getBounds(); |
139 | 179 | } |
140 | 180 | // Zooming to the bounds. |
141 | | {{ module }}.map.zoomToExtent(admin_geom.geometry.getBounds()); |
| 181 | {{ module }}.map.zoomToExtent(admin_bounds); |
142 | 182 | if ({{ module }}.is_point){ |
143 | 183 | {{ module }}.map.zoomTo({{ point_zoom }}); |
144 | 184 | } |