3
gp                 @   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< |rt|try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rd }| 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    ^/var/www/tester-filtro-web/env/lib/python3.6/site-packages/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rd| 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   
