3
W­E^p  ã               @   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	j
ƒ iZe jdƒZG dd	„ d	eƒZdS )
é    N)ÚGDALException)ÚGEOSExceptionÚGEOSGeometry)ÚTextarea)ÚtranslationZ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   sz  |r"| j j|ƒ | j d | j d< n
d| j d< d| j d< |rŠt|tƒrŠyt|ƒ}W n8 ttfk
rˆ } ztjd||ƒ d }W Y d d }~X nX |r¬|j	j
ƒ | j	kr¬| j	dkr¬d }| jƒ | j d< || j d	< | j d	 jd
dƒ}d| | j d< |�rh| j d }|j|k�rXy|j}|j|ƒ |j}W n: tk
�rT } ztjd|j||ƒ d}W Y d d }~X nX n|j}|| j d< | j 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)	Úselfr   ÚvalueÚattrsÚerrZjs_safe_namer   r   r
   © r    úB/tmp/pip-build-78s3knkw/Django/django/contrib/gis/admin/widgets.pyÚget_context   sD    







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 }xŽ|D ]†\}}}| jj|dƒrL|dkr||| j| ƒ}nN|dkr”|| j| ƒ}n6|ttfkr¬| j| }n|t fkrÆd| j|  }nt‚|||< qLW |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_boundsT   s    z/OpenLayersWidget.map_options.<locals>.ol_boundsc             S   s   d|  S )Nz$new OpenLayers.Projection("EPSG:%s")r    )r   r    r    r!   Úol_projectionW   s    z3OpenLayersWidget.map_options.<locals>.ol_projectionr   Ú
projectionÚdisplay_sridÚdisplayProjectionZunitsZmax_resolutionZmaxResolutionÚ
max_extentÚ	maxExtentÚboundsZnum_zoomZnumZoomLevelsZmax_zoomZmaxZoomLevelsZmin_zoomZminZoomLevelFz"%s")r   r%   r   )r&   r'   r   )r(   r)   r*   )r   ÚfloatÚintr   ÚgetÚ	TypeError)	r   r#   r$   Z	map_typesr   Ú
param_nameZjs_nameZoption_typer   r    r    r!   r   Q   s0    
zOpenLayersWidget.map_optionsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   r   r    r    r    r!   r      s   ?r   )ÚloggingZdjango.contrib.gis.gdalr   Zdjango.contrib.gis.geosr   r   Zdjango.forms.widgetsr   Zdjango.utilsr   Zget_language_bidir   Ú	getLoggerr   r   r    r    r    r!   Ú<module>   s   
