U
    8ÄT_  ã                   @   sd   d dl mZ d dlmZ d dlmZ d dl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)ÚOGRGeomType)ÚMediai  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.htmlzFhttps://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.jsé   z&http://vmap0.tiles.osgeo.org/wms/vmap0ÚbasiczOpenLayers WMSÚformatz
image/jpegc                    s   t ƒ jt| jg| j d� S )z-Injects OpenLayers JavaScript into the admin.)Zjs)ÚsuperÚmediar   Úopenlayers_urlÚextra_js)Úself©Ú	__class__© úD/tmp/pip-unpacked-wheel-dv63caxw/django/contrib/gis/admin/options.pyr   /   s    zGeoModelAdmin.mediac                    sF   t |tjƒr0|jdk r0|  |¡|d< |jf |ŽS 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).
        é   ÚwidgetN)Ú
isinstancer   ZGeometryFieldZdimÚget_map_widgetZ	formfieldr   Úformfield_for_dbfield)r   Údb_fieldÚrequestÚkwargsr   r   r   r   4   s    z#GeoModelAdmin.formfield_for_dbfieldc                    sV   ˆj dk‰ˆr2ˆj dkrd‰ q6tˆj  dd¡ƒ‰ nd‰ G ‡ ‡‡‡fdd„dˆjƒ}|S )	z»
        Return 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ÚGEOMETRYCOLLECTIONr!   ÚAnyZMULTIÚ ÚNonec                "       sâ   e Zd Z”jZ”jZdZ”jr@dd„ ”j ¡ D ƒZdd 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>V   s     z6GeoModelAdmin.get_map_widget.<locals>.OLMap.<listcomp>z, %sz, ZGEOMETRY)Z
LINESTRINGr   )ZPOLYGONr    )Z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_zoomZsridÚdisplay_sridÚwms_urlÚ	wms_layerÚwms_nameÚwms_optionsÚdebugN)$Ú__name__Ú
__module__Ú__qualname__Úmap_templateZtemplate_namer,   rB   ÚitemsÚjoinr(   r)   r*   rC   r+   r   Únamer/   r0   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   Úmap_sridr>   r?   r@   rA   Úparamsr   ©r1   r   r.   r   r   r   ÚOLMapP   sP   
ßrN   )r,   r   Úreplacer   )r   r   rN   r   rM   r   r   A   s    

,zGeoModelAdmin.get_map_widget)'rD   rE   rF   Ú__doc__r(   r)   r*   r+   r>   r   r2   r3   r4   r5   r6   r7   r8   r9   r:   r0   r/   r;   r<   rK   rG   r   r=   r?   r@   rA   rB   rC   r   r   Úpropertyr   r   r   Ú__classcell__r   r   r   r   r   
   sD   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)rD   rE   rF   rG   r2   Úspherical_mercator_sridrK   r7   r6   r=   r5   r   r   r   r   rS      s   rS   N)Zdjango.contrib.adminr   Z django.contrib.gis.admin.widgetsr   Zdjango.contrib.gis.dbr   Zdjango.contrib.gis.gdalr   Zdjango.formsr   rV   r   rS   r   r   r   r   Ú<module>   s   u