Ticket #11458: overlays.diff
File overlays.diff, 5.2 KB (added by , 15 years ago) |
---|
-
django/contrib/gis/maps/google/overlays.py
65 65 "The string representation is the JavaScript API call." 66 66 return mark_safe('%s(%s)' % (self.__class__.__name__, self.js_params)) 67 67 68 69 class 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 68 88 class GPolygon(GOverlayBase): 69 89 """ 70 90 A Python wrapper for the Google GPolygon object. For more information … … 73 93 """ 74 94 def __init__(self, poly, 75 95 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()): 77 97 """ 78 98 The GPolygon object initializes on a GEOS Polygon or a parameter that 79 99 may be instantiated into GEOS Polygon. Please note that this will not … … 95 115 96 116 fill_opacity: 97 117 The opacity of the polygon fill. Defaults to 0.4. 118 119 options: 120 GPolygonOptions (clickable, mouseOutTolerance) for the polygon. 121 98 122 """ 99 123 if isinstance(poly, basestring): poly = fromstr(poly) 100 124 if isinstance(poly, (tuple, list)): poly = Polygon(poly) … … 115 139 # Fill settings. 116 140 self.fill_color, self.fill_opacity = fill_color, fill_opacity 117 141 142 # Options settings. 143 self.options = options 144 118 145 super(GPolygon, self).__init__() 119 146 120 147 @property 121 148 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) 124 150 151 152 class 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 125 174 class GPolyline(GOverlayBase): 126 175 """ 127 176 A Python wrapper for the Google GPolyline object. For more information 128 177 please see the Google Maps API Reference: 129 178 http://code.google.com/apis/maps/documentation/reference.html#GPolyline 130 179 """ 131 def __init__(self, geom, color='#0000ff', weight=2, opacity=1 ):180 def __init__(self, geom, color='#0000ff', weight=2, opacity=1, options=GPolylineOptions()): 132 181 """ 133 182 The GPolyline object may be initialized on GEOS LineStirng, LinearRing, 134 183 and Polygon objects (internal rings not supported) or a parameter that … … 144 193 145 194 opacity: 146 195 The opacity of the polyline, between 0 and 1. Defaults to 1. 196 197 options: 198 GPolylineOptions (clickable, mouseOutTolerance) for the polygon. 147 199 """ 148 200 # If a GEOS geometry isn't passed in, try to contsruct one. 149 201 if isinstance(geom, basestring): geom = fromstr(geom) … … 158 210 159 211 # Getting the envelope for automatic zoom determination. 160 212 self.envelope = geom.envelope 161 self.color, self.weight, self.opacity = color, weight, opacity213 self.color, self.weight, self.opacity, self.options = color, weight, opacity, options 162 214 super(GPolyline, self).__init__() 163 215 164 216 @property 165 217 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) 167 219 168 220 169 221 class GIcon(object):