
 X.                 @   s  d  d l  m Z d  d l m Z 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 e e Gd d   d e    Z e e Gd	 d
   d
 e    Z Gd d   d e  Z Gd d   d e  Z e Gd d   d e   Z Gd d   d e  Z d S)    )unicode_literals)total_ordering)
LinearRing
LineStringPointPolygonfromstr)six)python_2_unicode_compatible)	html_safec               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)GEventa'  
    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:
     https://developers.google.com/maps/documentation/javascript/reference#event

    Example:

      from django.shortcuts import render
      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(request, 'mytemplate.html', {
              'google': GoogleMap(polylines=[polyline]),
          })
    c             C   s   | |  _  | |  _ d S)a  
        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)eventaction)selfr   r    r   U/home/ubuntu/projects/ifolica/build/django/django/contrib/gis/maps/google/overlays.py__init__(   s    	zGEvent.__init__c             C   s   d |  j  |  j f S)z'Returns the parameter part of a GEvent.z"%s", %s)r   r   )r   r   r   r   __str__<   s    zGEvent.__str__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s   r   c               @   s@   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 S)
GOverlayBasec             C   s   g  |  _  d  S)N)events)r   r   r   r   r   D   s    zGOverlayBase.__init__c             C   s   d d j  d d   | D  S)zJGenerates a JavaScript array of GLatLng objects for the given coordinates.z[%s],c             s   s%   |  ] \ } } d  | | f Vq d S)znew GLatLng(%s,%s)Nr   ).0xyr   r   r   	<genexpr>I   s    z2GOverlayBase.latlng_from_coords.<locals>.<genexpr>)join)r   coordsr   r   r   latlng_from_coordsG   s    zGOverlayBase.latlng_from_coordsc             C   s   |  j  j |  d S)z(Attaches a GEvent to the overlay object.N)r   append)r   r   r   r   r   	add_eventK   s    zGOverlayBase.add_eventc             C   s   d |  j  j |  j f S)z5The string representation is the JavaScript API call.z%s(%s))	__class__r   	js_params)r   r   r   r   r   O   s    zGOverlayBase.__str__N)r   r   r   r   r!   r#   r   r   r   r   r   r   A   s   r   c                   sI   e  Z d  Z d Z d d d d d   f d d  Z e d d	    Z   S)
GPolygonz
    A Python wrapper for the Google GPolygon object.  For more information
    please see the Google Maps API Reference:
     https://developers.google.com/maps/documentation/javascript/reference#Polygon
    z#0000ff      g?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)a  
        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.
        z.GPolygon may only initialize on GEOS Polygons.N)
isinstancer	   string_typesr   tuplelistr   	TypeErrorenveloper!   shellr    pointsstroke_colorstroke_opacitystroke_weight
fill_colorfill_opacitysuperr&   r   )r   polyr1   r3   r2   r4   r5   )r$   r   r   r   Z   s    zGPolygon.__init__c             C   s,   d |  j  |  j |  j |  j |  j |  j f S)Nz%s, "%s", %s, %s, "%s", %s)r0   r1   r3   r2   r4   r5   )r   r   r   r   r%      s    zGPolygon.js_params)r   r   r   r   r   propertyr%   r   r   )r$   r   r&   T   s   	.r&   c                   sC   e  Z d  Z d Z d d d   f d d  Z e d d    Z   S)		GPolylinez
    A Python wrapper for the Google GPolyline object.  For more information
    please see the Google Maps API Reference:
     https://developers.google.com/maps/documentation/javascript/reference#Polyline
    z#0000ffr'   r(   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)a  
        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.
        zXGPolyline may only initialize on GEOS LineString, LinearRing, and/or Polygon geometries.N)r)   r	   r*   r   r+   r,   r   r   r   r!   r    latlngsr/   r-   r.   colorweightopacityr6   r9   r   )r   geomr;   r<   r=   )r$   r   r   r      s    zGPolyline.__init__c             C   s    d |  j  |  j |  j |  j f S)Nz%s, "%s", %s, %s)r:   r;   r<   r=   )r   r   r   r   r%      s    zGPolyline.js_params)r   r   r   r   r   r8   r%   r   r   )r$   r   r9      s   #r9   c               @   sX   e  Z d  Z d Z d d d d d d d d  Z d d   Z d d   Z d	 d
   Z d S)GIcona  
    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:

    https://developers.google.com/maps/documentation/javascript/reference#Icon

    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.
    Nc             C   sC   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S)N)varnameimageiconsizeshadow
shadowsize
iconanchorinfowindowanchor)r   r@   rA   rB   rC   rD   rE   rF   r   r   r   r      s    						zGIcon.__init__c             C   s   |  j  | j  k S)N)r@   )r   otherr   r   r   __eq__   s    zGIcon.__eq__c             C   s   |  j  | j  k  S)N)r@   )r   rG   r   r   r   __lt__  s    zGIcon.__lt__c             C   s   t  |  j  t  |  j  AS)N)hashr$   r@   )r   r   r   r   __hash__  s    zGIcon.__hash__)r   r   r   r   r   rH   rI   rK   r   r   r   r   r?      s   5		r?   c                   s[   e  Z d  Z d Z d d d   f d d  Z d d   Z d d	   Z e d
 d    Z   S)GMarkera  
    A Python wrapper for the Google GMarker object.  For more information
    please see the Google Maps API Reference:
     https://developers.google.com/maps/documentation/javascript/reference#Marker

    Example:

      from django.shortcuts import render
      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(request, 'mytemplate.html', {
              'google': GoogleMap(markers=[marker]),
          })
    NFc                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)a  
        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.
        z3GMarker may only initialize on GEOS Point geometry.N)r)   r	   r*   r   r+   r,   r   r!   r    latlngr-   r.   title	draggableiconr6   rL   r   )r   r>   rN   rO   rP   )r$   r   r   r     s    			zGMarker.__init__c             C   s   d | d | d f S)Nznew GLatLng(%s,%s)r(   r   r   )r   r    r   r   r   r!   =  s    zGMarker.latlng_from_coordsc             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)Nztitle: "%s"zicon: %szdraggable: truez{%s}r   )rN   r"   rP   r@   rO   r   )r   resultr   r   r   options@  s    			zGMarker.optionsc             C   s   d |  j  |  j   f S)Nz%s, %s)rM   rR   )r   r   r   r   r%   J  s    zGMarker.js_params)	r   r   r   r   r   r!   rR   r8   r%   r   r   )r$   r   rL     s
   
rL   N)
__future__r   	functoolsr   Zdjango.contrib.gis.geosr   r   r   r   r   Zdjango.utilsr	   Zdjango.utils.encodingr
   Zdjango.utils.htmlr   objectr   r   r&   r9   r?   rL   r   r   r   r   <module>   s    (2<.L