pretty printed
[myslice.git] / plugins / senslabmap / senslabmap.js
1 /**
2  * MySlice GoogleMap plugin
3  * URL: http://trac.myslice.info
4  * Description: SensLab display of 3D-geolocated data
5  * Author: The MySlice Team
6  * Copyright (c) 2012 UPMC Sorbonne Universite - INRIA
7  * License: GPLv3
8  */
9
10 // xxx TODO -- this plugin has never been tested 
11 // update_map looks suspiciously empty...
12 // in addition it could use a bit of cleaning like what was done for the first plugins
13 // especially wrt using 'instance' and 'data' in such a confusing way
14
15 (function( $ ){
16
17     $.fn.SensLabMap = function( method ) {
18         /* Method calling logic */
19         if ( methods[method] ) {
20             return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
21         } else if ( typeof method === 'object' || ! method ) {
22             return methods.init.apply( this, arguments );
23         } else {
24             $.error( 'Method ' +  method + ' does not exist on $.SensLabMap' );
25         }    
26     };
27
28     var methods = {
29         init : function( options ) {
30             return this.each(function(){
31                 var $this = $(this),
32                 data = $this.data('SensLabMap'), SensLabMap = $('<div />', { text : $this.attr('title') });
33                 // If the plugin hasn't been initialized yet
34                 if ( ! data ) {
35                     /* Plugin initialization */
36                     //google.load('maps', '3', { other_params: 'sensor=false' });
37                     //google.setOnLoadCallback(initialize);
38                     init();
39                     /* End of plugin initialization */
40                     $(this).data('SensLabMap', {
41                         plugin_uuid: options.plugin_uuid,
42                         query_uuid: options.query_uuid,
43                         target : $this,
44                         SensLabMap : SensLabMap
45                     });
46                     /* Subscribe to query updates */
47                     $.subscribe('/results/' + options.query_uuid + '/changed', {instance: $this}, update_map);
48                 }
49             });
50         },
51         destroy : function( ) {
52             return this.each(function(){
53                 var $this = $(this), data = $this.data('SensLabMap');
54                 $(window).unbind('SensLabMap');
55                 data.SensLabMap.remove();
56                 $this.removeData('SensLabMap');
57             });
58         },
59 /*
60     reposition : function( ) { // ... },
61     show : function( ) { // ... },
62     hide : function( ) { // ... },
63 */
64         update : function( content ) { 
65             // should be made a private function
66             set3dsize()
67         },
68   };
69
70     /* Private methods */
71     function update_map(e, rows) {
72         var $plugindiv = e.data.instance;
73         $plugindiv.closest('.need-spin').spin(false);
74         
75         if(rows) {
76             /* TODO rendering */   
77         } else {
78             alert('error');
79         }
80         
81     }
82
83 })( jQuery );