<s> from django . contrib . admin import ModelAdmin <EOL> from django . contrib . gis . admin . widgets import OpenLayersWidget <EOL> from django . contrib . gis . gdal import OGRGeomType <EOL> from django . contrib . gis . db import models <EOL> class GeoModelAdmin ( ModelAdmin ) : <EOL> """<STR_LIT>""" <EOL> default_lon = <NUM_LIT:0> <EOL> default_lat = <NUM_LIT:0> <EOL> default_zoom = <NUM_LIT:4> <EOL> display_wkt = False <EOL> display_srid = False <EOL> extra_js = [ ] <EOL> num_zoom = <NUM_LIT> <EOL> max_zoom = False <EOL> min_zoom = False <EOL> units = False <EOL> max_resolution = False <EOL> max_extent = False <EOL> modifiable = True <EOL> mouse_position = True <EOL> scale_text = True <EOL> layerswitcher = True <EOL> scrollable = True <EOL> map_width = <NUM_LIT> <EOL> map_height = <NUM_LIT> <EOL> map_srid = <NUM_LIT> <EOL> map_template = '<STR_LIT>' <EOL> openlayers_url = '<STR_LIT>' <EOL> point_zoom = num_zoom - <NUM_LIT:6> <EOL> wms_url = '<STR_LIT>' <EOL> wms_layer = '<STR_LIT>' <EOL> wms_name = '<STR_LIT>' <EOL> wms_options = { '<STR_LIT>' : '<STR_LIT>' } <EOL> debug = False <EOL> widget = OpenLayersWidget <EOL> @ property <EOL> def media ( self ) : <EOL> "<STR_LIT>" <EOL> media = super ( GeoModelAdmin , self ) . media <EOL> media . add_js ( [ self . openlayers_url ] ) <EOL> media . add_js ( self . extra_js ) <EOL> return media <EOL> def formfield_for_dbfield ( self , db_field , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( db_field , models . GeometryField ) and db_field . dim < <NUM_LIT:3> : <EOL> request = kwargs . pop ( '<STR_LIT>' , None ) <EOL> kwargs [ '<STR_LIT>' ] = self . get_map_widget ( db_field ) <EOL> return db_field . formfield ( ** kwargs ) <EOL> else : <EOL> return super ( GeoModelAdmin , self ) . formfield_for_dbfield ( db_field , ** kwargs ) <EOL> def get_map_widget ( self , db_field ) : <EOL> """<STR_LIT>""" <EOL> is_collection = db_field . geom_type in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if is_collection : <EOL> if db_field . geom_type == '<STR_LIT>' : collection_type = '<STR_LIT>' <EOL> else : collection_type = OGRGeomType ( db_field . geom_type . replace ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> else : <EOL> collection_type = '<STR_LIT:None>' <EOL> class OLMap ( self . widget ) : <EOL> template = self . map_template <EOL> geom_type = db_field . geom_type <EOL> wms_options = '<STR_LIT>' <EOL> if self . wms_options : <EOL> wms_options = [ "<STR_LIT>" % pair for pair in self . wms_options . items ( ) ] <EOL> wms_options = '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( wms_options ) <EOL> params = { '<STR_LIT>' : self . default_lon , <EOL> '<STR_LIT>' : self . default_lat , <EOL> '<STR_LIT>' : self . default_zoom , <EOL> '<STR_LIT>' : self . debug or self . display_wkt , <EOL> '<STR_LIT>' : OGRGeomType ( db_field . geom_type ) , <EOL> '<STR_LIT>' : db_field . name , <EOL> '<STR_LIT>' : is_collection , <EOL> '<STR_LIT>' : self . scrollable , <EOL> '<STR_LIT>' : self . layerswitcher , <EOL> '<STR_LIT>' : collection_type , <EOL> '<STR_LIT>' : db_field . geom_type == '<STR_LIT>' , <EOL> '<STR_LIT>' : db_field . geom_type in ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : db_field . geom_type in ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : db_field . geom_type in ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . num_zoom , <EOL> '<STR_LIT>' : self . max_zoom , <EOL> '<STR_LIT>' : self . min_zoom , <EOL> '<STR_LIT>' : self . units , <EOL> '<STR_LIT>' : self . max_resolution , <EOL> '<STR_LIT>' : self . max_extent , <EOL> '<STR_LIT>' : self . modifiable , <EOL> '<STR_LIT>' : self . mouse_position , <EOL> '<STR_LIT>' : self . scale_text , <EOL> '<STR_LIT>' : self . map_width , <EOL> '<STR_LIT>' : self . map_height , <EOL> '<STR_LIT>' : self . point_zoom , <EOL> '<STR_LIT>' : self . map_srid , <EOL> '<STR_LIT>' : self . display_srid , <EOL> '<STR_LIT>' : self . wms_url , <EOL> '<STR_LIT>' : self . wms_layer , <EOL> '<STR_LIT>' : self . wms_name , <EOL> '<STR_LIT>' : wms_options , <EOL> '<STR_LIT>' : self . debug , <EOL> } <EOL> return OLMap <EOL> from django . contrib . gis import gdal <EOL> if gdal . HAS_GDAL : <EOL> if gdal . GDAL_VERSION >= ( <NUM_LIT:1> , <NUM_LIT:7> ) : <EOL> spherical_mercator_srid = <NUM_LIT> <EOL> else : <EOL> spherical_mercator_srid = <NUM_LIT> <EOL> class OSMGeoAdmin ( GeoModelAdmin ) : <EOL> map_template = '<STR_LIT>' <EOL> num_zoom = <NUM_LIT:20> <EOL> map_srid = spherical_mercator_srid <EOL> max_extent = '<STR_LIT>' <EOL> max_resolution = '<STR_LIT>' <EOL> point_zoom = num_zoom - <NUM_LIT:6> <EOL> units = '<STR_LIT:m>' </s>
