1 /***************************************************************************
2 * Copyright (C) 2003-2011 Polytechnique.org *
3 * http://opensource.polytechnique.org/ *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
21 // http://code.google.com/apis/maps/documentation/javascript/
22 // http://code.google.com/p/google-maps-utility-library-v3/wiki
/Libraries
24 function map_initialize()
28 center
: new google
.maps
.LatLng(0, 0),
29 mapTypeId
: google
.maps
.MapTypeId
.ROADMAP
31 var map
= new google
.maps
.Map($('#map_canvas').get(0), myOptions
);
33 $.xget(window
.location
.href
, {ajax
: true}, function(json_data
) {
34 var data
= jQuery
.parseJSON(json_data
);
36 var count
= dots
.length
;
37 var info_window
= new google
.maps
.InfoWindow({});
38 var parameters
= ", '_blank', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=840,height=600'";
41 for (var i
= 0; i
< count
; ++i
) {
42 var latLng
= new google
.maps
.LatLng(dots
[i
].latitude
, dots
[i
].longitude
);
43 var color
= promos_to_color(dots
[i
].promo
);
45 if (dots
[i
].hrpid
.search(',') > -1) {
46 var hrpids
= dots
[i
].hrpid
.split(',');
47 var names
= dots
[i
].name
.split(',');
48 var link_array
= new Array();
50 for (var j
= 0; j
< hrpids
.length
; ++j
) {
51 link_array
[j
] = '<a href="profile/' + hrpids[j] + '" onclick="window.open(this.href' + parameters + '); return false;">' + names[j] + '</a>';
53 var link
= link_array
.join('<br />');
55 var link
= '<a href="profile/' + dots[i].hrpid + '" onclick="window.open(this.href' + parameters + '); return false;">' + dots[i].name + '</a>';
58 var marker
= new google
.maps
.Marker({
63 marker
.bindTo('icon', new ColoredIcon(color
));
64 marker
.set('color', color
);
65 marker
.set('html', link
);
66 google
.maps
.event
.addListener(marker
, 'click', function() {
67 info_window
.setContent(this.html
);
68 info_window
.open(map
, this);
72 var mc
= new MarkerClusterer(map
, markers
, {'averageCenter': true});
76 function ColoredIcon(color
)
78 this.set('starcolor', null);
79 this.set('color', color
);
80 this.set('icon', 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=|' + color
);
83 ColoredIcon
.prototype = new google
.maps
.MVCObject();
85 var colors
= new Array();
86 colors
['red'] = 'ff0000';
87 colors
['yellow'] = 'ffff00';
88 colors
['blue'] = '0000ff';
89 colors
['green'] = '00ff00';
90 colors
['gray'] = '606060';
92 function promos_to_color(promos
)
94 var promos_array
= promos
.split(',');
95 var length
= promos_array
.length
;
98 return colors
[promo_to_color(promos
)];
101 var color_array
= new Array();
102 for (var i
= 0; i
< length
; ++i
) {
103 color_array
[i
] = promo_to_color(promos_array
[i
]);
106 return color_average(color_array
);
109 function promo_to_color(promo
)
111 var main_education
= promo
.charAt(0);
113 switch (main_education
)
116 var year_promo
= promo
.substr(1);
117 if ((year_promo
% 2) == 0) {
131 function color_average(color_array
)
133 var length
= color_array
.length
;
134 var rbg
= new Array(0, 0, 0);
136 for (var i
= 0; i
< length
; ++i
) {
137 switch (color_array
[i
])
163 for (var i
= 0; i
< 3; ++i
) {
164 var color
= Math
.floor(rbg
[i
] / length
* 255);
165 var hexa
= color
.toString(16);
166 if (hexa
.length
== 1) {
175 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: