o
    ^"<fp  ã                   @   sf   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e	 
¡ iZe  d¡ZG dd	„ d	eƒZdS )
é    N)ÚGDALException)ÚGEOSExceptionÚGEOSGeometry)ÚTextarea)ÚtranslationÚLANGUAGE_BIDIzdjango.contrib.gisc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚOpenLayersWidgetzA
    Render an OpenLayers map using the WKT of the geometry.
    c           	   
   C   sv  |r| j  |¡ | j d | j d< nd| j d< d| j d< |rFt|tƒrFzt|ƒ}W n ttfyE } zt d||¡ d }W Y d }~nd }~ww |rW|j	 
¡ | j	krW| j	dkrWd }|  ¡ | j d< || j d	< | j d	  d
d¡}d| | j d< |r²| j d }|j|krªz|j}| |¡ |j}W n  ty© } zt d|j||¡ d}W Y d }~nd }~ww |j}|| j d< | j  t¡ | j S )NÚ
modifiableÚeditableTÚ Úwktz,Error creating geometry from value '%s' (%s)Ú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ÚerrorÚ	geom_typeÚupperr   Úreplacer   ÚogrÚ	transformr   r   Úgeo_context)	Úselfr   ÚvalueÚattrsÚerrÚjs_safe_namer   r   r   © r&   úW/var/www/html/kck/venv/lib/python3.10/site-packages/django/contrib/gis/admin/widgets.pyÚget_context   sN   

€þ





þ€û
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 ]C\}}}| j |d¡rh|dkr=|| j| ƒ}n'|dkrI|| j| ƒ}n|ttfv rU| j| }n|t fv rbd| j|  }nt‚|||< q%|S )z7Build the map options hash for the OpenLayers template.c                 S   ó   d|  S )Nznew OpenLayers.Bounds(%s)r&   )Úextentr&   r&   r'   Ú	ol_boundsT   ó   z/OpenLayersWidget.map_options.<locals>.ol_boundsc                 S   r)   )Nz$new OpenLayers.Projection("EPSG:%s")r&   )r   r&   r&   r'   Úol_projectionW   r,   z3OpenLayersWidget.map_options.<locals>.ol_projection)r   Ú
projectionr   )Údisplay_sridÚdisplayProjectionr   ÚunitsÚmax_resolutionÚmaxResolution)Ú
max_extentÚ	maxExtentÚboundsÚnum_zoomÚnumZoomLevelsÚmax_zoomÚmaxZoomLevelsÚmin_zoomÚminZoomLevelFr   r6   z"%s")r   ÚfloatÚintr   ÚgetÚ	TypeError)	r!   r+   r-   Ú	map_typesr   Ú
param_nameÚjs_nameÚoption_typer"   r&   r&   r'   r   Q   s4   ù
€zOpenLayersWidget.map_optionsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r(   r   r&   r&   r&   r'   r      s    ?r   )ÚloggingÚdjango.contrib.gis.gdalr   Údjango.contrib.gis.geosr   r   Údjango.forms.widgetsr   Údjango.utilsr   Úget_language_bidir    Ú	getLoggerr   r   r&   r&   r&   r'   Ú<module>   s    
