Ticket #9204: icons_and_draggable.diff
File icons_and_draggable.diff, 5.8 KB (added by , 16 years ago) |
---|
-
templates/gis/google/js/google-map.js
20 20 {% for event in polyline.events %}GEvent.addListener(polyline{{ forloop.parentloop.counter }}, {{ event }}); {% endfor %} 21 21 {% if calc_zoom %}tmp_bounds = polyline{{ forloop.counter }}.getBounds(); bounds.extend(tmp_bounds.getSouthWest()); bounds.extend(tmp_bounds.getNorthEast());{% endif %}{% endfor %} 22 22 23 {% for icon in icons %} 24 var {{ icon.name }}_icon = new GIcon(G_DEFAULT_ICON); 25 {% if icon.image %}{{ icon.name }}_icon.image = "{{ icon.image }}";{% endif %} 26 {% if icon.shadow %}{{ icon.name }}_icon.shadow = "{{ icon.shadow }}";{% endif %} 27 {% if icon.iconsize %}{{ icon.name }}_icon.iconSize = new GSize({{ icon.iconsize }});{% endif %} 28 {% if icon.shadowsize %}{{ icon.name }}_icon.shadowSize = new GSize({{ icon.shadowsize }});{% endif %} 29 {% if icon.iconanchor %}{{ icon.name }}_icon.iconAnchor = new GPoint({{ icon.iconanchor }});{% endif %} 30 {% if icon.infowindowanchor %}{{ icon.name }}_icon.infoWindowAnchor = new GPoint({{ icon.infowindowanchor }});{% endif %}{% endfor %} 31 23 32 {% for marker in markers %}var marker{{ forloop.counter }} = new {{ marker }}; 24 33 map.addOverlay(marker{{ forloop.counter }}); 25 34 {% for event in marker.events %}GEvent.addListener(marker{{ forloop.parentloop.counter }}, {{ event }}); {% endfor %} -
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 7 from django.contrib.gis.maps.google.overlays import GPolygon, GPolyline, \ 8 GMarker, GIcon 8 9 9 10 # The default Google Maps URL (for the API javascript) 10 11 # TODO: Internationalize for Japan, UK, etc. … … 20 21 21 22 def __init__(self, key=None, api_url=None, version=None, 22 23 center=None, zoom=None, dom_id='map', load_func='gmap_load', 23 kml_urls=[], polygons=[], polylines=[], markers=[], 24 kml_urls=[], polygons=[], polylines=[], markers=[], icons=[], 24 25 template='gis/google/js/google-map.js', 25 26 extra_context={}): 26 27 … … 56 57 self.kml_urls = kml_urls 57 58 58 59 # Does the user want any GMarker, GPolygon, and/or GPolyline overlays? 59 self.polygons, self.polylines, self.markers = [], [], [] 60 self.polygons, self.polylines, self.markers, self.icons = [], [], [], [] 61 if icons: 62 for icon in icons: 63 if isinstance(icon, GIcon): 64 self.icons.append(icon) 65 else: 66 self.icons.append(GIcon(icon)) 60 67 if markers: 61 68 for point in markers: 62 69 if isinstance(point, GMarker): … … 103 110 'polygons' : self.polygons, 104 111 'polylines' : self.polylines, 105 112 'markers' : self.markers, 113 'icons' : self.icons, 106 114 } 107 115 params.update(extra_context) 108 116 self.js = render_to_string(self.template, params) -
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 class GIcon(object): 169 """ 170 Creates a GIcon object to pass into a Gmarker object. 171 """ 172 def __init__(self, name='custom', image=None, iconsize=None, shadow=None, shadowsize=None, 173 iconanchor=None, infowindowanchor=None): 174 self.name = name 175 self.image = image 176 self.iconsize = iconsize 177 self.shadow = shadow 178 self.shadowsize = shadowsize 179 self.iconanchor = iconanchor 180 self.infowindowanchor = infowindowanchor 181 182 168 183 class GMarker(GOverlayBase): 169 184 """ 170 185 A Python wrapper for the Google GMarker object. For more information … … 184 199 return render_to_response('mytemplate.html', 185 200 {'google' : GoogleMap(markers=[marker])}) 186 201 """ 187 def __init__(self, geom, title=None ):202 def __init__(self, geom, title=None, draggable=False, icon=None): 188 203 """ 189 204 The GMarker object may initialize on GEOS Points or a parameter 190 205 that may be instantiated into a GEOS point. Keyword options map to … … 193 208 Keyword Options: 194 209 title: 195 210 Title option for GMarker, will be displayed as a tooltip. 211 212 draggable: 213 Draggable option for GMarker, disabled by default 214 215 icon: 216 Takes a 196 217 """ 197 218 # If a GEOS geometry isn't passed in, try to construct one. 198 219 if isinstance(geom, basestring): geom = fromstr(geom) … … 205 226 self.envelope = geom.envelope 206 227 # TODO: Add support for more GMarkerOptions 207 228 self.title = title 229 self.draggable = draggable 230 self.icon = icon 208 231 super(GMarker, self).__init__() 209 232 210 233 def latlng_from_coords(self, coords): … … 212 235 213 236 def options(self): 214 237 result = [] 215 if self.title: result.append('title: "%s"' % self.title) 238 if self.title: result.append('title: "%s"' % self.title) 239 if self.icon: result.append('icon: %s_icon' % self.icon.name) 240 if self.draggable: result.append('draggable: true') 216 241 return '{%s}' % ','.join(result) 217 242 218 243 @property