summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Cahoon <chris.cahoon@gmail.com>2009-06-13 03:28:25 +0000
committerChris Cahoon <chris.cahoon@gmail.com>2009-06-13 03:28:25 +0000
commitd8aa8ced20dfc0168f97f838fc9c9e68b6fd2517 (patch)
tree123fbe885a782ba7dfcd496a57f5197128abfafa
parent5fa44cc855e7d5933d52f9f9eb09826ad9690477 (diff)
downloaddjango-d8aa8ced20dfc0168f97f838fc9c9e68b6fd2517.tar.gz
Fixed #11200 -- Now use a `set` data structure for `GoogleMap` icons so that they aren't repeated in rendered JavaScript. Thanks to ludifan for ticket and initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/http-wsgi-improvements@10992 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/gis/maps/google/gmap.py6
-rw-r--r--django/contrib/gis/maps/google/overlays.py8
2 files changed, 11 insertions, 3 deletions
diff --git a/django/contrib/gis/maps/google/gmap.py b/django/contrib/gis/maps/google/gmap.py
index dd4f67bc52..de8f75c5a0 100644
--- a/django/contrib/gis/maps/google/gmap.py
+++ b/django/contrib/gis/maps/google/gmap.py
@@ -143,7 +143,7 @@ class GoogleMap(object):
@property
def icons(self):
"Returns a sequence of GIcon objects in this map."
- return [marker.icon for marker in self.markers if marker.icon]
+ return set([marker.icon for marker in self.markers if marker.icon])
class GoogleMapSet(GoogleMap):
@@ -221,6 +221,6 @@ class GoogleMapSet(GoogleMap):
@property
def icons(self):
"Returns a sequence of all icons in each map of the set."
- icons = []
- for map in self.maps: icons.extend(map.icons)
+ icons = set()
+ for map in self.maps: icons |= map.icons
return icons
diff --git a/django/contrib/gis/maps/google/overlays.py b/django/contrib/gis/maps/google/overlays.py
index 4f1247d0a4..c2ebb3c992 100644
--- a/django/contrib/gis/maps/google/overlays.py
+++ b/django/contrib/gis/maps/google/overlays.py
@@ -231,6 +231,14 @@ class GIcon(object):
self.iconanchor = iconanchor
self.infowindowanchor = infowindowanchor
+ def __cmp__(self, other):
+ return cmp(self.varname, other.varname)
+
+ def __hash__(self):
+ # XOR with hash of GIcon type so that hash('varname') won't
+ # equal hash(GIcon('varname')).
+ return hash(self.__class__) ^ hash(self.varname)
+
class GMarker(GOverlayBase):
"""
A Python wrapper for the Google GMarker object. For more information