20 content_type = 'application/json' |
20 content_type = 'application/json' |
21 |
21 |
22 __select__ = implements(IGeocodable) |
22 __select__ = implements(IGeocodable) |
23 |
23 |
24 def call(self): |
24 def call(self): |
|
25 # remove entities that don't define latitude and longitude |
|
26 self.rset = self.rset.filtered_rset(lambda e: e.latitude and e.longitude) |
25 zoomlevel = self.req.form.pop('zoomlevel', 8) |
27 zoomlevel = self.req.form.pop('zoomlevel', 8) |
26 extraparams = self.req.form.copy() |
28 extraparams = self.req.form.copy() |
27 extraparams.pop('vid', None) |
29 extraparams.pop('vid', None) |
28 extraparams.pop('rql', None) |
30 extraparams.pop('rql', None) |
29 markers = [self.build_marker_data(rowidx, extraparams) |
31 markers = [self.build_marker_data(rowidx, extraparams) |
39 } |
41 } |
40 self.w(simplejson.dumps(geodata)) |
42 self.w(simplejson.dumps(geodata)) |
41 |
43 |
42 def build_marker_data(self, row, extraparams): |
44 def build_marker_data(self, row, extraparams): |
43 entity = self.rset.get_entity(row, 0) |
45 entity = self.rset.get_entity(row, 0) |
|
46 icon = None |
|
47 if hasattr(entity, 'marker_icon'): |
|
48 icon = entity.marker_icon() |
|
49 else: |
|
50 icon = (self.req.external_resource('GMARKER_ICON'), (20, 34), (4, 34), None) |
44 return {'latitude': entity.latitude, 'longitude': entity.longitude, |
51 return {'latitude': entity.latitude, 'longitude': entity.longitude, |
45 'title': entity.dc_long_title(), |
52 'title': entity.dc_long_title(), |
46 #icon defines : (icon._url, icon.size, icon.iconAncho', icon.shadow) |
53 #icon defines : (icon._url, icon.size, icon.iconAncho', icon.shadow) |
47 'icon': entity.marker_icon() or (self.req.external_resource('GMARKER_ICON'), (20, 34), (4, 34), None), |
54 'icon': icon, |
48 'bubbleUrl': entity.absolute_url(vid='gmap-bubble', __notemplate=1, **extraparams), |
55 'bubbleUrl': entity.absolute_url(vid='gmap-bubble', __notemplate=1, **extraparams), |
49 } |
56 } |
50 |
57 |
51 |
58 |
52 class GoogleMapBubbleView(EntityView): |
59 class GoogleMapBubbleView(EntityView): |
65 |
72 |
66 __select__ = implements(IGeocodable) |
73 __select__ = implements(IGeocodable) |
67 need_navigation = False |
74 need_navigation = False |
68 |
75 |
69 def call(self, gmap_key, width=400, height=400, uselabel=True, urlparams=None): |
76 def call(self, gmap_key, width=400, height=400, uselabel=True, urlparams=None): |
70 self.req.add_js('http://maps.google.com/maps?file=api&v=2&key=%s' % gmap_key, |
77 # remove entities that don't define latitude and longitude |
|
78 self.rset = self.rset.filtered_rset(lambda e: e.latitude and e.longitude) |
|
79 self.req.add_js('http://maps.google.com/maps?sensor=false&file=api&v=2&key=%s' % gmap_key, |
71 localfile=False) |
80 localfile=False) |
72 self.req.add_js( ('cubicweb.widgets.js', 'cubicweb.gmap.js', 'gmap.utility.labeledmarker.js') ) |
81 self.req.add_js( ('cubicweb.widgets.js', 'cubicweb.gmap.js', 'gmap.utility.labeledmarker.js') ) |
73 rql = self.rset.printable_rql() |
82 rql = self.rset.printable_rql() |
74 if urlparams is None: |
83 if urlparams is None: |
75 loadurl = self.build_url(rql=rql, vid='geocoding-json') |
84 loadurl = self.build_url(rql=rql, vid='geocoding-json') |