U
    N+|jé  ã                   @   sz   d dl Z d dlZd dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ de
 ¡ iZe  d¡ZG d	d
„ d
eƒZdS )é    N)ÚGDALException)ÚGEOSExceptionÚGEOSGeometry)ÚTextarea)Útranslation)ÚRemovedInDjango50WarningZLANGUAGE_BIDIzdjango.contrib.gisc                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )ÚOpenLayersWidgetzA
    Render an OpenLayers map using the WKT of the geometry.
    c                    s"   t jdtdd� tƒ j||Ž d S )Nz8django.contrib.gis.admin.OpenLayersWidget is deprecated.é   )Ú
stacklevel)ÚwarningsÚwarnr   ÚsuperÚ__init__)ÚselfÚargsÚkwargs©Ú	__class__© úhc:\users\snmko\desktop\web_content\django_cbt\venv\Lib\site-packages\django/contrib/gis/admin/widgets.pyr      s    ýzOpenLayersWidget.__init__c           	   
   C   sz  |r"| j  |¡ | j d | j d< n
d| j d< d| j d< |rŠt|tƒrŠzt|ƒ}W n8 ttfk
rˆ } zt d||¡ d }W 5 d }~X Y nX |r¬|j	 
¡ | j	kr¬| j	dkr¬d }|  ¡ | j d< || j d	< | j d	  d
d¡}d| | j d< |�rh| j d }|j|k�rXz|j}| |¡ |j}W n: tk
�rT } zt d|j||¡ d}W 5 d }~X Y nX n|j}|| j d< | j  t¡ | j S )NZ
modifiableÚeditableTÚ Úwktz,Error creating geometry from value '%s' (%s)ZGEOMETRYÚmap_optionsÚnameú-Ú_zgeodjango_%sÚmoduleÚsridz<Error transforming geometry from srid '%s' to srid '%s' (%s))ÚparamsÚupdateÚ
isinstanceÚstrr   r   Ú
ValueErrorÚloggerÚerrorZ	geom_typeÚupperr   Úreplacer   ÚogrZ	transformr   r   Úgeo_context)	r   r   ÚvalueÚattrsÚerrZjs_safe_namer   r(   r   r   r   r   Úget_context   sR    

ÿþý



ü
zOpenLayersWidget.get_contextc           	   
   C   sÖ   dd„ }dd„ }ddddt fdd	tfd
ddtfddtfddtfg}i }|D ]†\}}}| j |d¡rJ|dkrz|| j| ƒ}nN|dkr’|| j| ƒ}n6|ttfkrª| j| }n|t fkrÄd| j|  }nt‚|||< qJ|S )z7Build the map options hash for the OpenLayers template.c                 S   s   d|  S )Nznew OpenLayers.Bounds(%s)r   )Zextentr   r   r   Ú	ol_boundsf   s    z/OpenLayersWidget.map_options.<locals>.ol_boundsc                 S   s   d|  S )Nz$new OpenLayers.Projection("EPSG:%s")r   )r   r   r   r   Úol_projectioni   s    z3OpenLayersWidget.map_options.<locals>.ol_projection)r   Z
projectionr   )Zdisplay_sridZdisplayProjectionr   ZunitsZmax_resolutionZmaxResolution)Z
max_extentZ	maxExtentÚboundsZnum_zoomZnumZoomLevelsZmax_zoomZmaxZoomLevelsZmin_zoomZminZoomLevelFr   r0   z"%s")r"   ÚfloatÚintr   ÚgetÚ	TypeError)	r   r.   r/   Z	map_typesr   Ú
param_nameZjs_nameZoption_typer*   r   r   r   r   b   s2    ø

zOpenLayersWidget.map_options)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r-   r   Ú__classcell__r   r   r   r   r      s   Dr   )Úloggingr   Zdjango.contrib.gis.gdalr   Zdjango.contrib.gis.geosr   r   Zdjango.forms.widgetsr   Zdjango.utilsr   Zdjango.utils.deprecationr   Zget_language_bidir)   Ú	getLoggerr$   r   r   r   r   r   Ú<module>   s   
