3
(hz                 @   sh   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 dZG dd deZG d	d
 d
eZdS )    )
ModelAdmin)OpenLayersWidget)models)HAS_GDALOGRGeomType)ImproperlyConfiguredi  c                   s   e Zd ZdZdZdZdZdZdZg Z	dZ
dZdZdZdZdZdZdZdZdZdZdZdZd	Zd
ZdZe
d ZdZdZdZddiZdZe Z!e" fddZ# fddZ$dd Z%  Z&S )GeoModelAdminz
    The administration options class for Geographic models. Map settings
    may be overloaded from their defaults to create custom maps.
    r      F   TiX  i  i  zgis/admin/openlayers.htmlz.http://openlayers.org/api/2.13.1/OpenLayers.js   z&http://vmap0.tiles.osgeo.org/wms/vmap0basiczOpenLayers WMSformatz
image/jpegc                s*   t t| j}|j| jg |j| j |S )z-Injects OpenLayers JavaScript into the admin.)superr   mediaZadd_jsopenlayers_urlextra_js)selfr   )	__class__ D/tmp/pip-install-q3hcpn_q/Django/django/contrib/gis/admin/options.pyr   /   s    zGeoModelAdmin.mediac                sr   t |tjrX|jdk rXt r>|j| jkr>td| j||jf | j||d< |j	f |S t
t| j||f|S dS )z
        Overloaded from ModelAdmin so that an OpenLayersWidget is used
        for viewing/editing 2D GeometryFields (OpenLayers 2 does not support
        3D editing).
           z\Map SRID is %s and SRID of `%s` is %s. GDAL must be installed to perform the transformation.widgetN)
isinstancer   ZGeometryFieldZdimr   sridmap_sridr   get_map_widgetZ	formfieldr   r   formfield_for_dbfield)r   db_fieldrequestkwargs)r   r   r   r   7   s    z#GeoModelAdmin.formfield_for_dbfieldc                sV   j dkr2j dkrd q6tj jdd nd G  fd	d
d
j}|S )z
        Returns a subclass of the OpenLayersWidget (or whatever was specified
        in the `widget` attribute) using the settings from the attributes set
        in this class.
        
MULTIPOINTMULTILINESTRINGMULTIPOLYGONGEOMETRYCOLLECTIONZAnyZMULTI Nonec            "       s   e Zd ZjZjZdZjr@dd jj D Zddje Zj	j
jjpVjejjjj jdkjdkjdkjdkjjjjjjjjjjjjjjj j!j"ejd!Z#dS )z+GeoModelAdmin.get_map_widget.<locals>.OLMapr$   c             S   s   g | ]}d | qS )z%s: '%s'r   ).0pairr   r   r   
<listcomp>_   s    z6GeoModelAdmin.get_map_widget.<locals>.OLMap.<listcomp>z, %sz, ZGEOMETRY
LINESTRINGr!   POLYGONr"   POINTr    )!default_londefault_latdefault_zoomdisplay_wkt	geom_type
field_nameis_collection
scrollablelayerswitchercollection_typeZ
is_genericZis_linestringZ
is_polygonZis_pointnum_zoommax_zoommin_zoomunitsmax_resolution
max_extent
modifiablemouse_position
scale_text	map_width
map_height
point_zoomr   display_sridwms_url	wms_layerwms_namewms_optionsdebugN)r)   r!   )r*   r"   )r+   r    )$__name__
__module____qualname__map_templatetemplater0   rF   itemsjoinr,   r-   r.   rG   r/   r   namer3   r4   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   r   rB   rC   rD   rE   paramsr   )r5   r   r2   r   r   r   OLMapY   sN   
rQ   )r    r!   r"   r#   )r0   r   replacer   )r   r   rQ   r   )r5   r   r2   r   r   r   J   s    

+zGeoModelAdmin.get_map_widget)'rH   rI   rJ   __doc__r,   r-   r.   r/   rB   r   r6   r7   r8   r9   r:   r;   r<   r=   r>   r4   r3   r?   r@   r   rK   r   rA   rC   rD   rE   rF   rG   r   r   propertyr   r   r   __classcell__r   r   )r   r   r   
   sB   r   c               @   s,   e Zd ZdZdZeZdZdZed Z	dZ
dS )OSMGeoAdminzgis/admin/osm.html   z%-20037508,-20037508,20037508,20037508z156543.0339r   mN)rH   rI   rJ   rK   r6   spherical_mercator_sridr   r;   r:   rA   r9   r   r   r   r   rV      s   rV   N)Zdjango.contrib.adminr   Z django.contrib.gis.admin.widgetsr   Zdjango.contrib.gis.dbr   Zdjango.contrib.gis.gdalr   r   Zdjango.core.exceptionsr   rY   r   rV   r   r   r   r   <module>   s   }