| 1 | Index: maps/google/__init__.py
|
|---|
| 2 | ===================================================================
|
|---|
| 3 | --- maps/google/__init__.py (revision 11246)
|
|---|
| 4 | +++ maps/google/__init__.py (working copy)
|
|---|
| 5 | @@ -57,5 +57,6 @@
|
|---|
| 6 | version.
|
|---|
| 7 | """
|
|---|
| 8 | from django.contrib.gis.maps.google.gmap import GoogleMap, GoogleMapSet
|
|---|
| 9 | -from django.contrib.gis.maps.google.overlays import GEvent, GIcon, GMarker, GPolygon, GPolyline
|
|---|
| 10 | +from django.contrib.gis.maps.google.events import GEvent
|
|---|
| 11 | +from django.contrib.gis.maps.google.overlays import GIcon, GMarker, GPolygon, GPolyline
|
|---|
| 12 | from django.contrib.gis.maps.google.zoom import GoogleZoom
|
|---|
| 13 | Index: maps/google/events.py
|
|---|
| 14 | ===================================================================
|
|---|
| 15 | --- maps/google/events.py (revision 0)
|
|---|
| 16 | +++ maps/google/events.py (revision 0)
|
|---|
| 17 | @@ -0,0 +1,49 @@
|
|---|
| 18 | +from django.utils.safestring import mark_safe
|
|---|
| 19 | +
|
|---|
| 20 | +class GEvent(object):
|
|---|
| 21 | + """
|
|---|
| 22 | + A Python wrapper for the Google GEvent object.
|
|---|
| 23 | +
|
|---|
| 24 | + Events can be attached to any object derived from GOverlayBase with the
|
|---|
| 25 | + add_event() call.
|
|---|
| 26 | +
|
|---|
| 27 | + For more information please see the Google Maps API Reference:
|
|---|
| 28 | + http://code.google.com/apis/maps/documentation/reference.html#GEvent
|
|---|
| 29 | +
|
|---|
| 30 | + Example:
|
|---|
| 31 | +
|
|---|
| 32 | + from django.shortcuts import render_to_response
|
|---|
| 33 | + from django.contrib.gis.maps.google import GoogleMap, GEvent, GPolyline
|
|---|
| 34 | +
|
|---|
| 35 | + def sample_request(request):
|
|---|
| 36 | + polyline = GPolyline('LINESTRING(101 26, 112 26, 102 31)')
|
|---|
| 37 | + event = GEvent('click',
|
|---|
| 38 | + 'function() { location.href = "http://www.google.com"}')
|
|---|
| 39 | + polyline.add_event(event)
|
|---|
| 40 | + return render_to_response('mytemplate.html',
|
|---|
| 41 | + {'google' : GoogleMap(polylines=[polyline])})
|
|---|
| 42 | + """
|
|---|
| 43 | +
|
|---|
| 44 | + def __init__(self, event, action):
|
|---|
| 45 | + """
|
|---|
| 46 | + Initializes a GEvent object.
|
|---|
| 47 | +
|
|---|
| 48 | + Parameters:
|
|---|
| 49 | +
|
|---|
| 50 | + event:
|
|---|
| 51 | + string for the event, such as 'click'. The event must be a valid
|
|---|
| 52 | + event for the object in the Google Maps API.
|
|---|
| 53 | + There is no validation of the event type within Django.
|
|---|
| 54 | +
|
|---|
| 55 | + action:
|
|---|
| 56 | + string containing a Javascript function, such as
|
|---|
| 57 | + 'function() { location.href = "newurl";}'
|
|---|
| 58 | + The string must be a valid Javascript function. Again there is no
|
|---|
| 59 | + validation fo the function within Django.
|
|---|
| 60 | + """
|
|---|
| 61 | + self.event = event
|
|---|
| 62 | + self.action = action
|
|---|
| 63 | +
|
|---|
| 64 | + def __unicode__(self):
|
|---|
| 65 | + "Returns the parameter part of a GEvent."
|
|---|
| 66 | + return mark_safe('"%s", %s' %(self.event, self.action))
|
|---|
| 67 | \ No newline at end of file
|
|---|
| 68 | Index: maps/google/gmap.py
|
|---|
| 69 | ===================================================================
|
|---|
| 70 | --- maps/google/gmap.py (revision 11246)
|
|---|
| 71 | +++ maps/google/gmap.py (working copy)
|
|---|
| 72 | @@ -23,8 +23,11 @@
|
|---|
| 73 | kml_urls=[], polylines=None, polygons=None, markers=None,
|
|---|
| 74 | template='gis/google/google-map.js',
|
|---|
| 75 | js_module='geodjango',
|
|---|
| 76 | + events = [],
|
|---|
| 77 | extra_context={}):
|
|---|
| 78 |
|
|---|
| 79 | + self.events = events
|
|---|
| 80 | +
|
|---|
| 81 | # The Google Maps API Key defined in the settings will be used
|
|---|
| 82 | # if not passed in as a parameter. The use of an API key is
|
|---|
| 83 | # _required_.
|
|---|
| 84 | @@ -101,6 +104,7 @@
|
|---|
| 85 | 'polylines' : self.polylines,
|
|---|
| 86 | 'icons': self.icons,
|
|---|
| 87 | 'markers' : self.markers,
|
|---|
| 88 | + 'events' : self.events,
|
|---|
| 89 | }
|
|---|
| 90 | params.update(self.extra_context)
|
|---|
| 91 | return render_to_string(self.template, params)
|
|---|
| 92 | @@ -144,6 +148,10 @@
|
|---|
| 93 | def icons(self):
|
|---|
| 94 | "Returns a sequence of GIcon objects in this map."
|
|---|
| 95 | return set([marker.icon for marker in self.markers if marker.icon])
|
|---|
| 96 | +
|
|---|
| 97 | + def add_event(self, event):
|
|---|
| 98 | + "Attaches a GEvent to the map object."
|
|---|
| 99 | + self.events.append(event)
|
|---|
| 100 |
|
|---|
| 101 | class GoogleMapSet(GoogleMap):
|
|---|
| 102 |
|
|---|
| 103 | Index: maps/google/overlays.py
|
|---|
| 104 | ===================================================================
|
|---|
| 105 | --- maps/google/overlays.py (revision 11246)
|
|---|
| 106 | +++ maps/google/overlays.py (working copy)
|
|---|
| 107 | @@ -1,54 +1,6 @@
|
|---|
| 108 | from django.utils.safestring import mark_safe
|
|---|
| 109 | from django.contrib.gis.geos import fromstr, Point, LineString, LinearRing, Polygon
|
|---|
| 110 |
|
|---|
| 111 | -class GEvent(object):
|
|---|
| 112 | - """
|
|---|
| 113 | - A Python wrapper for the Google GEvent object.
|
|---|
| 114 | -
|
|---|
| 115 | - Events can be attached to any object derived from GOverlayBase with the
|
|---|
| 116 | - add_event() call.
|
|---|
| 117 | -
|
|---|
| 118 | - For more information please see the Google Maps API Reference:
|
|---|
| 119 | - http://code.google.com/apis/maps/documentation/reference.html#GEvent
|
|---|
| 120 | -
|
|---|
| 121 | - Example:
|
|---|
| 122 | -
|
|---|
| 123 | - from django.shortcuts import render_to_response
|
|---|
| 124 | - from django.contrib.gis.maps.google import GoogleMap, GEvent, GPolyline
|
|---|
| 125 | -
|
|---|
| 126 | - def sample_request(request):
|
|---|
| 127 | - polyline = GPolyline('LINESTRING(101 26, 112 26, 102 31)')
|
|---|
| 128 | - event = GEvent('click',
|
|---|
| 129 | - 'function() { location.href = "http://www.google.com"}')
|
|---|
| 130 | - polyline.add_event(event)
|
|---|
| 131 | - return render_to_response('mytemplate.html',
|
|---|
| 132 | - {'google' : GoogleMap(polylines=[polyline])})
|
|---|
| 133 | - """
|
|---|
| 134 | -
|
|---|
| 135 | - def __init__(self, event, action):
|
|---|
| 136 | - """
|
|---|
| 137 | - Initializes a GEvent object.
|
|---|
| 138 | -
|
|---|
| 139 | - Parameters:
|
|---|
| 140 | -
|
|---|
| 141 | - event:
|
|---|
| 142 | - string for the event, such as 'click'. The event must be a valid
|
|---|
| 143 | - event for the object in the Google Maps API.
|
|---|
| 144 | - There is no validation of the event type within Django.
|
|---|
| 145 | -
|
|---|
| 146 | - action:
|
|---|
| 147 | - string containing a Javascript function, such as
|
|---|
| 148 | - 'function() { location.href = "newurl";}'
|
|---|
| 149 | - The string must be a valid Javascript function. Again there is no
|
|---|
| 150 | - validation fo the function within Django.
|
|---|
| 151 | - """
|
|---|
| 152 | - self.event = event
|
|---|
| 153 | - self.action = action
|
|---|
| 154 | -
|
|---|
| 155 | - def __unicode__(self):
|
|---|
| 156 | - "Returns the parameter part of a GEvent."
|
|---|
| 157 | - return mark_safe('"%s", %s' %(self.event, self.action))
|
|---|
| 158 | -
|
|---|
| 159 | class GOverlayBase(object):
|
|---|
| 160 | def __init__(self):
|
|---|
| 161 | self.events = []
|
|---|
| 162 | Index: templates/gis/google/google-map.js
|
|---|
| 163 | ===================================================================
|
|---|
| 164 | --- templates/gis/google/google-map.js (revision 11246)
|
|---|
| 165 | +++ templates/gis/google/google-map.js (working copy)
|
|---|
| 166 | @@ -10,6 +10,7 @@
|
|---|
| 167 | if (GBrowserIsCompatible()) {
|
|---|
| 168 | {{ js_module }}.{{ dom_id }} = new GMap2(document.getElementById("{{ dom_id }}"));
|
|---|
| 169 | {{ js_module }}.{{ dom_id }}.setCenter(new GLatLng({{ center.1 }}, {{ center.0 }}), {{ zoom }});
|
|---|
| 170 | + {% for event in events %}GEvent.addListener({{ js_module }}.{{ dom_id }}, {{ event }});{% endfor %}
|
|---|
| 171 | {% block controls %}{{ js_module }}.{{ dom_id }}.setUIToDefault();{% endblock %}
|
|---|
| 172 | {% if calc_zoom %}var bounds = new GLatLngBounds(); var tmp_bounds = new GLatLngBounds();{% endif %}
|
|---|
| 173 | {% for kml_url in kml_urls %}{{ js_module }}.{{ dom_id }}_kml{{ forloop.counter }} = new GGeoXml("{{ kml_url }}");
|
|---|