ó
Š*Pc           @   s  d  d l  m Z m Z 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 e d e f d „  ƒ  Yƒ Z e d e f d	 „  ƒ  Yƒ Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ e d e f d „  ƒ  Yƒ Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   fromstrt   Pointt
   LineStringt
   LinearRingt   Polygon(   t   total_ordering(   t	   mark_safe(   t   six(   t   python_2_unicode_compatiblet   GEventc           B   s    e  Z d  Z d „  Z d „  Z RS(   s  
    A Python wrapper for the Google GEvent object.

    Events can be attached to any object derived from GOverlayBase with the
    add_event() call.

    For more information please see the Google Maps API Reference:
     http://code.google.com/apis/maps/documentation/reference.html#GEvent

    Example:

      from django.shortcuts import render_to_response
      from django.contrib.gis.maps.google import GoogleMap, GEvent, GPolyline

      def sample_request(request):
          polyline = GPolyline('LINESTRING(101 26, 112 26, 102 31)')
          event = GEvent('click',
            'function() { location.href = "http://www.google.com"}')
          polyline.add_event(event)
          return render_to_response('mytemplate.html',
          {'google' : GoogleMap(polylines=[polyline])})
    c         C   s   | |  _  | |  _ d S(   s  
        Initializes a GEvent object.

        Parameters:

        event:
          string for the event, such as 'click'. The event must be a valid
          event for the object in the Google Maps API.
          There is no validation of the event type within Django.

        action:
          string containing a Javascript function, such as
          'function() { location.href = "newurl";}'
          The string must be a valid Javascript function. Again there is no
          validation fo the function within Django.
        N(   t   eventt   action(   t   selfR
   R   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyt   __init__!   s    	c         C   s   t  d |  j |  j f ƒ S(   s'   Returns the parameter part of a GEvent.s   "%s", %s(   R   R
   R   (   R   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyt   __str__5   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR	      s   	t   GOverlayBasec           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s   g  |  _  d  S(   N(   t   events(   R   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR   ;   s    c         C   s4   d d j  g  | D] \ } } d | | f ^ q ƒ S(   sJ   Generates a JavaScript array of GLatLng objects for the given coordinates.s   [%s]t   ,s   new GLatLng(%s,%s)(   t   join(   R   t   coordst   xt   y(    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyt   latlng_from_coords>   s    c         C   s   |  j  j | ƒ d S(   s(   Attaches a GEvent to the overlay object.N(   R   t   append(   R   R
   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyt	   add_eventB   s    c         C   s   t  d |  j j |  j f ƒ S(   s5   The string representation is the JavaScript API call.s   %s(%s)(   R   t	   __class__R   t	   js_params(   R   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR   F   s    (   R   R   R   R   R   R   (    (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR   9   s   			t   GPolygonc           B   s5   e  Z d  Z d d d d d d „ Z e d „  ƒ Z RS(   sÊ   
    A Python wrapper for the Google GPolygon object.  For more information
    please see the Google Maps API Reference:
     http://code.google.com/apis/maps/documentation/reference.html#GPolygon
    s   #0000ffi   i   gš™™™™™Ù?c         C   sÎ   t  | t j ƒ r! t | ƒ } n  t  | t t f ƒ rE t | ƒ } n  t  | t ƒ sc t d ƒ ‚ n  | j |  _ |  j	 | j
 j ƒ |  _ | | | |  _ |  _ |  _ | | |  _ |  _ t t |  ƒ j ƒ  d S(   sØ  
        The GPolygon object initializes on a GEOS Polygon or a parameter that
        may be instantiated into GEOS Polygon.  Please note that this will not
        depict a Polygon's internal rings.

        Keyword Options:

          stroke_color:
            The color of the polygon outline. Defaults to '#0000ff' (blue).

          stroke_weight:
            The width of the polygon outline, in pixels.  Defaults to 2.

          stroke_opacity:
            The opacity of the polygon outline, between 0 and 1.  Defaults to 1.

          fill_color:
            The color of the polygon fill.  Defaults to '#0000ff' (blue).

          fill_opacity:
            The opacity of the polygon fill.  Defaults to 0.4.
        s.   GPolygon may only initialize on GEOS Polygons.N(   t
   isinstanceR   t   string_typesR    t   tuplet   listR   t	   TypeErrort   envelopeR   t   shellR   t   pointst   stroke_colort   stroke_opacityt   stroke_weightt
   fill_colort   fill_opacityt   superR   R   (   R   t   polyR'   R)   R(   R*   R+   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR   P   s      c         C   s,   d |  j  |  j |  j |  j |  j |  j f S(   Ns   %s, "%s", %s, %s, "%s", %s(   R&   R'   R)   R(   R*   R+   (   R   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR   ~   s    (   R   R   R   R   t   propertyR   (    (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR   J   s   	,t	   GPolylinec           B   s/   e  Z d  Z d d d d „ Z e d „  ƒ Z RS(   sÌ   
    A Python wrapper for the Google GPolyline object.  For more information
    please see the Google Maps API Reference:
     http://code.google.com/apis/maps/documentation/reference.html#GPolyline
    s   #0000ffi   i   c         C   sè   t  | t j ƒ r! t | ƒ } n  t  | t t f ƒ rE t | ƒ } n  t  | t t f ƒ rr |  j	 | j
 ƒ |  _ n6 t  | t ƒ rœ |  j	 | j j
 ƒ |  _ n t d ƒ ‚ | j |  _ | | | |  _ |  _ |  _ t t |  ƒ j ƒ  d S(   s  
        The GPolyline object may be initialized on GEOS LineStirng, LinearRing,
        and Polygon objects (internal rings not supported) or a parameter that
        may instantiated into one of the above geometries.

        Keyword Options:

          color:
            The color to use for the polyline.  Defaults to '#0000ff' (blue).

          weight:
            The width of the polyline, in pixels.  Defaults to 2.

          opacity:
            The opacity of the polyline, between 0 and 1.  Defaults to 1.
        sX   GPolyline may only initialize on GEOS LineString, LinearRing, and/or Polygon geometries.N(   R   R   R    R    R!   R"   R   R   R   R   R   t   latlngsR%   R#   R$   t   colort   weightt   opacityR,   R/   R   (   R   t   geomR1   R2   R3   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR   ‰   s      c         C   s    d |  j  |  j |  j |  j f S(   Ns   %s, "%s", %s, %s(   R0   R1   R2   R3   (   R   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR   ª   s    (   R   R   R   R   R.   R   (    (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR/   ƒ   s   !t   GIconc           B   sD   e  Z d  Z d d d d d d d „ Z d „  Z d „  Z d „  Z RS(   sÕ  
    Creates a GIcon object to pass into a Gmarker object.

    The keyword arguments map to instance attributes of the same name. These,
    in turn, correspond to a subset of the attributes of the official GIcon
    javascript object:

    http://code.google.com/apis/maps/documentation/reference.html#GIcon

    Because a Google map often uses several different icons, a name field has
    been added to the required arguments.

    Required Arguments:
        varname:
            A string which will become the basis for the js variable name of
            the marker, for this reason, your code should assign a unique
            name for each GIcon you instantiate, otherwise there will be
            name space collisions in your javascript.

    Keyword Options:
        image:
            The url of the image to be used as the icon on the map defaults
            to 'G_DEFAULT_ICON'

        iconsize:
            a tuple representing the pixel size of the foreground (not the
            shadow) image of the icon, in the format: (width, height) ex.:

            GIcon('fast_food',
                  image="/media/icon/star.png",
                  iconsize=(15,10))

            Would indicate your custom icon was 15px wide and 10px height.

        shadow:
            the url of the image of the icon's shadow

        shadowsize:
            a tuple representing the pixel size of the shadow image, format is
            the same as ``iconsize``

        iconanchor:
            a tuple representing the pixel coordinate relative to the top left
            corner of the icon image at which this icon is anchored to the map.
            In (x, y) format.  x increases to the right in the Google Maps
            coordinate system and y increases downwards in the Google Maps
            coordinate system.)

        infowindowanchor:
            The pixel coordinate relative to the top left corner of the icon
            image at which the info window is anchored to this icon.

    c         C   sC   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   varnamet   imaget   iconsizet   shadowt
   shadowsizet
   iconanchort   infowindowanchor(   R   R6   R7   R8   R9   R:   R;   R<   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR   æ   s    						c         C   s   |  j  | j  k S(   N(   R6   (   R   t   other(    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyt   __eq__ñ   s    c         C   s   |  j  | j  k  S(   N(   R6   (   R   R=   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyt   __lt__ô   s    c         C   s   t  |  j ƒ t  |  j ƒ AS(   N(   t   hashR   R6   (   R   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyt   __hash__÷   s    N(   R   R   R   t   NoneR   R>   R?   RA   (    (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR5   ¯   s   6				t   GMarkerc           B   sA   e  Z d  Z d e d d „ Z d „  Z d „  Z e d „  ƒ Z	 RS(   s¯  
    A Python wrapper for the Google GMarker object.  For more information
    please see the Google Maps API Reference:
     http://code.google.com/apis/maps/documentation/reference.html#GMarker

    Example:

      from django.shortcuts import render_to_response
      from django.contrib.gis.maps.google.overlays import GMarker, GEvent

      def sample_request(request):
          marker = GMarker('POINT(101 26)')
          event = GEvent('click',
                         'function() { location.href = "http://www.google.com"}')
          marker.add_event(event)
          return render_to_response('mytemplate.html',
                 {'google' : GoogleMap(markers=[marker])})
    c         C   s¶   t  | t j ƒ r! t | ƒ } n  t  | t t f ƒ rE t | ƒ } n  t  | t ƒ rl |  j | j ƒ |  _	 n t
 d ƒ ‚ | j |  _ | |  _ | |  _ | |  _ t t |  ƒ j ƒ  d S(   s¤  
        The GMarker object may initialize on GEOS Points or a parameter
        that may be instantiated into a GEOS point.  Keyword options map to
        GMarkerOptions -- so far only the title option is supported.

        Keyword Options:
         title:
           Title option for GMarker, will be displayed as a tooltip.

         draggable:
           Draggable option for GMarker, disabled by default.
        s3   GMarker may only initialize on GEOS Point geometry.N(   R   R   R    R    R!   R"   R   R   R   t   latlngR#   R$   t   titlet	   draggablet   iconR,   RC   R   (   R   R4   RE   RF   RG   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR     s      			c         C   s   d | d | d f S(   Ns   new GLatLng(%s,%s)i   i    (    (   R   R   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR   +  s    c         C   ss   g  } |  j  r& | j d |  j  ƒ n  |  j rI | j d |  j j ƒ n  |  j rb | j d ƒ n  d d j | ƒ S(   Ns   title: "%s"s   icon: %ss   draggable: trues   {%s}R   (   RE   R   RG   R6   RF   R   (   R   t   result(    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyt   options.  s    	 	 	 c         C   s   d |  j  |  j ƒ  f S(   Ns   %s, %s(   RD   RI   (   R   (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyR   5  s    N(
   R   R   R   RB   t   FalseR   R   RI   R.   R   (    (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyRC   ü   s
   		N(   t   django.contrib.gis.geosR    R   R   R   R   t   django.utils.functionalR   t   django.utils.safestringR   t   django.utilsR   t   django.utils.encodingR   t   objectR	   R   R   R/   R5   RC   (    (    (    s@   ../Django//lib/python/django/contrib/gis/maps/google/overlays.pyt   <module>   s   (09,L