
 X$                 @   s   d  d l  m Z d  d l m Z d  d l m Z m Z m Z d  d l m	 Z	 d  d l
 m Z d  d l m Z d  d l m Z Gd d	   d	 e  Z d
 Z Gd d   d e  Z Gd d   d e  Z d S)    )unicode_literals)settings)GMarkerGPolygon	GPolyline)render_to_string)format_html)	mark_safe)rangec               @   s   e  Z d  Z d S)GoogleMapExceptionN)__name__
__module____qualname__ r   r   Q/home/ubuntu/projects/ifolica/build/django/django/contrib/gis/maps/google/gmap.pyr      s   r   z.http://maps.google.com/maps?file=api&v=%s&key=c               @   s	  e  Z d  Z d Z e d  Z e d  Z e d  Z d d d d d d g  d d d d d i  d	 d
  Z d d   Z	 e
 d d    Z e
 d d    Z e
 d d    Z e
 d d    Z e
 d d    Z e
 d d    Z e
 d d    Z e
 d d    Z d S)	GoogleMapz.A class for generating Google Maps JavaScript.zonunload="GUnload()"z"v\:* {behavior:url(#default#VML);}z'xmlns:v="urn:schemas-microsoft-com:vml"Nmapzgis/google/google-map.jsZ	geodjangoc             C   s  | s: y t  j |  _ WqC t k
 r6 t d   YqC Xn	 | |  _ | sa t t  d d  |  _ n	 | |  _ | s t t  d t  |  j |  _ n	 | |  _ | |  _	 | |  _
 | |  _ | |  _ | |  _ t |
 d g t |	 d g t | d g g } x | D]} \ } } } t |  | g   | r xU | D]J } t | |  rPt |  |  j |  q"t |  |  j | |   q"Wq q Wd |  _ |  j s|  j s|  j r| d  k s| d  k rd	 |  _ qn  | d  k rd
 } n  | |  _ | d  k rd } n  | |  _ d  S)NzPGoogle Maps API Key not found (try adding GOOGLE_MAPS_API_KEY to your settings).ZGOOGLE_MAPS_API_VERSIONz2.xGOOGLE_MAPS_URLmarkerspolygons	polylinesFT   r   )r   r   )r   ZGOOGLE_MAPS_API_KEYkeyAttributeErrorr   getattrversionr   api_urldom_idextra_context	js_moduletemplatekml_urlsr   r   r   setattr
isinstanceappend	calc_zoomr   r   r   zoomcenter)selfr   r   r   r'   r&   r   r!   r   r   r   r    r   r   Zoverlay_infoZoverlay_classZoverlay_listZvarnameZoverlayr   r   r   __init__   sL    
								'				zGoogleMap.__init__c             C   s   i
 |  j  d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d	 6|  j	 d
 6} | j
 |  j  t |  j |  S)zT
        Generates the JavaScript necessary for displaying this Google Map.
        r%   r'   r   r   r!   r&   r   r   iconsr   )r%   r'   r   r   r!   r&   r   r   r*   r   updater   r   r    )r(   paramsr   r   r   renderh   s    







zGoogleMap.renderc             C   s   t  d |  j |  j  S)zGReturns HTML body tag for loading and unloading Google Maps javascript.z<body {} {}>)r   onloadonunload)r(   r   r   r   bodyz   s    zGoogleMap.bodyc             C   s   t  d |  j |  j  S)z+Returns the `onload` HTML <body> attribute.zonload="{}.{}_load()")r   r   r   )r(   r   r   r   r.      s    zGoogleMap.onloadc             C   s   t  d |  j |  j  S)z<Returns the <script> tag for the Google Maps API javascript.z3<script src="{}{}" type="text/javascript"></script>)r   r   r   )r(   r   r   r   
api_script   s    zGoogleMap.api_scriptc             C   s
   |  j    S)zEReturns only the generated Google Maps JavaScript (no <script> tags).)r-   )r(   r   r   r   js   s    zGoogleMap.jsc             C   s   t  d |  j t |  j   S)zHReturns all <script></script> tags required with Google Maps JavaScript.zD{}
  <script type="text/javascript">
//<![CDATA[
{}//]]>
  </script>)r   r1   r	   r2   )r(   r   r   r   scripts   s    zGoogleMap.scriptsc             C   s   t  d |  j  S)z<Returns additional CSS styling needed for Google Maps on IE.z!<style type="text/css">{}</style>)r   vml_css)r(   r   r   r   style   s    zGoogleMap.stylec             C   s   t  d |  j  S)z5Returns XHTML information needed for IE VML overlays.z.<html xmlns="http://www.w3.org/1999/xhtml" {}>)r   xmlns)r(   r   r   r   xhtml   s    zGoogleMap.xhtmlc             C   s   t  d d   |  j D  S)z0Returns a sequence of GIcon objects in this map.c             s   s!   |  ] } | j  r | j  Vq d  S)N)Zicon).0markerr   r   r   	<genexpr>   s    z"GoogleMap.icons.<locals>.<genexpr>)setr   )r(   r   r   r   r*      s    zGoogleMap.icons)r   r   r   __doc__r	   r/   r4   r6   r)   r-   propertyr0   r.   r1   r2   r3   r5   r7   r*   r   r   r   r   r      s&   		Er   c                   s^   e  Z d  Z   f d d   Z d d   Z d d   Z e d d    Z e d	 d
    Z   S)GoogleMapSetc                s   | j  d d  } | j  d d  |  _ t t |   j |   | |  _ t | d t t f  ro | d |  _	 n	 | |  _	 d d   t
 t |  j	   D |  _ d S)	z
        A class for generating sets of Google Maps that will be shown on the
        same page together.

        Example:
         gmapset = GoogleMapSet( GoogleMap( ... ), GoogleMap( ... ) )
         gmapset = GoogleMapSet( [ gmap1, gmap2] )
        r    zgis/google/google-multi.jsmap_templatezgis/google/google-single.jsr   c             S   s   g  |  ] } d  |  q S)zmap%dr   )r8   ir   r   r   
<listcomp>   s   	 z)GoogleMapSet.__init__.<locals>.<listcomp>N)popr?   superr>   r)   r    r#   tuplelistmapsr
   lendom_ids)r(   argskwargsr    )	__class__r   r   r)      s    		zGoogleMapSet.__init__c             C   s   g  } xl t  |  j |  j  D]U \ } } | j | j f } |  j | _ | | _ | j | j  | \ | _ | _ q Wt d j	 |   S)zm
        Returns JavaScript containing all of the loading routines for each
        map in this set.
         )
ziprH   rF   r    r   r?   r$   r2   r	   join)r(   resultr   Zgmaptmpr   r   r   load_map_js   s    "	zGoogleMapSet.load_map_jsc             C   sQ   i |  j  d 6|  j d 6|  j   d 6|  j d 6} | j |  j  t |  j |  S)za
        Generates the JavaScript for the collection of Google Maps in
        this set.
        r   rH   rQ   r*   )r   rH   rQ   r*   r+   r   r   r    )r(   r,   r   r   r   r-      s    
zGoogleMapSet.renderc             C   s   t  d |  j  S)z+Returns the `onload` HTML <body> attribute.zonload="%s.load()")r	   r   )r(   r   r   r   r.      s    zGoogleMapSet.onloadc             C   s.   t    } x |  j D] } | | j O} q W| S)z7Returns a sequence of all icons in each map of the set.)r;   rF   r*   )r(   r*   r   r   r   r   r*      s    	zGoogleMapSet.icons)	r   r   r   r)   rQ   r-   r=   r.   r*   r   r   )rK   r   r>      s
   r>   N)
__future__r   Zdjango.confr   Z'django.contrib.gis.maps.google.overlaysr   r   r   Zdjango.template.loaderr   Zdjango.utils.htmlr   Zdjango.utils.safestringr	   Zdjango.utils.six.movesr
   	Exceptionr   r   objectr   r>   r   r   r   r   <module>   s   