o
    Ti                     @   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|i | d S )Nz8django.contrib.gis.admin.OpenLayersWidget is deprecated.   )
stacklevel)warningswarnr   super__init__)selfargskwargs	__class__ `/var/www/html/evchargy.com/venv/lib/python3.10/site-packages/django/contrib/gis/admin/widgets.pyr      s   zOpenLayersWidget.__init__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rz|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 )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   ogr	transformr   r   geo_context)	r   r   valueattrserrZjs_safe_namer   r(   r   r   r   r   get_context   sV   







	
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   )Zextentr   r   r   	ol_boundsf      z/OpenLayersWidget.map_options.<locals>.ol_boundsc                 S   r/   )Nz$new OpenLayers.Projection("EPSG:%s")r   )r   r   r   r   ol_projectioni   r1   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   r3   z"%s")r"   floatintr   get	TypeError)	r   r0   r2   Z	map_typesr   
param_nameZjs_nameZoption_typer+   r   r   r   r   b   s4   
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   
