ó
Š*Pc           @   s¸   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z m Z m Z d e f d „  ƒ  YZ d	 Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   settings(   t   render_to_string(   t   format_html(   t	   mark_safe(   t   xrange(   t   GPolygont	   GPolylinet   GMarkert   GoogleMapExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyR   	   s   s.   http://maps.google.com/maps?file=api&v=%s&key=t	   GoogleMapc           B   sã   e  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 „ Z d „  Z	 e
 d	 „  ƒ Z e
 d
 „  ƒ Z e
 d „  ƒ Z e
 d „  ƒ Z e
 d „  ƒ Z e
 d „  ƒ Z e
 d „  ƒ Z e
 d „  ƒ Z RS(   s.   A class for generating Google Maps JavaScript.s   onunload="GUnload()"s"   v\:* {behavior:url(#default#VML);}s'   xmlns:v="urn:schemas-microsoft-com:vml"t   maps   gis/google/google-map.jst	   geodjangoc         C   s  | s9 y t  j |  _ WqB t k
 r5 t d ƒ ‚ qB Xn	 | |  _ | s` 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 | | ƒ rOt |  | ƒ j | ƒ q!t |  | ƒ j | | ƒ ƒ q!Wqõ qõ Wt |  _ |  j sš|  j sš|  j rÁ| d  k s²| d  k rÁt |  _ qÁn  | d  k rÖd } n  | |  _ | d  k rôd
 } n  | |  _ d  S(   NsP   Google Maps API Key not found (try adding GOOGLE_MAPS_API_KEY to your settings).t   GOOGLE_MAPS_API_VERSIONs   2.xt   GOOGLE_MAPS_URLt   markerst   polygonst	   polylinesi   i    (   i    i    (   R    t   GOOGLE_MAPS_API_KEYt   keyt   AttributeErrorR   t   getattrt   versionR   t   api_urlt   dom_idt   extra_contextt	   js_modulet   templatet   kml_urlsR   R   R   t   setattrt
   isinstancet   appendt   Falset	   calc_zoomR   R   R   t   Nonet   Truet   zoomt   center(   t   selfR   R   R   R&   R%   R   R   R   R   R   R   R   R   t   overlay_infot   overlay_classt   overlay_listt   varnamet   overlay(    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyt   __init__   sJ    
								'	 		 	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(   sT   
        Generates the JavaScript necessary for displaying this Google Map.
        R"   R&   R   R   R   R%   R   R   t   iconsR   (   R"   R&   R   R   R   R%   R   R   R.   R   t   updateR   R   R   (   R'   t   params(    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyt   render_   s    







c         C   s   t  d |  j |  j ƒ S(   sG   Returns HTML body tag for loading and unloading Google Maps javascript.s   <body {0} {1}>(   R   t   onloadt   onunload(   R'   (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyt   bodyq   s    c         C   s   t  d |  j |  j ƒ S(   s+   Returns the `onload` HTML <body> attribute.s   onload="{0}.{1}_load()"(   R   R   R   (   R'   (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyR2   v   s    c         C   s   t  d |  j |  j ƒ S(   s<   Returns the <script> tag for the Google Maps API javascript.s5   <script src="{0}{1}" type="text/javascript"></script>(   R   R   R   (   R'   (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyt
   api_script{   s    c         C   s
   |  j  ƒ  S(   sE   Returns only the generated Google Maps JavaScript (no <script> tags).(   R1   (   R'   (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyt   js   s    c         C   s   t  d |  j t |  j ƒ ƒ S(   sH   Returns all <script></script> tags required with Google Maps JavaScript.sD   %s
  <script type="text/javascript">
//<![CDATA[
%s//]]>
  </script>(   R   R5   R   R6   (   R'   (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyt   scripts†   s    c         C   s   t  d |  j ƒ S(   s<   Returns additional CSS styling needed for Google Maps on IE.s"   <style type="text/css">{0}</style>(   R   t   vml_css(   R'   (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyt   style‹   s    c         C   s   t  d |  j ƒ S(   s5   Returns XHTML information needed for IE VML overlays.s/   <html xmlns="http://www.w3.org/1999/xhtml" {0}>(   R   t   xmlns(   R'   (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyt   xhtml   s    c         C   s,   t  g  |  j D] } | j r | j ^ q ƒ S(   s0   Returns a sequence of GIcon objects in this map.(   t   setR   t   icon(   R'   t   marker(    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyR.   •   s    N(   R	   R
   t   __doc__R   R3   R8   R:   R#   R-   R1   t   propertyR4   R2   R5   R6   R7   R9   R;   R.   (    (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyR      s&   		@	t   GoogleMapSetc           B   sA   e  Z d  „  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z RS(   c         O   s«   | j  d d ƒ } | j  d d ƒ |  _ t t |  ƒ j |   | |  _ t | d t t f ƒ ro | d |  _	 n	 | |  _	 g  t
 t |  j	 ƒ ƒ D] } d | ^ qŽ |  _ d S(   sý   
        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   s   gis/google/google-multi.jst   map_templates   gis/google/google-single.jsi    s   map%dN(   t   popRB   t   superRA   R-   R   R   t   tuplet   listt   mapsR   t   lent   dom_ids(   R'   t   argst   kwargsR   t   i(    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyR-   œ   s    		c         C   sˆ   g  } xl t  |  j |  j ƒ D]U \ } } | j | j f } |  j | _ | | _ | j | j ƒ | \ | _ | _ q Wt d j	 | ƒ ƒ S(   sm   
        Returns JavaScript containing all of the loading routines for each
        map in this set.
        t    (
   t   zipRI   RG   R   R   RB   R    R6   R   t   join(   R'   t   resultR   t   gmapt   tmp(    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyt   load_map_js»   s    "	c         C   sQ   i |  j  d 6|  j d 6|  j ƒ  d 6|  j d 6} | j |  j ƒ t |  j | ƒ S(   sa   
        Generates the JavaScript for the collection of Google Maps in
        this set.
        R   RI   RS   R.   (   R   RI   RS   R.   R/   R   R   R   (   R'   R0   (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyR1   Î   s    
c         C   s   t  d |  j ƒ S(   s+   Returns the `onload` HTML <body> attribute.s   onload="%s.load()"(   R   R   (   R'   (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyR2   Û   s    c         C   s.   t  ƒ  } x |  j D] } | | j O} q W| S(   s7   Returns a sequence of all icons in each map of the set.(   R<   RG   R.   (   R'   R.   R   (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyR.   ã   s    	 (   R	   R
   R-   RS   R1   R@   R2   R.   (    (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyRA   š   s
   			N(   t   django.confR    t   django.template.loaderR   t   django.utils.htmlR   t   django.utils.safestringR   t   django.utils.six.movesR   t'   django.contrib.gis.maps.google.overlaysR   R   R   t	   ExceptionR   R   t   objectR   RA   (    (    (    s<   ../Django//lib/python/django/contrib/gis/maps/google/gmap.pyt   <module>   s   ˆ