rough, untested, port of SensLabMap
[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 // in addition it could use a bit of cleaning like what was done for the first plugins
12 // especially wrt using 'instance' and 'data' in such a confusing way
13
14 (function( jQuery ){
15
16   var methods = {
17      init : function( options ) {
18
19        return this.each(function(){
20          
21          var $this = jQuery(this),
22              data = $this.data('SensLabMap'), SensLabMap = jQuery('<div />', { text : $this.attr('title') });
23          
24          // If the plugin hasn't been initialized yet
25          if ( ! data ) {
26          
27            /* Plugin initialization */
28
29             //google.load('maps', '3', { other_params: 'sensor=false' });
30             //google.setOnLoadCallback(initialize);
31
32             init();
33             /* End of plugin initialization */
34
35             jQuery(this).data('SensLabMap', {
36                                 plugin_uuid: options.plugin_uuid,
37                                 query_uuid: options.query_uuid,
38                 target : $this,
39                 SensLabMap : SensLabMap
40             });
41
42                         /* Subscribe to query updates */
43                         jQuery.subscribe('/results/' + options.query_uuid + '/changed', {instance: $this}, update_map);
44                         
45
46          }
47        });
48      },
49     destroy : function( ) {
50
51         return this.each(function(){
52             var $this = jQuery(this), data = $this.data('SensLabMap');
53                         jQuery(window).unbind('SensLabMap');
54                         data.SensLabMap.remove();
55                         $this.removeData('SensLabMap');
56                 })
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     jQuery.fn.SensLabMap = function( method ) {
71                 /* Method calling logic */
72                 if ( methods[method] ) {
73                         return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
74                 } else if ( typeof method === 'object' || ! method ) {
75                         return methods.init.apply( this, arguments );
76                 } else {
77                         jQuery.error( 'Method ' +  method + ' does not exist on jQuery.SensLabMap' );
78                 }    
79
80     };
81
82     /* Private methods */
83
84         function update_map(e, rows) {
85             var $plugindiv = e.data.instance;
86             $plugindiv.closest('.need-spin').spin(false);
87             
88             if(rows) {
89                 /* TODO rendering */   
90             } else {
91                 alert('error');
92             }
93             
94         }
95
96 })( jQuery );