backport stable branch
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Sun, 16 Aug 2009 20:42:33 +0200
changeset 2869 0cb160fd3cdf
parent 2867 e8581a4f1bae (current diff)
parent 2868 937890e25765 (diff)
child 2880 bfc8e1831290
backport stable branch
web/views/igeocodable.py
--- a/web/views/igeocodable.py	Sun Aug 16 20:27:28 2009 +0200
+++ b/web/views/igeocodable.py	Sun Aug 16 20:42:33 2009 +0200
@@ -22,6 +22,8 @@
     __select__ = implements(IGeocodable)
 
     def call(self):
+        # remove entities that don't define latitude and longitude
+        self.rset = self.rset.filtered_rset(lambda e: e.latitude and e.longitude)
         zoomlevel = self.req.form.pop('zoomlevel', 8)
         extraparams = self.req.form.copy()
         extraparams.pop('vid', None)
@@ -41,10 +43,15 @@
 
     def build_marker_data(self, row, extraparams):
         entity = self.rset.get_entity(row, 0)
+        icon = None
+        if hasattr(entity, 'marker_icon'):
+            icon = entity.marker_icon()
+        else:
+            icon = (self.req.external_resource('GMARKER_ICON'), (20, 34), (4, 34), None)
         return {'latitude': entity.latitude, 'longitude': entity.longitude,
                 'title': entity.dc_long_title(),
                 #icon defines : (icon._url, icon.size,  icon.iconAncho', icon.shadow)
-                'icon': entity.marker_icon() or (self.req.external_resource('GMARKER_ICON'), (20, 34), (4, 34), None),
+                'icon': icon,
                 'bubbleUrl': entity.absolute_url(vid='gmap-bubble', __notemplate=1, **extraparams),
                 }
 
@@ -67,7 +74,9 @@
     need_navigation = False
 
     def call(self, gmap_key, width=400, height=400, uselabel=True, urlparams=None):
-        self.req.add_js('http://maps.google.com/maps?file=api&amp;v=2&amp;key=%s' % gmap_key,
+        # remove entities that don't define latitude and longitude
+        self.rset = self.rset.filtered_rset(lambda e: e.latitude and e.longitude)
+        self.req.add_js('http://maps.google.com/maps?sensor=false&file=api&amp;v=2&amp;key=%s' % gmap_key,
                         localfile=False)
         self.req.add_js( ('cubicweb.widgets.js', 'cubicweb.gmap.js', 'gmap.utility.labeledmarker.js') )
         rql = self.rset.printable_rql()