Django

Code

Ticket #7619 (closed: fixed)

Opened 2 months ago

Last modified 2 months ago

GIS/GoogleMaps: Support for point geometries in map creation

Reported by: LudwigBrinckmann Assigned to: jbronn
Milestone: 1.0 beta Component: GIS
Version: gis Keywords: Google Maps Markers
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

The automatic creation of Google maps in the GIS branch supports the display of Polygons and Polylines, but not Points.

The attached patch adds the display of Points as GMarkers by adding another class GMarker to the overlays defined in overlays.py. The GMarker is very similar to polygons and polylines, but has the option to attach a title to it, whch will appear in Google Maps as a tooltip when moving over the marker. In addition the GoogleMap? class takes another keyword parameter points to pass the point data through to the template.

Another option to implement the marker functionality would be to use a marker manager, as defined in the Google Maps API, which has the ability to deal with large amount of markers. The proposed patch, however, works fine with a small amount of markers.

The patch furthermore extends the model by having a GEvent class that allows to attach an event, such as 'click' to a line, polygon or point. A bit of example code for this is given in overlays.py:

     from django.shortcuts import render_to_response
      from django.contrib.gis.maps.google.gmap import GoogleMap
      from django.contrib.gis.maps.google.overlays import GMarker, GEvent
      from django.contrib.gis.geos import fromstr

      def sample_request(request):
          points = []
          location = fromstr('POINT(101 26)')
          point = GMarker(location)
          event = GEvent('click', 
            'function() { location.href = "http://www.google.com"}')
          point.add_event(event)
          points.append(point)
          return render_to_response('mytemplate.html', 
          {'google' : GoogleMap(points=points)})

There is a working version of (a slightly older version of this patch) in the small map on the right hand panel at http://www.yunnanexplorer.com/festivals.

Attachments

gis-googlemaps.diff (10.3 kB) - added by ludwigbrinckmann@gmail.com on 07/03/08 05:55:54.
Patch

Change History

07/03/08 05:55:54 changed by ludwigbrinckmann@gmail.com

  • attachment gis-googlemaps.diff added.

Patch

07/03/08 10:04:17 changed by jbronn

  • owner changed from nobody to jbronn.
  • version changed from SVN to gis.
  • milestone set to 1.0 beta.

07/05/08 17:10:33 changed by jbronn

  • status changed from new to closed.
  • resolution set to fixed.

(In [7841]) gis: Fixed #7619. Added support Google Maps markers (GMarker) and events (GEvent). Thanks, Ludwig Brinckmann.

07/05/08 17:17:04 changed by jbronn

I've revised the patch a bit in r7841 -- here's how you would do it now:

from django.shortcuts import render_to_response
from django.contrib.gis.maps.google import GoogleMap GMarker, GEvent

def sample_request(request):
    marker = GMarker('POINT(101 26)') # Could also be GMarker((101, 26))
    event = GEvent('click', 'function() { location.href = "http://www.google.com"}')
    marker.add_event(event)
    return render_to_response('mytemplate.html', {'google' : GoogleMap(markers=[marker])})

Add/Change #7619 (GIS/GoogleMaps: Support for point geometries in map creation)




Change Properties
Action