Ticket #14186: geodjango-gdirections.patch
File geodjango-gdirections.patch, 5.1 KB (added by , 14 years ago) |
---|
-
django/contrib/gis/templates/gis/google/google-map.js
22 22 {{ js_module }}.{{ dom_id }}.addOverlay({{ js_module }}.{{ dom_id }}_polyline{{ forloop.counter }}); 23 23 {% for event in polyline.events %}GEvent.addListener({{ js_module }}.{{ dom_id }}_polyline{{ forloop.parentloop.counter }}, {{ event }}); {% endfor %} 24 24 {% if calc_zoom %}tmp_bounds = {{ js_module }}.{{ dom_id }}_polyline{{ forloop.counter }}.getBounds(); bounds.extend(tmp_bounds.getSouthWest()); bounds.extend(tmp_bounds.getNorthEast());{% endif %}{% endfor %} 25 {% if directions %}{{ js_module }}.{{ dom_id }}_directions = new GDirections({{ js_module }}.{{ dom_id }}); 26 {{ js_module }}.{{ dom_id }}_directions.loadFromWaypoints({{ directions }});{% endif %} 25 27 {% for marker in markers %}{{ js_module }}.{{ dom_id }}_marker{{ forloop.counter }} = new {{ marker }}; 26 28 {{ js_module }}.{{ dom_id }}.addOverlay({{ js_module }}.{{ dom_id }}_marker{{ forloop.counter }}); 27 29 {% for event in marker.events %}GEvent.addListener({{ js_module }}.{{ dom_id }}_marker{{ forloop.parentloop.counter }}, {{ event }}); {% endfor %} -
django/contrib/gis/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, GIcon 7 from django.contrib.gis.maps.google.overlays import GPolygon, GPolyline, GMarker, GIcon, GDirections 8 8 9 9 # The default Google Maps URL (for the API javascript) 10 10 # TODO: Internationalize for Japan, UK, etc. … … 21 21 def __init__(self, key=None, api_url=None, version=None, 22 22 center=None, zoom=None, dom_id='map', 23 23 kml_urls=[], polylines=None, polygons=None, markers=None, 24 directions=None, 24 25 template='gis/google/google-map.js', 25 26 js_module='geodjango', 26 27 extra_context={}): … … 56 57 self.js_module = js_module 57 58 self.template = template 58 59 self.kml_urls = kml_urls 60 # Does the user want to draw google directions on the map? 61 self.directions = directions; 59 62 60 63 # Does the user want any GMarker, GPolygon, and/or GPolyline overlays? 61 64 overlay_info = [[GMarker, markers, 'markers'], … … 101 104 'polylines' : self.polylines, 102 105 'icons': self.icons, 103 106 'markers' : self.markers, 107 'directions' : self.directions, 104 108 } 105 109 params.update(self.extra_context) 106 110 return render_to_string(self.template, params) -
django/contrib/gis/maps/google/overlays.py
299 299 @property 300 300 def js_params(self): 301 301 return '%s, %s' % (self.latlng, self.options()) 302 303 class GDirections(): 304 """ 305 A Python wrapper for the Google GDirections object. For more information 306 please see the Google Maps API Reference: 307 http://code.google.com/apis/maps/documentation/reference.html#GDirections 308 309 Example: 310 311 from django.shortcuts import render_to_response 312 from django.contrib.gis.maps.google.overlays import GDirections 313 314 def sample_request(request): 315 route = GDirections(LineString(POINT(40.44 -3.77), POINT(42.33 -3.66)) 316 return render_to_response('mytemplate.html', 317 {'google' : GoogleMap(directions=route)}) 318 """ 319 320 def __init__(self, geom): 321 """ 322 The GDirections object may be initialized on GEOS LineString, LinearRing, 323 and Polygon objects (internal rings not supported) or a parameter that 324 may instantiated into one of the above geometries. 325 """ 326 # If a GEOS geometry isn't passed in, try to contsruct one. 327 if isinstance(geom, basestring): geom = fromstr(geom) 328 if isinstance(geom, (tuple, list)): geom = Polygon(geom) 329 # Generating the lat/lng coordinate pairs. 330 if isinstance(geom, (LineString, LinearRing)): 331 self.latlngs = self.waypoints(geom.coords) 332 elif isinstance(geom, Polygon): 333 self.latlngs = self.waypoints(geom.shell.coords) 334 else: 335 raise TypeError('GPolyline may only initialize on GEOS LineString, LinearRing, and/or Polygon geometries.') 336 337 def waypoints(self, coords): 338 "Generates a JavaScript array of strings for the given coordinates." 339 return '[%s]' % ','.join(['"%s,%s"' % (y, x) for x, y in coords]) 340 341 def __unicode__(self): 342 return self.latlngs