Ticket #13926: osm_ol_admin.diff
File osm_ol_admin.diff, 6.7 KB (added by , 13 years ago) |
---|
-
openlayers.
old new 1 1 {% load l10n %}{# Author: Justin Bronn, Travis Pinney & Dane Springmeyer #} 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 = /^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" }}; … … 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. … … 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 } … … 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 } … … 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'})); 94 129 } 130 if ({{ module }}.is_point|| {{ module }}.is_collection){ 131 draw_ctl.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'})); 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 = { … … 127 169 if ({{ module }}.is_collection){ 128 170 // If geometry collection, add each component individually so they may be 129 171 // edited individually. 172 if ({{ module }}.collection_type == 'Any') { 173 {{ module }}.layers.vector.addFeatures(admin_geom); 174 var admin_bounds = new OpenLayers.Bounds(); 175 for(var i = 0; i < {{ module }}.num_geom; i++){ 176 admin_bounds.extend(admin_geom[i].geometry.getBounds()); 177 } 178 } else { 130 179 for (var i = 0; i < {{ module }}.num_geom; i++){ 131 180 {{ module }}.layers.vector.addFeatures([new OpenLayers.Feature.Vector(admin_geom.geometry.components[i].clone())]); 132 181 } 182 var admin_bounds = admin_geom.geometry.getBounds(); 183 } 133 184 } else { 134 185 {{ module }}.layers.vector.addFeatures([admin_geom]); 186 var admin_bounds = admin_geom.geometry.getBounds(); 135 187 } 136 188 // Zooming to the bounds. 137 {{ module }}.map.zoomToExtent(admin_ geom.geometry.getBounds());189 {{ module }}.map.zoomToExtent(admin_bounds); 138 190 if ({{ module }}.is_point){ 139 191 {{ module }}.map.zoomTo({{ point_zoom }}); 140 192 }