Index: maps/google/__init__.py =================================================================== --- maps/google/__init__.py (revision 11246) +++ maps/google/__init__.py (working copy) @@ -57,5 +57,6 @@ version. """ from django.contrib.gis.maps.google.gmap import GoogleMap, GoogleMapSet -from django.contrib.gis.maps.google.overlays import GEvent, GIcon, GMarker, GPolygon, GPolyline +from django.contrib.gis.maps.google.events import GEvent +from django.contrib.gis.maps.google.overlays import GIcon, GMarker, GPolygon, GPolyline from django.contrib.gis.maps.google.zoom import GoogleZoom Index: maps/google/events.py =================================================================== --- maps/google/events.py (revision 0) +++ maps/google/events.py (revision 0) @@ -0,0 +1,49 @@ +from django.utils.safestring import mark_safe + +class GEvent(object): + """ + 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: + http://code.google.com/apis/maps/documentation/reference.html#GEvent + + Example: + + from django.shortcuts import render_to_response + 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_to_response('mytemplate.html', + {'google' : GoogleMap(polylines=[polyline])}) + """ + + def __init__(self, event, action): + """ + 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. + """ + self.event = event + self.action = action + + def __unicode__(self): + "Returns the parameter part of a GEvent." + return mark_safe('"%s", %s' %(self.event, self.action)) \ No newline at end of file Index: maps/google/gmap.py =================================================================== --- maps/google/gmap.py (revision 11246) +++ maps/google/gmap.py (working copy) @@ -23,8 +23,11 @@ kml_urls=[], polylines=None, polygons=None, markers=None, template='gis/google/google-map.js', js_module='geodjango', + events = [], extra_context={}): + self.events = events + # The Google Maps API Key defined in the settings will be used # if not passed in as a parameter. The use of an API key is # _required_. @@ -101,6 +104,7 @@ 'polylines' : self.polylines, 'icons': self.icons, 'markers' : self.markers, + 'events' : self.events, } params.update(self.extra_context) return render_to_string(self.template, params) @@ -144,6 +148,10 @@ def icons(self): "Returns a sequence of GIcon objects in this map." return set([marker.icon for marker in self.markers if marker.icon]) + + def add_event(self, event): + "Attaches a GEvent to the map object." + self.events.append(event) class GoogleMapSet(GoogleMap): Index: maps/google/overlays.py =================================================================== --- maps/google/overlays.py (revision 11246) +++ maps/google/overlays.py (working copy) @@ -1,54 +1,6 @@ from django.utils.safestring import mark_safe from django.contrib.gis.geos import fromstr, Point, LineString, LinearRing, Polygon -class GEvent(object): - """ - 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: - http://code.google.com/apis/maps/documentation/reference.html#GEvent - - Example: - - from django.shortcuts import render_to_response - 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_to_response('mytemplate.html', - {'google' : GoogleMap(polylines=[polyline])}) - """ - - def __init__(self, event, action): - """ - 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. - """ - self.event = event - self.action = action - - def __unicode__(self): - "Returns the parameter part of a GEvent." - return mark_safe('"%s", %s' %(self.event, self.action)) - class GOverlayBase(object): def __init__(self): self.events = [] Index: templates/gis/google/google-map.js =================================================================== --- templates/gis/google/google-map.js (revision 11246) +++ templates/gis/google/google-map.js (working copy) @@ -10,6 +10,7 @@ if (GBrowserIsCompatible()) { {{ js_module }}.{{ dom_id }} = new GMap2(document.getElementById("{{ dom_id }}")); {{ js_module }}.{{ dom_id }}.setCenter(new GLatLng({{ center.1 }}, {{ center.0 }}), {{ zoom }}); + {% for event in events %}GEvent.addListener({{ js_module }}.{{ dom_id }}, {{ event }});{% endfor %} {% block controls %}{{ js_module }}.{{ dom_id }}.setUIToDefault();{% endblock %} {% if calc_zoom %}var bounds = new GLatLngBounds(); var tmp_bounds = new GLatLngBounds();{% endif %} {% for kml_url in kml_urls %}{{ js_module }}.{{ dom_id }}_kml{{ forloop.counter }} = new GGeoXml("{{ kml_url }}");