3
(h.                 @   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G dd deZeeG d	d
 d
eZG dd deZG dd deZeG dd deZG d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   K/tmp/pip-install-q3hcpn_q/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                   s.   e Zd ZdZd
 fdd	Zedd	 Z  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
    #0000ff      皙?c                s   t |tjrt|}t |ttfr*t|}t |ts<td|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   polyr3   r5   r4   r6   r7   )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)r2   r3   r5   r4   r6   r7   )r   r   r   r   r%      s    zGPolygon.js_params)r'   r(   r)   r'   r*   )r   r   r   r   r   propertyr%   __classcell__r   r   )r$   r   r&   T   s    .r&   c                   s.   e Zd ZdZd	 fdd	Zedd Z  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
    #0000ffr(   r)   c                s   t |tjrt|}t |ttfr*t|}t |ttfrH| j	|j
| _n$t |trd| 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    latlngsr1   r/   r0   colorweightopacityr8   r<   r   )r   geomr?   r@   rA   )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@   rA   )r   r   r   r   r%      s    zGPolyline.js_params)r=   r(   r)   )r   r   r   r   r   r:   r%   r;   r   r   )r$   r   r<      s   #r<   c               @   s2   e Zd ZdZ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   s.   || _ || _|| _|| _|| _|| _|| _d S )N)varnameimageiconsizeshadow
shadowsize
iconanchorinfowindowanchor)r   rD   rE   rF   rG   rH   rI   rJ   r   r   r   r      s    zGIcon.__init__c             C   s   | j |j kS )N)rD   )r   otherr   r   r   __eq__   s    zGIcon.__eq__c             C   s   | j |j k S )N)rD   )r   rK   r   r   r   __lt__  s    zGIcon.__lt__c             C   s   t | jt | jA S )N)hashr$   rD   )r   r   r   r   __hash__  s    zGIcon.__hash__)NNNNNN)r   r   r   r   r   rL   rM   rO   r   r   r   r   rC      s   5  
	rC   c                   s>   e Zd ZdZd fdd	Zdd Zdd	 Zed
d Z  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                sx   t |tjrt|}t |ttfr*t|}t |trD| 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/   r0   title	draggableiconr8   rP   r   )r   rB   rR   rS   rT   )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   sP   g }| j r|jd| j   | jr2|jd| jj  | jrB|jd ddj| S )Nztitle: "%s"zicon: %szdraggable: truez{%s}r   )rR   r"   rT   rD   rS   r   )r   resultr   r   r   options@  s    
zGMarker.optionsc             C   s   d| j | j f S )Nz%s, %s)rQ   rV   )r   r   r   r   r%   J  s    zGMarker.js_params)NFN)
r   r   r   r   r   r!   rV   r:   r%   r;   r   r   )r$   r   rP     s
   
rP   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&   r<   rC   rP   r   r   r   r   <module>   s    
2
<.L