equal
deleted
inserted
replaced
60 binary = True |
60 binary = True |
61 templatable = False |
61 templatable = False |
62 content_type = 'application/json' |
62 content_type = 'application/json' |
63 |
63 |
64 def call(self): |
64 def call(self): |
65 zoomlevel = self._cw.form.pop('zoomlevel', 8) |
65 zoomlevel = self._cw.form.pop('zoomlevel', None) |
66 extraparams = self._cw.form.copy() |
66 extraparams = self._cw.form.copy() |
67 extraparams.pop('vid', None) |
67 extraparams.pop('vid', None) |
68 extraparams.pop('rql', None) |
68 extraparams.pop('rql', None) |
69 markers = [] |
69 markers = [] |
70 for entity in self.cw_rset.entities(): |
70 for entity in self.cw_rset.entities(): |
72 # remove entities that don't define latitude and longitude |
72 # remove entities that don't define latitude and longitude |
73 if not (igeocodable.latitude and igeocodable.longitude): |
73 if not (igeocodable.latitude and igeocodable.longitude): |
74 continue |
74 continue |
75 markers.append(self.build_marker_data(entity, igeocodable, |
75 markers.append(self.build_marker_data(entity, igeocodable, |
76 extraparams)) |
76 extraparams)) |
77 center = { |
77 if not markers: |
78 'latitude': sum(marker['latitude'] for marker in markers) / len(markers), |
78 return |
79 'longitude': sum(marker['longitude'] for marker in markers) / len(markers), |
|
80 } |
|
81 geodata = { |
79 geodata = { |
82 'zoomlevel': int(zoomlevel), |
|
83 'center': center, |
|
84 'markers': markers, |
80 'markers': markers, |
85 } |
81 } |
|
82 if zoomlevel: |
|
83 geodata['zoomlevel'] = zoomlevel |
86 self.w(json_dumps(geodata)) |
84 self.w(json_dumps(geodata)) |
87 |
85 |
88 def build_marker_data(self, entity, igeocodable, extraparams): |
86 def build_marker_data(self, entity, igeocodable, extraparams): |
89 return {'latitude': igeocodable.latitude, |
87 return {'latitude': igeocodable.latitude, |
90 'longitude': igeocodable.longitude, |
88 'longitude': igeocodable.longitude, |