diff --git a/openlayers.js b/openlayers.js
index eb40eda..813756b 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
|
10 | 14 | {{ module }}.is_polygon = {{ is_polygon|yesno:"true,false" }}; |
11 | 15 | {{ module }}.is_point = {{ is_point|yesno:"true,false" }}; |
12 | 16 | {% endblock %} |
13 | | {{ module }}.get_ewkt = function(feat){return 'SRID={{ srid }};' + {{ module }}.wkt_f.write(feat);} |
| 17 | // Patch for http://trac.osgeo.org/openlayers/ticket/2240 |
| 18 | {{ module }}.get_ewkt = function(feat){ |
| 19 | if (feat.constructor == Array) { |
| 20 | wkts = []; |
| 21 | for(var i = 0; i < feat.length; i++){ |
| 22 | wkts.push(feat[i].geometry.toString()); |
| 23 | } |
| 24 | return 'SRID={{ srid }};GEOMETRYCOLLECTION(' + wkts.join(', ') + ')'; |
| 25 | } else if (feat.geometry.CLASS_NAME == 'OpenLayers.Geometry.Collection') { |
| 26 | wkts = []; |
| 27 | for (var i=0; i < feat.geometry.components.length; i++){ |
| 28 | wkts.push(feat.geometry.components[i].toString()); |
| 29 | } |
| 30 | return 'SRID={{ srid }};GEOMETRYCOLLECTION(' + wkts.join(', ') + ')'; |
| 31 | } else { |
| 32 | return 'SRID={{ srid }};' + {{ module }}.wkt_f.write(feat); |
| 33 | } |
| 34 | } |
14 | 35 | {{ module }}.read_wkt = function(wkt){ |
15 | 36 | // OpenLayers cannot handle EWKT -- we make sure to strip it out. |
16 | 37 | // EWKT is only exposed to OL if there's a validation error in the admin. |
… |
… |
OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
|
19 | 40 | return {{ module }}.wkt_f.read(wkt); |
20 | 41 | } |
21 | 42 | {{ module }}.write_wkt = function(feat){ |
22 | | if ({{ module }}.is_collection){ {{ module }}.num_geom = feat.geometry.components.length;} |
23 | | else { {{ module }}.num_geom = 1;} |
| 43 | if ({{ module }}.is_collection){ |
| 44 | if (feat.constructor == Array) { |
| 45 | {{ module }}.num_geom = feat.length; |
| 46 | } else { |
| 47 | {{ module }}.num_geom = feat.geometry.components.length; |
| 48 | } |
| 49 | } else { |
| 50 | {{ module }}.num_geom = 1; |
| 51 | } |
24 | 52 | document.getElementById('{{ id }}').value = {{ module }}.get_ewkt(feat); |
25 | 53 | } |
26 | 54 | {{ module }}.add_wkt = function(event){ |
27 | 55 | // This function will sync the contents of the `vector` layer with the |
28 | 56 | // WKT in the text field. |
29 | 57 | if ({{ module }}.is_collection){ |
| 58 | if ({{ module }}.collection_type == 'Any') { |
| 59 | var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Collection()); |
| 60 | } else { |
30 | 61 | var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); |
| 62 | } |
31 | 63 | for (var i = 0; i < {{ module }}.layers.vector.features.length; i++){ |
32 | 64 | feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]); |
33 | 65 | } |
… |
… |
OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
|
50 | 82 | } else { |
51 | 83 | // When modifying the selected components are added to the |
52 | 84 | // vector layer so we only increment to the `num_geom` value. |
| 85 | if ({{ module }}.collection_type == 'Any') { |
| 86 | var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Collection()); |
| 87 | } else { |
53 | 88 | var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); |
| 89 | } |
54 | 90 | for (var i = 0; i < {{ module }}.num_geom; i++){ |
55 | 91 | feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]); |
56 | 92 | } |
… |
… |
OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
|
84 | 120 | {{ module }}.getControls = function(lyr){ |
85 | 121 | {{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'}); |
86 | 122 | var nav = new OpenLayers.Control.Navigation(); |
87 | | var draw_ctl; |
88 | | if ({{ module }}.is_linestring){ |
89 | | draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'}); |
90 | | } else if ({{ module }}.is_polygon){ |
91 | | draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'}); |
92 | | } else if ({{ module }}.is_point){ |
93 | | draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}); |
| 123 | var draw_ctl = []; |
| 124 | if ({{ module }}.is_linestring || {{ module }}.is_collection){ |
| 125 | draw_ctl.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'})); |
| 126 | } |
| 127 | if ({{ module }}.is_polygon || {{ module }}.is_collection){ |
| 128 | draw_ctl.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'})); |
| 129 | } |
| 130 | if ({{ module }}.is_point|| {{ module }}.is_collection){ |
| 131 | draw_ctl.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'})); |
94 | 132 | } |
| 133 | var ctls = draw_ctl; |
95 | 134 | if ({{ module }}.modifiable){ |
96 | 135 | var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'}); |
97 | | {{ module }}.controls = [nav, draw_ctl, mod]; |
| 136 | ctls.splice(0, 0, nav); |
| 137 | ctls.push(mod); |
98 | 138 | } else { |
99 | 139 | if(!lyr.features.length){ |
100 | | {{ module }}.controls = [nav, draw_ctl]; |
| 140 | ictls.splice(0, 0, nav); |
101 | 141 | } else { |
102 | | {{ module }}.controls = [nav]; |
| 142 | ctls = [nav]; |
103 | 143 | } |
104 | 144 | } |
| 145 | {{ module }}.controls = ctls; |
105 | 146 | } |
| 147 | |
106 | 148 | {{ module }}.init = function(){ |
107 | 149 | {% block map_options %}// The options hash, w/ zoom, resolution, and projection settings. |
108 | 150 | var options = { |
… |
… |
OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
|
129 | 171 | if ({{ module }}.is_collection){ |
130 | 172 | // If geometry collection, add each component individually so they may be |
131 | 173 | // edited individually. |
| 174 | if ({{ module }}.collection_type == 'Any') { |
| 175 | {{ module }}.layers.vector.addFeatures(admin_geom); |
| 176 | var admin_bounds = new OpenLayers.Bounds(); |
| 177 | for(var i = 0; i < {{ module }}.num_geom; i++){ |
| 178 | admin_bounds.extend(admin_geom[i].geometry.getBounds()); |
| 179 | } |
| 180 | } else { |
132 | 181 | for (var i = 0; i < {{ module }}.num_geom; i++){ |
133 | 182 | {{ module }}.layers.vector.addFeatures([new OpenLayers.Feature.Vector(admin_geom.geometry.components[i].clone())]); |
134 | 183 | } |
| 184 | var admin_bounds = admin_geom.geometry.getBounds(); |
| 185 | } |
135 | 186 | } else { |
136 | 187 | {{ module }}.layers.vector.addFeatures([admin_geom]); |
| 188 | var admin_bounds = admin_geom.geometry.getBounds(); |
137 | 189 | } |
138 | 190 | // Zooming to the bounds. |
139 | | {{ module }}.map.zoomToExtent(admin_geom.geometry.getBounds()); |
| 191 | {{ module }}.map.zoomToExtent(admin_bounds); |
140 | 192 | if ({{ module }}.is_point){ |
141 | 193 | {{ module }}.map.zoomTo({{ point_zoom }}); |
142 | 194 | } |