Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 273 | Rev 303 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 273 Rev 288
1
var tableau_couleurs = {"particulier": "#A9582B", "etablissement_scolaire" :"#8DC7B8",
1
var tableau_couleurs = {"particulier": "#A9582B", "etablissement_scolaire" :"#8DC7B8",
2
						"association": "#0000FF","professionnel": "#A7BD5B",
2
						"association": "#0000FF","professionnel": "#A7BD5B",
3
						"autre": "#FFC730"};
3
						"autre": "#FFC730"};
4
 
4
 
5
var infowindow = new google.maps.InfoWindow();
5
var infowindow = new google.maps.InfoWindow();
6
var types_affiches = new Array();
6
var types_affiches = new Array();
7
var marqueurs = new Array();
7
var marqueurs = new Array();
8
 
8
 
9
function getUrlBaseJrest() {
9
function getUrlBaseJrest() {
10
	return 'http://localhost/obs_saisons/applications/jrest/';
10
	return 'http://localhost/obs_saisons/applications/jrest/';
11
}
11
}
12
 
12
 
13
function initialiserCarte() {
13
function initialiserCarte() {
14
 
14
 
15
	if($('#map_canvas').length == 0) {
15
	if($('#map_canvas').length == 0) {
16
		return;
16
		return;
17
	}
17
	}
18
 
18
 
19
	var latlng = new google.maps.LatLng(47.0504, 2.2347);
19
	var latlng = new google.maps.LatLng(47.0504, 2.2347);
20
	var myOptions = {
20
	var myOptions = {
21
		zoom: 5,
21
		zoom: 5,
22
		center: latlng,
22
		center: latlng,
23
		mapTypeId: google.maps.MapTypeId.HYBRID
23
		mapTypeId: google.maps.MapTypeId.HYBRID
24
	};
24
	};
25
 
25
 
26
	map = new google.maps.Map(document.getElementById("map_canvas"),
26
	map = new google.maps.Map(document.getElementById("map_canvas"),
27
    	myOptions);
27
    	myOptions);
28
	
28
	
29
	$('.lien_vers_profil').live('click', function(event) {
29
	$('.lien_vers_profil').live('click', function(event) {
30
		event.preventDefault();
30
		event.preventDefault();
31
		window.open($(this).attr('href'));
31
		window.open($(this).attr('href'));
32
		return false;
32
		return false;
33
	});
33
	});
34
	
34
	
35
	obtenirStations();
35
	obtenirStations();
36
}
36
}
37
 
37
 
38
function obtenirStations() {
38
function obtenirStations() {
39
	
39
	
40
	$.get(getUrlBaseJrest()+'OdsExport/ExportStationJson/', function(data) {	
40
	$.get(getUrlBaseJrest()+'OdsExport/ExportStationJson/', function(data) {	
41
				
41
				
42
		var infos_stations = data.stations;
42
		var infos_stations = data.stations;
43
		var stats = data.stats;
43
		var stats = data.stats;
44
				
44
				
45
		for(i in infos_stations) {
45
		for(i in infos_stations) {
46
			creerEtAjouterMarqueur(i, infos_stations[i]);
46
			creerEtAjouterMarqueur(i, infos_stations[i]);
47
		}
47
		}
48
		genererLegende(stats);
48
		genererLegende(stats);
49
	});
49
	});
50
}
50
}
51
 
51
 
52
function obtenirImagePourChaineCouleur(chaine_couleur) {
52
function obtenirImagePourChaineCouleur(chaine_couleur) {
53
	
53
	
54
	chaine_couleur = encodeURIComponent(chaine_couleur);
54
	chaine_couleur = encodeURIComponent(chaine_couleur);
55
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
55
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
56
    
56
    
57
    return image;
57
    return image;
58
}
58
}
59
 
59
 
60
function genererLegende(stats) {	
60
function genererLegende(stats) {	
61
	chaine_legende = '<div class="critere" id="legende">';	
61
	chaine_legende = '<div class="critere" id="legende">';	
62
	for(i in stats) {
62
	for(i in stats) {
63
		if(i != 'total') {
63
		if(i != 'total') {
64
			var intitule_type = i.formaterTypePourBalise();
64
			var intitule_type = i.formaterTypePourBalise();
65
			var id_legende = 'type_'+intitule_type;
65
			var id_legende = 'type_'+intitule_type;
66
			var legende = i+' ('+stats[i]+')';
66
			var legende = i+' ('+stats[i]+')';
67
			var couleur = tableau_couleurs[intitule_type];
67
			var couleur = tableau_couleurs[intitule_type];
68
			chaine_legende += '<input class="selecteur_type" type="checkbox" value="'+intitule_type+'" id="selecteur_'+id_legende+'" />'+
68
			chaine_legende += '<input class="selecteur_type" type="checkbox" value="'+intitule_type+'" id="selecteur_'+id_legende+'" />'+
69
							  '<span class="legende" style="background-color:'+couleur+'"></span>'+
69
							  '<span class="legende" style="background-color:'+couleur+'"></span>'+
70
							  '<label id="'+id_legende+'">'+legende+'</label>'+
70
							  '<label id="'+id_legende+'">'+legende+'</label>'+
71
							  '<br />';
71
							  '<br />';
72
		} else {
72
		} else {
73
			$('#conteneur_nb_stations').text(stats[i]+' stations au total');
73
			$('#conteneur_nb_stations').text(stats[i]+' stations au total');
74
		}
74
		}
75
	}
75
	}
76
	chaine_legende += '</div>';
76
	chaine_legende += '</div>';
77
	$("#conteneur_legende").html(chaine_legende);
77
	$("#conteneur_legende").html(chaine_legende);
78
	
78
	
79
	$('.selecteur_type').change(function() {
79
	$('.selecteur_type').change(function() {
80
		types_affiches = new Array();
80
		types_affiches = new Array();
81
		$('.selecteur_type:checked').each(function(){
81
		$('.selecteur_type:checked').each(function(){
82
			types_affiches.push($(this).attr("id").replace("selecteur_type_",'')); 
82
			types_affiches.push($(this).attr("id").replace("selecteur_type_",'')); 
83
		}); 
83
		}); 
84
		afficherMarqueursSelectionnes();
84
		afficherMarqueursSelectionnes();
85
	})
85
	})
86
}
86
}
87
 
87
 
88
function creerEtAjouterMarqueur(id_marqueur, infos_station) {
88
function creerEtAjouterMarqueur(id_marqueur, infos_station) {
89
	
89
	
90
	latlng = new google.maps.LatLng(infos_station['latitude'],infos_station['longitude']);
90
	latlng = new google.maps.LatLng(infos_station['latitude'],infos_station['longitude']);
91
	var intitule_type = infos_station['type_participant'].formaterTypePourBalise();
91
	var intitule_type = infos_station['type_participant'].formaterTypePourBalise();
92
	var chaine_couleur = tableau_couleurs[intitule_type];	
92
	var chaine_couleur = tableau_couleurs[intitule_type];	
93
    var image = obtenirImagePourChaineCouleur(chaine_couleur);
93
    var image = obtenirImagePourChaineCouleur(chaine_couleur);
94
    var nom_station = infos_station['nom'];
94
    var nom_station = infos_station['nom'];
95
    	
95
    	
96
 	var marqueur_station = new google.maps.Marker({
96
 	var marqueur_station = new google.maps.Marker({
97
	      position: latlng,
97
	      position: latlng,
98
	      icon:image,
98
	      icon:image,
99
	      code:intitule_type,
99
	      code:intitule_type,
100
	      title:nom_station,
100
	      title:nom_station,
101
	      optimized: true
101
	      optimized: true
102
	});
102
	});
103
 
103
 
104
	google.maps.event.addListener(marqueur_station, 'click', function() {
104
	google.maps.event.addListener(marqueur_station, 'click', function() {
105
		
105
		
106
		contenu_fenetre = formaterContenuFenetre(infos_station);
106
		contenu_fenetre = formaterContenuFenetre(infos_station);
107
		infowindow.close();
107
		infowindow.close();
108
		infowindow.content = contenu_fenetre;
108
		infowindow.setContent(contenu_fenetre);
109
		infowindow.open(map,this);
109
		infowindow.open(map,this);
110
	});
110
	});
111
	
111
	
112
 	marqueur_station.setDraggable(false);
112
 	marqueur_station.setDraggable(false);
113
 	marqueur_station.setClickable(true);
113
 	marqueur_station.setClickable(true);
114
		
114
		
115
 	marqueur_station.setMap(map); 	
115
 	marqueur_station.setMap(map); 	
116
 	marqueurs.push(marqueur_station);
116
 	marqueurs.push(marqueur_station);
117
}
117
}
118
 
118
 
119
function afficherMarqueursSelectionnes() {
119
function afficherMarqueursSelectionnes() {
120
	for(i in marqueurs) {
120
	for(i in marqueurs) {
121
		var afficher = (types_affiches.length == 0 || jQuery.inArray(marqueurs[i].code, types_affiches) > -1) ? true : false;
121
		var afficher = (types_affiches.length == 0 || jQuery.inArray(marqueurs[i].code, types_affiches) > -1) ? true : false;
122
		marqueurs[i].setVisible(afficher);
122
		marqueurs[i].setVisible(afficher);
123
	}
123
	}
124
}
124
}
125
 
125
 
126
function formaterContenuFenetre(infos_station) {
126
function formaterContenuFenetre(infos_station) {
127
	
127
	
128
	var contenu_fenetre = "";
128
	var contenu_fenetre = "";
129
	contenu_fenetre = "<h3> "+infos_station['nom']+"</h3>";
129
	contenu_fenetre = "<h3> "+infos_station['nom']+"</h3>";
130
	contenu_fenetre += '<div class="infos_participant"> Participant  : '+construireUrlProfilParticipant(infos_station['participant'])+'</div>';
130
	contenu_fenetre += '<div class="infos_participant"> Participant  : '+construireUrlProfilParticipant(infos_station['participant'])+'</div>';
131
	contenu_fenetre += '<div class="infos_commune"> ';
131
	contenu_fenetre += '<div class="infos_commune"> ';
132
	if(infos_station['nom_commune'] != null && infos_station['nom_commune'] != "") {
132
	if(infos_station['nom_commune'] != null && infos_station['nom_commune'] != "") {
133
		contenu_fenetre += 'Commune : '+infos_station['nom_commune'];
133
		contenu_fenetre += 'Commune : '+infos_station['nom_commune'];
134
	}
134
	}
135
	
135
	
136
	if(infos_station['code_commune'] != null && infos_station['code_commune'] != "") {
136
	if(infos_station['code_commune'] != null && infos_station['code_commune'] != "") {
137
		contenu_fenetre += ' ('+infos_station['code_commune']+')';
137
		contenu_fenetre += ' ('+infos_station['code_commune']+')';
138
	}
138
	}
139
	contenu_fenetre += '</div>';
139
	contenu_fenetre += '</div>';
140
	contenu_fenetre += '<div class="infos_altitude"> Altitude : '+infos_station['altitude']+' m</div>';
140
	contenu_fenetre += '<div class="infos_altitude"> Altitude : '+infos_station['altitude']+' m</div>';
141
 
141
 
142
	
142
	
143
	return contenu_fenetre;
143
	return contenu_fenetre;
144
}
144
}
145
 
145
 
146
function obtenirImagePourChaineCouleur(chaine_couleur) {
146
function obtenirImagePourChaineCouleur(chaine_couleur) {
147
	
147
	
148
	chaine_couleur = encodeURIComponent(chaine_couleur);
148
	chaine_couleur = encodeURIComponent(chaine_couleur);
149
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
149
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
150
    
150
    
151
    return image;
151
    return image;
152
}
152
}
153
 
153
 
154
function construireUrlProfilParticipant(participant) {
154
function construireUrlProfilParticipant(participant) {
155
	
155
	
156
	if(participant['id'] == null && participant['nom'] == null) {
156
	if(participant['id'] == null && participant['nom'] == null) {
157
		return "anonyme";
157
		return "anonyme";
158
	}
158
	}
159
	
159
	
160
	var id = participant['id'];
160
	var id = participant['id'];
161
	
161
	
162
	if(participant['nom'] == null || participant['nom'] == "null") {
162
	if(participant['nom'] == null || participant['nom'] == "null") {
163
		var pseudo = participant['id'];
163
		var pseudo = participant['id'];
164
	} else {
164
	} else {
165
		var pseudo = participant['nom'];
165
		var pseudo = participant['nom'];
166
	}
166
	}
167
	
167
	
168
	return '<a class="lien_vers_profil" href="http://obs-saisons.fr/user/'+id+'"> '+pseudo+' </a>';
168
	return '<a class="lien_vers_profil" href="http://obs-saisons.fr/user/'+id+'"> '+pseudo+' </a>';
169
}
169
}
170
 
170
 
171
$('#map_canvas').ready(function() {
171
$('#map_canvas').ready(function() {
172
	initialiserCarte();
172
	initialiserCarte();
173
});
173
});
174
 
174
 
175
String.prototype.formaterTypePourBalise = function() {
175
String.prototype.formaterTypePourBalise = function() {
176
	var s = this;
176
	var s = this;
177
	return s.removeDiacritics().replace(' ','_').toLowerCase();
177
	return s.removeDiacritics().replace(' ','_').toLowerCase();
178
}
178
}
179
 
179
 
180
String.prototype.removeDiacritics = function() {
180
String.prototype.removeDiacritics = function() {
181
	var diacritics = [
181
	var diacritics = [
182
	    [/[\300-\306]/g, 'A'],
182
	    [/[\300-\306]/g, 'A'],
183
	    [/[\340-\346]/g, 'a'],
183
	    [/[\340-\346]/g, 'a'],
184
	    [/[\310-\313]/g, 'E'],
184
	    [/[\310-\313]/g, 'E'],
185
	    [/[\350-\353]/g, 'e'],
185
	    [/[\350-\353]/g, 'e'],
186
	    [/[\314-\317]/g, 'I'],
186
	    [/[\314-\317]/g, 'I'],
187
	    [/[\354-\357]/g, 'i'],
187
	    [/[\354-\357]/g, 'i'],
188
	    [/[\322-\330]/g, 'O'],
188
	    [/[\322-\330]/g, 'O'],
189
	    [/[\362-\370]/g, 'o'],
189
	    [/[\362-\370]/g, 'o'],
190
	    [/[\331-\334]/g, 'U'],
190
	    [/[\331-\334]/g, 'U'],
191
	    [/[\371-\374]/g, 'u'],
191
	    [/[\371-\374]/g, 'u'],
192
	    [/[\321]/g, 'N'],
192
	    [/[\321]/g, 'N'],
193
	    [/[\361]/g, 'n'],
193
	    [/[\361]/g, 'n'],
194
	    [/[\307]/g, 'C'],
194
	    [/[\307]/g, 'C'],
195
	    [/[\347]/g, 'c'],
195
	    [/[\347]/g, 'c'],
196
	];
196
	];
197
	var s = this;
197
	var s = this;
198
	for (var i = 0; i < diacritics.length; i++) {
198
	for (var i = 0; i < diacritics.length; i++) {
199
	    s = s.replace(diacritics[i][0], diacritics[i][1]);
199
	    s = s.replace(diacritics[i][0], diacritics[i][1]);
200
	}
200
	}
201
	return s;
201
	return s;
202
}
202
}