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/trunk@10865 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2009-05-30 16:10:23 +00:00
parent 419747d1c8
commit 1ed5d8fc39
2 changed files with 11 additions and 3 deletions

View File

@ -143,7 +143,7 @@ class GoogleMap(object):
@property @property
def icons(self): def icons(self):
"Returns a sequence of GIcon objects in this map." "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): class GoogleMapSet(GoogleMap):
@ -221,6 +221,6 @@ class GoogleMapSet(GoogleMap):
@property @property
def icons(self): def icons(self):
"Returns a sequence of all icons in each map of the set." "Returns a sequence of all icons in each map of the set."
icons = [] icons = set()
for map in self.maps: icons.extend(map.icons) for map in self.maps: icons |= map.icons
return icons return icons

View File

@ -231,6 +231,14 @@ class GIcon(object):
self.iconanchor = iconanchor self.iconanchor = iconanchor
self.infowindowanchor = infowindowanchor 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): class GMarker(GOverlayBase):
""" """
A Python wrapper for the Google GMarker object. For more information A Python wrapper for the Google GMarker object. For more information