provide a config option to specify a googlemap API key if needed
[myslice.git] / plugins / googlemap / __init__.py
1 from unfold.plugin import Plugin
2
3 class GoogleMap (Plugin):
4
5     # expcted input are
6     # query :           query about the slice 
7     # query_all :       query about all resources
8     # googlemap_key :   mandatory googlemap API v3 key
9     # latitude,longitude, zoom : the starting point
10     # apparently at some point there has been support for a boolean 'checkboxes' input arg but seems dropped
11     def __init__ (self, query, query_all, googlemap_api_key=None, latitude=43., longitude=7., zoom=4, **settings):
12         Plugin.__init__ (self, **settings)
13         self.query=query
14         self.query_all = query_all
15         self.googlemap_api_key=googlemap_api_key
16         self.query_all_uuid = query_all.query_uuid if query_all else None
17         self.latitude=latitude
18         self.longitude=longitude
19         self.zoom=zoom
20
21     def template_file (self):
22         return "googlemap.html"
23
24     def template_env (self, request):
25         env={}
26         return env
27
28     def requirements (self):
29         googlemap_api_url = "https://maps.googleapis.com/maps/api/js?"
30         if self.googlemap_api_key: googlemap_api_url+="key=%s&"%self.googlemap_api_key
31         googlemap_api_url += "sensor=false"
32         reqs = {
33             # let users configure their googlemap API key in production deployements
34             'js_files' : [ googlemap_api_url,
35                            "/js/googlemap.js",
36                            "/js/markerclusterer.js",
37                             "js/manifold.js", "js/manifold-query.js", 
38                             "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js", 
39                             "js/unfold-helper.js",
40                            ],
41             'css_files' : [ "css/googlemap.css",
42                             ],
43             }
44         return reqs
45
46     # the list of things passed to the js plugin
47     def json_settings_list (self): return ['plugin_uuid','query_uuid', 'query_all_uuid', 'latitude', 'longitude', 'zoom', ]