Subversion Repositories Sites.obs-saisons.fr

Rev

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

Rev 245 Rev 247
-
 
1
var tableau_couleurs = {"Particulier": "#A9582B", "Établissement scolaire" :"#8DC7B8",
-
 
2
						"Association": "#ED9355","Professionnel": "#A7BD5B",
-
 
3
						"Autre": "#FFC730","Inconnu": "#0000FF"};
-
 
4
 
-
 
5
var infowindow = new google.maps.InfoWindow();
-
 
6
 
1
function getUrlBaseJrest() {
7
function getUrlBaseJrest() {
2
	return 'http://162.38.234.9/obs_saisons/applications/jrest/';
8
	return 'http://162.38.234.9/obs_saisons/applications/jrest/';
3
}
9
}
4
 
10
 
5
function initialiserCarte() {
11
function initialiserCarte() {
6
 
12
 
7
	if($('#map_canvas').length == 0) {
13
	if($('#map_canvas').length == 0) {
8
		return;
14
		return;
9
	}
15
	}
10
 
16
 
11
	var latlng = new google.maps.LatLng(47.0504, 2.2347);
17
	var latlng = new google.maps.LatLng(47.0504, 2.2347);
12
	var myOptions = {
18
	var myOptions = {
13
		zoom: 5,
19
		zoom: 5,
14
		center: latlng,
20
		center: latlng,
15
		mapTypeId: google.maps.MapTypeId.HYBRID
21
		mapTypeId: google.maps.MapTypeId.HYBRID
16
	};
22
	};
17
 
23
 
18
	map = new google.maps.Map(document.getElementById("map_canvas"),
24
	map = new google.maps.Map(document.getElementById("map_canvas"),
19
    	myOptions);
25
    	myOptions);
20
	
26
	
21
	$('.lien_vers_profil').live('click', function(event) {
27
	$('.lien_vers_profil').live('click', function(event) {
22
		event.preventDefault();
28
		event.preventDefault();
23
		window.open($(this).attr('href'));
29
		window.open($(this).attr('href'));
24
		return false;
30
		return false;
25
	});
31
	});
26
	
32
	
27
	obtenirStations();
33
	obtenirStations();
28
}
34
}
29
 
35
 
30
function obtenirStations() {
36
function obtenirStations() {
31
	
37
	
32
	$.get(getUrlBaseJrest()+'OdsExport/ExportStationJson/', function(data) {	
38
	$.get(getUrlBaseJrest()+'OdsExport/ExportStationJson/', function(data) {	
33
				
39
				
34
		infos_stations = data;
40
		infos_stations = data;
35
				
41
				
36
		for(i in infos_stations) {
42
		for(i in infos_stations) {
37
			creerEtAjouterMarqueur(i, infos_stations[i]);
43
			creerEtAjouterMarqueur(i, infos_stations[i]);
38
		}
44
		}
39
	});
45
	});
40
}
46
}
41
 
47
 
42
function obtenirImagePourChaineCouleur(chaine_couleur) {
48
function obtenirImagePourChaineCouleur(chaine_couleur) {
43
	
49
	
44
	chaine_couleur = encodeURIComponent(chaine_couleur);
50
	chaine_couleur = encodeURIComponent(chaine_couleur);
45
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
51
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
46
    
52
    
47
    return image;
53
    return image;
48
}
54
}
49
 
55
 
50
function creerEtAjouterMarqueur(id_marqueur, infos_station) {
56
function creerEtAjouterMarqueur(id_marqueur, infos_station) {
51
	
57
	
52
	latlng = new google.maps.LatLng(infos_station['latitude'],infos_station['longitude']);
58
	latlng = new google.maps.LatLng(infos_station['latitude'],infos_station['longitude']);
-
 
59
	
-
 
60
	
53
	/*var chaine_couleur = '';
61
	var chaine_couleur = tableau_couleurs[infos_station['type_participant']];
54
	
62
	
55
	for(i in infos_stations.especes) {
-
 
56
		var observation = infos_station.obs[i];
-
 
57
		
-
 
58
		if(typeof(tableau_couleurs_en_cours[observation.id_espece]) != 'undefined') {		
-
 
59
			chaine_couleur += tableau_couleurs_en_cours[observation.id_espece]+",";
63
	for(i in infos_stations.especes) {
60
		}
-
 
61
	}
-
 
62
	
-
 
63
	chaine_couleur = chaine_couleur.slice(0,chaine_couleur.length - 1);
64
		
64
	*/
-
 
65
	var chaine_couleur = "#A9582B";
65
	}
66
    var image = obtenirImagePourChaineCouleur(chaine_couleur);
66
	
67
    
67
    var image = obtenirImagePourChaineCouleur(chaine_couleur);
68
	
68
    	
69
 	var marqueur_station = new google.maps.Marker({
69
 	var marqueur_station = new google.maps.Marker({
70
	      position: latlng,
70
	      position: latlng,
71
	      icon:image,
71
	      icon:image,
72
	      title:infos_station.station,
72
	      title:infos_station.station,
73
	      optimized: false
73
	      optimized: false
74
	});
74
	});
75
 
75
 
76
	/*google.maps.event.addListener(tableau_marqueurs[id_marqueur], 'click', function() {
76
	google.maps.event.addListener(marqueur_station, 'click', function() {
77
		
77
		
78
		//contenu_fenetre = formaterContenuFenetre(infos_stations.obs);
78
		contenu_fenetre = formaterContenuFenetre(infos_station);
79
		infowindow.close();
79
		infowindow.close();
80
		infowindow.content = contenu_fenetre;
80
		infowindow.content = contenu_fenetre;
81
		infowindow.open(map,this);
81
		infowindow.open(map,this);
82
	});*/
82
	});
83
	
83
	
84
 	marqueur_station.setDraggable(false);
84
 	marqueur_station.setDraggable(false);
85
 	marqueur_station.setClickable(true);
85
 	marqueur_station.setClickable(true);
86
		
86
		
87
 	marqueur_station.setMap(map); 
87
 	marqueur_station.setMap(map); 
-
 
88
}
-
 
89
 
-
 
90
function formaterContenuFenetre(infos_station) {
-
 
91
	
-
 
92
	var contenu_fenetre = "";
-
 
93
	contenu_fenetre = "<h3> "+infos_station.station+"</h3>";
-
 
94
	
-
 
95
	contenu_fenetre += '<div class="infos_participant"> Participant  : '+construireUrlProfilParticipant(infos_station.id_participant,infos_station.pseudo_participant)+'</div>';
-
 
96
	
-
 
97
	contenu_fenetre += '<div class="infos_commune"> ';
-
 
98
	if(infos_station.nom_commune != null && infos_station.nom_commune != "") {
-
 
99
		contenu_fenetre += 'Commune : '+infos_station.nom_commune;
-
 
100
	}
-
 
101
	
-
 
102
	if(infos_station.code_commune != null && infos_station.code_commune != "") {
-
 
103
		contenu_fenetre += ' ('+infos_station.code_commune+')';
-
 
104
	}
-
 
105
	contenu_fenetre += '</div>';
-
 
106
	
-
 
107
	
-
 
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>';
-
 
126
	}
-
 
127
	
-
 
128
	return contenu_fenetre;
-
 
129
}
-
 
130
 
-
 
131
function genererLegende() {
-
 
132
	
-
 
133
	chaine_legende = '<div class="critere" id="legende">';
-
 
134
	
-
 
135
	for(i in tableau_couleurs) {
-
 
136
		chaine_legende += '<span class="legende" style="background-color:'+tableau_couleurs[i]+'"></span>';
-
 
137
		chaine_legende += '<label for="type_'+i+'">'+i+'</label><br />';
-
 
138
	}
-
 
139
	
-
 
140
	chaine_legende += '</div>';
-
 
141
	
88
 
142
	$("#conteneur_legende").html(chaine_legende);
89
}
143
}
90
 
144
 
91
function obtenirImagePourChaineCouleur(chaine_couleur) {
145
function obtenirImagePourChaineCouleur(chaine_couleur) {
92
	
146
	
93
	chaine_couleur = encodeURIComponent(chaine_couleur);
147
	chaine_couleur = encodeURIComponent(chaine_couleur);
94
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
148
	var image = getUrlBaseJrest()+"OdsMarqueur/point?couleurs="+chaine_couleur;
95
    
149
    
96
    return image;
150
    return image;
97
}
151
}
-
 
152
 
-
 
153
function construireUrlProfilParticipant(id, pseudo) {
-
 
154
	
-
 
155
	if(id == null && pseudo == null) {
-
 
156
		return "anonyme";
-
 
157
	}
-
 
158
	
-
 
159
	if(pseudo == null || pseudo == "null") {
-
 
160
		pseudo = id;
-
 
161
	}
-
 
162
	
-
 
163
	return '<a class="lien_vers_profil" href="http://obs-saisons.fr/user/'+id+'"> '+pseudo+' </a>';
-
 
164
}
98
 
165
 
99
$('#map_canvas').ready(function() {
166
$('#map_canvas').ready(function() {
-
 
167
	initialiserCarte();
100
	initialiserCarte();
168
	genererLegende();
101
});
169
});