Ticket #11458: overlays.diff

File overlays.diff, 5.2 KB (added by Thomas Achtemichuk, 15 years ago)

Patch adding GPolygonOptions and GPolylineOptions

  • django/contrib/gis/maps/google/overlays.py

     
    6565        "The string representation is the JavaScript API call."
    6666        return mark_safe('%s(%s)' % (self.__class__.__name__, self.js_params))
    6767
     68
     69class GPolygonOptions(object):
     70    """
     71    A Python wrapper for the Google GPolygonOptions object. For more information
     72    please see the Google Maps API Reference:
     73    http://code.google.com/apis/maps/documentation/reference.html#GPolygonOptions
     74    """
     75    def __init__(self, clickable=None, mouseout_tolerance=None):
     76        self.clickable = clickable
     77        self.mouseout_tolerance = mouseout_tolerance
     78
     79    def __str__(self):
     80        options = []
     81        if isinstance(self.clickable, bool):
     82            options.append('clickable: %s' % (str(self.clickable).lower()))
     83        if isinstance(self.mouseout_tolerance, int):
     84            options.append('mouseOutTolerance: %d' % (self.mouseout_tolerance))
     85        return mark_safe('{' + ','.join(options) + '}')
     86
     87
    6888class GPolygon(GOverlayBase):
    6989    """
    7090    A Python wrapper for the Google GPolygon object.  For more information
     
    7393    """
    7494    def __init__(self, poly,
    7595                 stroke_color='#0000ff', stroke_weight=2, stroke_opacity=1,
    76                  fill_color='#0000ff', fill_opacity=0.4):
     96                 fill_color='#0000ff', fill_opacity=0.4, options=GPolygonOptions()):
    7797        """
    7898        The GPolygon object initializes on a GEOS Polygon or a parameter that
    7999        may be instantiated into GEOS Polygon.  Please note that this will not
     
    95115
    96116          fill_opacity:
    97117            The opacity of the polygon fill.  Defaults to 0.4.
     118
     119          options:
     120            GPolygonOptions (clickable, mouseOutTolerance) for the polygon.
     121
    98122        """
    99123        if isinstance(poly, basestring): poly = fromstr(poly)
    100124        if isinstance(poly, (tuple, list)): poly = Polygon(poly)
     
    115139        # Fill settings.
    116140        self.fill_color, self.fill_opacity = fill_color, fill_opacity
    117141
     142        # Options settings.
     143        self.options = options
     144
    118145        super(GPolygon, self).__init__()
    119146
    120147    @property
    121148    def js_params(self):
    122         return '%s, "%s", %s, %s, "%s", %s' % (self.points, self.stroke_color, self.stroke_weight, self.stroke_opacity,
    123                                                self.fill_color, self.fill_opacity)
     149        return '%s, "%s", %s, %s, "%s", %s, %s' % (self.points, self.stroke_color, self.stroke_weight, self.stroke_opacity, self.fill_color, self.fill_opacity, self.options)
    124150
     151
     152class GPolylineOptions(object):
     153    """
     154    A Python wrapper for the Google GPolylineOptions object. For more information
     155    please see the Google Maps API Reference:
     156    http://code.google.com/apis/maps/documentation/reference.html#GPolylineOptions
     157    """
     158    def __init__(self, clickable=None, geodesic=None, mouseout_tolerance=None):
     159        self.clickable = clickable
     160        self.geodesic = geodesic
     161        self.mouseout_tolerance = mouseout_tolerance
     162
     163    def __str__(self):
     164        options = []
     165        if isinstance(self.clickable, bool):
     166            options.append('clickable: %s' % (str(self.clickable).lower()))
     167        if isinstance(self.geodesic, bool):
     168            options.append('clickable: %s' % (str(self.geodesic).lower()))
     169        if isinstance(self.mouseout_tolerance, int):
     170            options.append('mouseOutTolerance: %d' % (self.mouseout_tolerance))
     171        return mark_safe('{' + ','.join(options) + '}')
     172
     173
    125174class GPolyline(GOverlayBase):
    126175    """
    127176    A Python wrapper for the Google GPolyline object.  For more information
    128177    please see the Google Maps API Reference:
    129178     http://code.google.com/apis/maps/documentation/reference.html#GPolyline
    130179    """
    131     def __init__(self, geom, color='#0000ff', weight=2, opacity=1):
     180    def __init__(self, geom, color='#0000ff', weight=2, opacity=1, options=GPolylineOptions()):
    132181        """
    133182        The GPolyline object may be initialized on GEOS LineStirng, LinearRing,
    134183        and Polygon objects (internal rings not supported) or a parameter that
     
    144193
    145194          opacity:
    146195            The opacity of the polyline, between 0 and 1.  Defaults to 1.
     196
     197          options:
     198            GPolylineOptions (clickable, mouseOutTolerance) for the polygon.
    147199        """
    148200        # If a GEOS geometry isn't passed in, try to contsruct one.
    149201        if isinstance(geom, basestring): geom = fromstr(geom)
     
    158210
    159211        # Getting the envelope for automatic zoom determination.
    160212        self.envelope = geom.envelope
    161         self.color, self.weight, self.opacity = color, weight, opacity
     213        self.color, self.weight, self.opacity, self.options = color, weight, opacity, options
    162214        super(GPolyline, self).__init__()
    163215
    164216    @property
    165217    def js_params(self):
    166         return '%s, "%s", %s, %s' % (self.latlngs, self.color, self.weight, self.opacity)
     218        return '%s, "%s", %s, %s, %s' % (self.latlngs, self.color, self.weight, self.opacity, self.options)
    167219
    168220
    169221class GIcon(object):
Back to Top