Subversion Repositories Sites.obs-saisons.fr

Rev

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

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