Ticket #9806: 9806.4.diff
File 9806.4.diff, 10.2 KB (added by , 14 years ago) |
---|
-
admin/options.py
diff -u -r gis-orig/admin/options.py gis/admin/options.py
old new 67 67 in the `widget` attribute) using the settings from the attributes set 68 68 in this class. 69 69 """ 70 is_collection = db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION') 71 if is_collection: 72 if db_field.geom_type == 'GEOMETRYCOLLECTION': collection_type = 'Any' 73 else: collection_type = OGRGeomType(db_field.geom_type.replace('MULTI', '')) 70 71 is_unknown = db_field.geom_type in ('GEOMETRY',) 72 if not is_unknown: 73 #If it is not generic, get the parameters from the db_field 74 is_collection = db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION') 75 if is_collection: 76 if db_field.geom_type == 'GEOMETRYCOLLECTION': collection_type = 'Any' 77 else: collection_type = OGRGeomType(db_field.geom_type.upper().replace('MULTI', '')) 78 else: 79 collection_type = 'None' 80 is_linestring = db_field.geom_type in ('LINESTRING', 'MULTILINESTRING') 81 is_polygon = db_field.geom_type in ('POLYGON', 'MULTIPOLYGON') 82 is_point = db_field.geom_type in ('POINT', 'MULTIPOINT') 83 geom_type = OGRGeomType(db_field.geom_type) 74 84 else: 85 #If it is generic, set sensible defaults 86 is_collection = False 75 87 collection_type = 'None' 88 is_linestring = False 89 is_polygon = False 90 is_point = False 91 geom_type = OGRGeomType('Unknown') 76 92 77 93 class OLMap(self.widget): 78 94 template = self.map_template … … 81 97 'default_lat' : self.default_lat, 82 98 'default_zoom' : self.default_zoom, 83 99 'display_wkt' : self.debug or self.display_wkt, 84 'geom_type' : OGRGeomType(db_field.geom_type),100 'geom_type' : geom_type, 85 101 'field_name' : db_field.name, 102 'is_unknown': is_unknown, 86 103 'is_collection' : is_collection, 87 104 'scrollable' : self.scrollable, 88 105 'layerswitcher' : self.layerswitcher, 89 106 'collection_type' : collection_type, 90 'is_linestring' : db_field.geom_type in ('LINESTRING', 'MULTILINESTRING'),91 'is_polygon' : db_field.geom_type in ('POLYGON', 'MULTIPOLYGON'),92 'is_point' : db_field.geom_type in ('POINT', 'MULTIPOINT'),107 'is_linestring' : is_linestring, 108 'is_polygon' : is_polygon, 109 'is_point' : is_point, 93 110 'num_zoom' : self.num_zoom, 94 111 'max_zoom' : self.max_zoom, 95 112 'min_zoom' : self.min_zoom, -
admin/widgets.py
diff -u -r gis-orig/admin/widgets.py gis/admin/widgets.py
old new 4 4 from django.forms.widgets import Textarea 5 5 from django.template import loader, Context 6 6 from django.utils import translation 7 from django.contrib.gis.gdal import OGRGeomType 7 8 8 9 # Creating a template context that contains Django settings 9 10 # values needed by admin map templates. … … 31 32 value = GEOSGeometry(value) 32 33 except (GEOSException, ValueError): 33 34 value = None 34 35 if value and value.geom_type.upper() != self.geom_type: 35 if value and value.geom_type.upper() != self.geom_type and self.geom_type != 'GEOMETRY': 36 36 value = None 37 37 38 38 # Constructing the dictionary of the map options. … … 65 65 # geometry. 66 66 self.params['wkt'] = wkt 67 67 68 # Check if the field is generic so the proper values are overriden 69 if self.params['is_unknown']: 70 self.params['geom_type'] = OGRGeomType(value.geom_type) 71 if value.geom_type.upper() in ('LINESTRING', 'MULTILINESTRING'): 72 self.params['is_linestring'] = True 73 elif value.geom_type.upper() in ('POLYGON', 'MULTIPOLYGON'): 74 self.params['is_polygon'] = True 75 elif value.geom_type.upper() in ('POINT', 'MULTIPOINT'): 76 self.params['is_point'] = True 77 if value.geom_type.upper() in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION'): 78 self.params['is_collection']=True 79 if value.geom_type.upper() == 'GEOMETRYCOLLECTION': 80 self.params['collection_type'] = 'Any' 81 else: 82 self.params['collection_type'] = OGRGeomType(value.geom_type.upper().replace('MULTI', '')) 83 84 else: 85 if self.params['is_unknown']: 86 # If the geometry is unknown and the value is not set, make it as flexible as possible. 87 self.params['geom_type'] = OGRGeomType('GEOMETRYCOLLECTION') 88 self.params['is_collection']=True 89 self.params['collection_type'] = 'Any' 90 68 91 return loader.render_to_string(self.template, self.params, 69 92 context_instance=geo_context) 70 93 -
templates/gis/admin/openlayers.js
diff -u -r gis-orig/templates/gis/admin/openlayers.js gis/templates/gis/admin/openlayers.js
old new 1 // Overrides for Openblock: support multipolygon and multipoint. 2 // TODO: submit upstream patch at http://code.djangoproject.com/ticket/9806 1 3 {# Author: Justin Bronn, Travis Pinney & Dane Springmeyer #} 2 4 {% block vars %}var {{ module }} = {}; 3 5 {{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\d+;(.+)", "i"); {{ module }}.layers = {}; … … 9 11 {{ module }}.is_polygon = {{ is_polygon|yesno:"true,false" }}; 10 12 {{ module }}.is_point = {{ is_point|yesno:"true,false" }}; 11 13 {% endblock %} 12 {{ module }}.get_ewkt = function(feat){return 'SRID={{ srid }};' + {{ module }}.wkt_f.write(feat);} 14 {{ module }}.get_ewkt = function(feat){return 'SRID={{ srid }};' + {{ module }}.wkt_f.write(feat);}; 13 15 {{ module }}.read_wkt = function(wkt){ 14 16 // OpenLayers cannot handle EWKT -- we make sure to strip it out. 15 17 // EWKT is only exposed to OL if there's a validation error in the admin. 16 18 var match = {{ module }}.re.exec(wkt); 17 19 if (match){wkt = match[1];} 18 20 return {{ module }}.wkt_f.read(wkt); 19 } 21 }; 20 22 {{ module }}.write_wkt = function(feat){ 21 23 if ({{ module }}.is_collection){ {{ module }}.num_geom = feat.geometry.components.length;} 22 24 else { {{ module }}.num_geom = 1;} 23 25 document.getElementById('{{ id }}').value = {{ module }}.get_ewkt(feat); 24 } 26 }; 25 27 {{ module }}.add_wkt = function(event){ 26 28 // This function will sync the contents of the `vector` layer with the 27 29 // WKT in the text field. … … 40 42 } 41 43 {{ module }}.write_wkt(event.feature); 42 44 } 43 } 45 }; 44 46 {{ module }}.modify_wkt = function(event){ 45 47 if ({{ module }}.is_collection){ 46 48 if ({{ module }}.is_point){ … … 58 60 } else { 59 61 {{ module }}.write_wkt(event.feature); 60 62 } 61 } 63 }; 62 64 // Function to clear vector features and purge wkt from div 63 65 {{ module }}.deleteFeatures = function(){ 64 66 {{ module }}.layers.vector.removeFeatures({{ module }}.layers.vector.features); … … 68 70 {{ module }}.deleteFeatures(); 69 71 document.getElementById('{{ id }}').value = ''; 70 72 {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }}); 71 } 73 }; 72 74 // Add Select control 73 75 {{ module }}.addSelectControl = function(){ 74 76 var select = new OpenLayers.Control.SelectFeature({{ module }}.layers.vector, {'toggle' : true, 'clickout' : true}); 75 77 {{ module }}.map.addControl(select); 76 78 select.activate(); 77 } 78 {{ module }}.enableDrawing = function(){ {{ module }}.map.getControlsByClass('OpenLayers.Control.DrawFeature')[0].activate();} 79 {{ module }}.enableEditing = function(){ {{ module }}.map.getControlsByClass('OpenLayers.Control.ModifyFeature')[0].activate();} 79 }; 80 {{ module }}.enableDrawing = function(){ {{ module }}.map.getControlsByClass('OpenLayers.Control.DrawFeature')[0].activate();}; 81 {{ module }}.enableEditing = function(){ {{ module }}.map.getControlsByClass('OpenLayers.Control.ModifyFeature')[0].activate();}; 80 82 // Create an array of controls based on geometry type 81 83 {{ module }}.getControls = function(lyr){ 82 84 {{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'}); … … 88 90 draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'}); 89 91 } else if ({{ module }}.is_point){ 90 92 draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}); 91 } 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]; 93 }; 94 // TODO: draw_ctl is undefined if is_collection==true and collection_type=='Any'. Don't know what handler to use then. 95 if (draw_ctl != undefined) { 96 if ({{module}}.is_collection ) { 97 draw_ctl.multi = true; 98 }; 99 if ({{ module }}.modifiable){ 100 var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'}); 101 {{ module }}.controls = [nav, draw_ctl, mod]; 98 102 } else { 99 {{ module }}.controls = [nav]; 103 if(!lyr.features.length){ 104 {{ module }}.controls = [nav, draw_ctl]; 105 } else { 106 {{ module }}.controls = [nav]; 107 } 100 108 } 101 109 } 102 } 110 }; 103 111 {{ module }}.init = function(){ 104 112 {% block map_options %}// The options hash, w/ zoom, resolution, and projection settings. 105 113 var options = { … … 164 172 } else { 165 173 {{ module }}.enableDrawing(); 166 174 } 167 } 175 };