Ticket #9204: global_iconvars_gicon_patch.diff
File global_iconvars_gicon_patch.diff, 8.4 KB (added by , 16 years ago) |
---|
-
templates/gis/google/google-base.js
1 {% block vars %}var geodjango = {};{% endblock %} 1 {% block vars %}var geodjango = {};{% for icon in icons %} 2 var {{ icon.name }}_icon = new GIcon(G_DEFAULT_ICON); 3 {% if icon.image %}{{ icon.name }}_icon.image = "{{ icon.image }}";{% endif %} 4 {% if icon.shadow %}{{ icon.name }}_icon.shadow = "{{ icon.shadow }}";{% endif %} 5 {% if icon.iconsize %}{{ icon.name }}_icon.iconSize = new GSize({{ icon.iconsize.0 }}, {{ icon.iconsize.1 }});{% endif %} 6 {% if icon.shadowsize %}{{ icon.name }}_icon.shadowSize = new GSize({{ icon.shadowsize.0 }}, {{ icon.shadowsize.1 }});{% endif %} 7 {% if icon.iconanchor %}{{ icon.name }}_icon.iconAnchor = new GPoint({{ icon.iconanchor.0 }}, {{ icon.iconanchor.1 }});{% endif %} 8 {% if icon.infowindowanchor %}{{ icon.name }}_icon.infoWindowAnchor = new GPoint({{ icon.infowindowanchor.0 }}, {{ icon.infowindowanchor.1 }});{% endif %}{% endfor %}{% endblock %} 2 9 {% block functions %}{% endblock %} 10 No newline at end of file -
maps/google/gmap.py
4 4 from django.utils.safestring import mark_safe 5 5 6 6 class GoogleMapException(Exception): pass 7 from django.contrib.gis.maps.google.overlays import GPolygon, GPolyline, GMarker 8 7 from django.contrib.gis.maps.google.overlays import GPolygon, GPolyline, \ 8 GMarker, GIcon 9 9 10 # The default Google Maps URL (for the API javascript) 10 11 # TODO: Internationalize for Japan, UK, etc. 11 12 GOOGLE_MAPS_URL='http://maps.google.com/maps?file=api&v=%s&key=' … … 20 21 21 22 def __init__(self, key=None, api_url=None, version=None, 22 23 center=None, zoom=None, dom_id='map', 23 kml_urls=[], polygons=[], polylines=[], markers=[],24 template='gis/google/google-single.js',24 kml_urls=[], icons=None, markers=None, polylines=None, 25 polygons=None, template='gis/google/google-single.js', 25 26 js_module='geodjango',extra_context={}): 26 27 27 28 # The Google Maps API Key defined in the settings will be used … … 57 58 self.kml_urls = kml_urls 58 59 59 60 # Does the user want any GMarker, GPolygon, and/or GPolyline overlays? 60 self.polygons, self.polylines, self.markers = [], [], [] 61 if markers: 62 for point in markers: 63 if isinstance(point, GMarker): 64 self.markers.append(point) 65 else: 66 self.markers.append(GMarker(point)) 67 if polygons: 68 for poly in polygons: 69 if isinstance(poly, GPolygon): 70 self.polygons.append(poly) 71 else: 72 self.polygons.append(GPolygon(poly)) 73 if polylines: 74 for pline in polylines: 75 if isinstance(pline, GPolyline): 76 self.polylines.append(pline) 77 else: 78 self.polylines.append(GPolyline(pline)) 79 61 overlay_info = [[GIcon, icons, 'icons'], 62 [GMarker, markers, 'markers'], 63 [GPolygon, polygons, 'polygons'], 64 [GPolyline, polylines, 'polylines']] 65 66 for overlay_class, overlay_list, varname in overlay_info: 67 setattr(self, varname, []) 68 if overlay_list: 69 for overlay in overlay_list: 70 if isinstance(overlay, overlay_class): 71 getattr(self, varname).append(overlay) 72 else: 73 getattr(self, varname).append(overlay_class(overlay)) 74 80 75 # If GMarker, GPolygons, and/or GPolylines are used the zoom will be 81 76 # automatically calculated via the Google Maps API. If both a zoom 82 77 # level and a center coordinate are provided with polygons/polylines, … … 105 100 'zoom' : self.zoom, 106 101 'polygons' : self.polygons, 107 102 'polylines' : self.polylines, 103 'icons': self.icons, 108 104 'markers' : self.markers, 109 105 } 110 106 params.update(self.extra_context) -
maps/google/overlays.py
165 165 def js_params(self): 166 166 return '%s, "%s", %s, %s' % (self.latlngs, self.color, self.weight, self.opacity) 167 167 168 169 class GIcon(object): 170 """ 171 Creates a GIcon object to pass into a Gmarker object. 172 173 The keyword arguments map to instance attributes of the same name. These, 174 in turn, correspond to a subset of the attributes of the official GIcon 175 javascript object: 176 177 http://code.google.com/apis/maps/documentation/reference.html#GIcon 178 179 Because a Google map often uses several different icons, a name field has 180 been added to the required arguments. 181 182 Required Arguments: 183 name: 184 A string which will become the basis for the js variable name of 185 the marker, for this reason, your code should assign a unique 186 name for each GIcon you instantiate, otherwise there will be 187 name space collisions in your javascript. 188 189 Keyword Options: 190 image: 191 The url of the image to be used as the icon on the map defaults 192 to 'G_DEFAULT_ICON' 193 194 iconsize: 195 a tuple representing the pixel size of the foreground (not the 196 shadow) image of the icon, in the format: (width, height) ex.: 197 198 GIcon('fast_food', 199 image="/media/icon/star.png", 200 iconsize=(15,10)) 201 202 Would indicate your custom icon was 15px wide and 10px height. 203 204 shadow: 205 the url of the image of the icon's shadow 206 207 shadowsize: 208 a tuple representing the pixel size of the shadow image, format is 209 the same as ``iconsize`` 210 211 iconanchor: 212 a tuple representing the pixel coordinate relative to the top left 213 corner of the icon image at which this icon is anchored to the map. 214 In (x, y) format. x increases to the right in the Google Maps 215 coordinate system and y increases downwards in the Google Maps 216 coordinate system.) 217 218 infowindowanchor: 219 The pixel coordinate relative to the top left corner of the icon 220 image at which the info window is anchored to this icon. 221 222 """ 223 def __init__(self, name, image='G_DEFAULT_ICON', iconsize=None, 224 shadow=None, shadowsize=None, iconanchor=None, 225 infowindowanchor=None): 226 self.name = name 227 self.image = image 228 self.iconsize = iconsize 229 self.shadow = shadow 230 self.shadowsize = shadowsize 231 self.iconanchor = iconanchor 232 self.infowindowanchor = infowindowanchor 233 234 168 235 class GMarker(GOverlayBase): 169 236 """ 170 237 A Python wrapper for the Google GMarker object. For more information … … 184 251 return render_to_response('mytemplate.html', 185 252 {'google' : GoogleMap(markers=[marker])}) 186 253 """ 187 def __init__(self, geom, title=None, draggable=False ):254 def __init__(self, geom, title=None, draggable=False, icon=None): 188 255 """ 189 256 The GMarker object may initialize on GEOS Points or a parameter 190 257 that may be instantiated into a GEOS point. Keyword options map to … … 209 276 # TODO: Add support for more GMarkerOptions 210 277 self.title = title 211 278 self.draggable = draggable 279 self.icon = icon 212 280 super(GMarker, self).__init__() 213 281 214 282 def latlng_from_coords(self, coords): … … 217 285 def options(self): 218 286 result = [] 219 287 if self.title: result.append('title: "%s"' % self.title) 288 if self.icon: result.append('icon: %s_icon' % self.icon.name) 220 289 if self.draggable: result.append('draggable: true') 221 290 return '{%s}' % ','.join(result) 291 222 292 223 293 @property 224 294 def js_params(self):