adopting jquery 2.0.3 - benchmarking showed no impact on performance
[myslice.git] / plugins / pres_view / static / js / recup_data.js
1 function recup_data (url,id,method)
2 {                       
3                                 var longueur;
4                                 j.getJSON(url, function(data) 
5                                 {
6                                         j.each(data     , function(key, val) 
7                                         {       
8                                                 switch ( val.params.data.print_method )
9                                                         {
10                                                                 case 'marker' :
11                                                                                 pos_marker[id]= [];
12                                                                                 opt_marker[id]= [];
13                                                                                 marker[id]= [];
14                                                                                 ref[id] = 'marker';
15                                                                 break;
16                                                                 case 'line' :
17                                                                                 opt_line[id] =[];
18                                                                                 pos_line[id]= [];
19                                                                                 line[id]= [];
20                                                                                 ref[id] = 'line';
21                                                                 break;
22                                                                 case 'circle' :
23                                                                                 opt_circle[id] =[];
24                                                                                 pos_circle[id]= [];
25                                                                                 circle[id]= [];
26                                                                                 ref[id] = 'circle';
27                                                                 break;
28                                                                 default:
29                                                                         alert ("unknown method");
30                                                                 break;
31                                                         }       
32                                                 for ( var i= 0; i<val.params.data.message.length;i++)
33                                                 {
34                                                         var longueur;
35                                                         switch ( val.params.data.print_method )
36                                                         {
37                                                                 case 'marker' :
38                                                                         pos_marker[id].push( new google.maps.LatLng(val.params.data.message[i].ape_position[0].latitude,val.params.data.message[i].ape_position[0].longitude));
39
40                                                                                 opt_marker[id].push 
41                                                                                 ({
42                                                                                         position: pos_marker[id][pos_marker[id].length - 1],
43                                                                                         visible: true,
44                                                                                         map : map
45                                                                                         //title : val.params.data.message.ape_timestamp
46                                                                                 });
47                                                                         
48                                                                         //marker[id].push( new google.maps.Marker(opt_marker[id][opt_marker[id].length - 1 ])); 
49                                                                         if ( val.params.data.print_options )
50                                                                         {
51                                                                                 opt_conf[id] = val.params.data.print_options;
52                                                                         }
53                                                                         
54                                                                 break;
55                                                                 
56                                                                 case 'line' :
57                                                                         for ( var j = 0 ; j < val.params.data.message[i].ape_position.length ; j++ ) 
58                                                                         {
59                                                                                 pos_line[id].push(new google.maps.LatLng(val.params.data.message[i].ape_position[j].latitude,val.params.data.message[i].ape_position[j].longitude)) ;
60                                                                         }       
61                                                                         
62                                                                         opt_line[id].push
63                                                                         ({
64                                                                                 path : pos_line[id] ,
65                                                                                 map : map,
66                                                                                 strokeColor: "#FF0000",
67                                                                                 strokeOpacity: 1.0,
68                                                                                 strokeWeight: 2
69                                                                         })
70
71                                                                         if ( val.params.data.print_options )
72                                                                         {
73                                                                                 opt_conf[id] = val.params.data.print_options;
74                                                                         }
75                                                                         
76                                                                 break;
77                                                                 
78                                                                 case 'circle':
79                                                                         
80                                                                         longueur = pos_circle[id].length;
81                                                                         pos_circle[id][longueur]= [];
82                                                                         pos_circle[id][longueur].push( new google.maps.LatLng(val.params.data.message[i].ape_position[0].latitude,val.params.data.message[i].ape_position[0].longitude));
83                                                                         var l_radius=get_Radius(val.params.data.message[i], val.params.data.print_options);
84                                                                         opt_circle[id].push({
85                                                                                 map : map,
86                                                                                 center : pos_circle[id][longueur][0],
87                                                                                 radius : l_radius
88                                                                         })
89                                                                         if ( val.params.data.print_options )
90                                                                         {
91                                                                                 opt_conf[id] = val.params.data.print_options;
92                                                                         }
93                                                                         
94                                                                 break;
95                                                                 
96                                                                 default :
97                                                                         alert("pas bon");
98                                                                 break;
99                                                         }
100                                                                 
101                                                 }
102                                                 
103                                         });
104                                         afficher_par_id(id,method);
105                                         set_options(id);
106                                 });
107                                 
108 }
109
110 function set_options(id) {
111         if (opt_conf[id]){
112                 
113                 switch ( ref[id] ) 
114                                 {
115                                         case 'marker' :
116                                                 for ( var i = 0; i < marker[id].length ; i++ ) 
117                                                         {
118                                                                 {
119                                                                                 if ( opt_conf[id].icon ) // color need to be in english 
120                                                                                 {
121                                                                                         marker[id][i].setIcon("http://labs.google.com/ridefinder/images/mm_20_"+opt_conf[id].icon+".png");
122                                                                                 }
123                                                                 }
124                                                         }
125                                                 break;
126                                                 
127                                         case'circle':
128                                         
129                                         break;
130                                         
131                                         case'line':
132                                         
133                                         
134                                         break;
135                                                 
136                                                 
137                                         default :
138                                                         { alert ( "set_options : mauvais id" );}
139                                         break;
140                                         }
141         }
142 }
143
144 function get_Radius(message,print_options){
145         var tiny        =       1000;
146         var small       =       5000;
147         var avg         =       10000;
148         var big         =       100000;
149         var giant       =       500000;
150         console.log(print_options.circle_radius_arg+"--"+message.date_created);
151         console.log(eval('message.'+print_options.circle_radius_arg));
152         data = eval('message.'+print_options.circle_radius_arg);
153         if (data < print_options.size.tiny){return tiny;}
154         else if(data < print_options.size.small){return small;}
155         else if(data < print_options.size.avg){return avg;}
156         else if(data < print_options.size.big){return big;}
157         else {return giant;}
158 }