Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2998 Rev 3006
1
/*+--------------------------------------------------------------------------------------------------------+*/
1
/*+--------------------------------------------------------------------------------------------------------+*/
2
// PARAMÊTRES et CONSTANTES
2
// PARAMÊTRES et CONSTANTES
3
// Mettre à true pour afficher les messages de débogage
3
// Mettre à true pour afficher les messages de débogage
4
var DEBUG = false; 
4
var DEBUG = false; 
5
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
5
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
6
var pointsOrigine = null;
6
var pointsOrigine = null;
7
var boundsOrigine = null;
7
var boundsOrigine = null;
8
var markerClusterer = null;
8
var markerClusterer = null;
9
var map = null;
9
var map = null;
10
var infoBulle = new google.maps.InfoWindow();
10
var infoBulle = new google.maps.InfoWindow();
11
var pointClique = null;
11
var pointClique = null;
12
var carteCentre = new google.maps.LatLng(46.4, 3.10);
12
var carteCentre = new google.maps.LatLng(46.4, 3.10);
13
var carteOptions = {
13
var carteOptions = {
14
	zoom: 6,
14
	zoom: 6,
15
	mapTypeId: 'OSM',
15
	mapTypeId: 'OSM',
16
	mapTypeControlOptions: {
16
	mapTypeControlOptions: {
17
		mapTypeIds: ['OSM', 
17
		mapTypeIds: ['OSM', 
18
		             google.maps.MapTypeId.ROADMAP, 
18
		             google.maps.MapTypeId.ROADMAP, 
19
		             google.maps.MapTypeId.HYBRID, 
19
		             google.maps.MapTypeId.HYBRID, 
20
		             google.maps.MapTypeId.SATELLITE, 
20
		             google.maps.MapTypeId.SATELLITE, 
21
		             google.maps.MapTypeId.TERRAIN]
21
		             google.maps.MapTypeId.TERRAIN]
22
	},
22
	},
23
	scaleControl: true,
23
	scaleControl: true,
24
	center: carteCentre
24
	center: carteCentre
25
};			
25
};			
26
var ctaLayer = null;
26
var ctaLayer = null;
27
var osmMapType = new google.maps.ImageMapType({
27
var osmMapType = new google.maps.ImageMapType({
28
	getTileUrl: function(coord, zoom) {
28
	getTileUrl: function(coord, zoom) {
29
		return "https://osm.tela-botanica.org/tuiles/osmfr/" + // cache de tuiles avec nginx
29
		return "https://osm.tela-botanica.org/tuiles/osmfr/" + // cache de tuiles avec nginx
30
		zoom + "/" + coord.x + "/" + coord.y + ".png";
30
		zoom + "/" + coord.x + "/" + coord.y + ".png";
31
	},
31
	},
32
	tileSize: new google.maps.Size(256, 256),
32
	tileSize: new google.maps.Size(256, 256),
33
	isPng: true,
33
	isPng: true,
34
	alt: "OpenStreetMap",
34
	alt: "OpenStreetMap",
35
	name: "OSM",
35
	name: "OSM",
36
	maxZoom: 19
36
	maxZoom: 19
37
});
37
});
38
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
38
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
39
var station = {'commune':'', 'obsNbre':0};
39
var station = {'commune':'', 'obsNbre':0};
40
var obsStation = new Array();
40
var obsStation = new Array();
41
var obsPage = new Array();
41
var obsPage = new Array();
42
var taxonsCarte = new Array();
42
var taxonsCarte = new Array();
43
/*+--------------------------------------------------------------------------------------------------------+*/
43
/*+--------------------------------------------------------------------------------------------------------+*/
44
// INITIALISATION DU CODE
44
// INITIALISATION DU CODE
45
 
45
 
46
//Déclenchement d'actions quand JQuery et le document HTML sont OK
46
//Déclenchement d'actions quand JQuery et le document HTML sont OK
47
$(document).ready(function() {
47
$(document).ready(function() {
48
	initialiserWidget();
48
	initialiserWidget();
49
});
49
});
50
 
50
 
51
function initialiserWidget() {
51
function initialiserWidget() {
52
	afficherStats();
52
	afficherStats();
53
	definirTailleTitre();
53
	definirTailleTitre();
54
	initialiserAffichageCarte();
54
	initialiserAffichageCarte();
55
	initialiserAffichagePanneauLateral();
55
	initialiserAffichagePanneauLateral();
56
	
56
	
57
	initialiserCarte();
57
	initialiserCarte();
58
	initialiserInfoBulle();
58
	initialiserInfoBulle();
59
	initialiserFormulaireContact();
59
	initialiserFormulaireContact();
60
	chargerLimitesCommunales();
60
	chargerLimitesCommunales();
61
	rafraichirCarte();
61
	rafraichirCarte();
62
}
62
}
63
 
63
 
64
/*+--------------------------------------------------------------------------------------------------------+*/
64
/*+--------------------------------------------------------------------------------------------------------+*/
65
// AFFICHAGE GÉNÉRAL
65
// AFFICHAGE GÉNÉRAL
66
 
66
 
67
function afficherStats() {
67
function afficherStats() {
68
	if (stations.stats.observations > 0) {
68
	if (stations.stats.observations > 0) {
69
		// Ajout du nombre de communes où des observations ont eu lieu
69
		// Ajout du nombre de communes où des observations ont eu lieu
70
		$('#commune-nbre').text(stations.stats.communes.formaterNombre());
70
		$('#commune-nbre').text(stations.stats.communes.formaterNombre());
71
		// Ajout du nombre d'observations
71
		// Ajout du nombre d'observations
72
		$('#obs-nbre').text(stations.stats.observations.formaterNombre());
72
		$('#obs-nbre').text(stations.stats.observations.formaterNombre());
73
		// affichage du titre
73
		// affichage du titre
74
		$('#titre-decompte').show();
74
		$('#titre-decompte').show();
75
		$('#aucune-obs').hide();
75
		$('#aucune-obs').hide();
76
	} else {
76
	} else {
77
		// masquage du titre
77
		// masquage du titre
78
		$('#titre-decompte').hide();
78
		$('#titre-decompte').hide();
79
		$('#aucune-obs').show();
79
		$('#aucune-obs').show();
80
	}
80
	}
81
}
81
}
82
 
82
 
83
function definirTailleTitre() {
83
function definirTailleTitre() {
84
	var largeurViewPort = $(window).width();
84
	var largeurViewPort = $(window).width();
85
	var taille = null;
85
	var taille = null;
86
	if (largeurViewPort < 400) {
86
	if (largeurViewPort < 400) {
87
		taille = '0.8';
87
		taille = '0.8';
88
	} else if (largeurViewPort >= 400 && largeurViewPort < 800) {
88
	} else if (largeurViewPort >= 400 && largeurViewPort < 800) {
89
		taille = '1.0';
89
		taille = '1.0';
90
	} else if (largeurViewPort >= 800) {
90
	} else if (largeurViewPort >= 800) {
91
		taille = '1.6';
91
		taille = '1.6';
92
	}
92
	}
93
	$("#carte-titre").css('font-size', taille+'em');
93
	$("#carte-titre").css('font-size', taille+'em');
94
}
94
}
95
 
95
 
96
/*+--------------------------------------------------------------------------------------------------------+*/
96
/*+--------------------------------------------------------------------------------------------------------+*/
97
// CARTE
97
// CARTE
98
 
98
 
99
function initialiserAffichageCarte() {
99
function initialiserAffichageCarte() {
100
	$('#carte').height($(window).height() - 35);
100
	$('#carte').height($(window).height() - 35);
101
	$('#carte').width($(window).width() - 24);
101
	$('#carte').width($(window).width() - 24);
102
	
102
	
103
	if (nt != '*') {
103
	if (nt != '*') {
104
		$('#carte').css('left', 0);
104
		$('#carte').css('left', 0);
105
	}
105
	}
106
}
106
}
107
 
107
 
108
function initialiserCarte() {
108
function initialiserCarte() {
109
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
109
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
110
	// Ajout de la couche OSM à la carte
110
	// Ajout de la couche OSM à la carte
111
	map.mapTypes.set('OSM', osmMapType);
111
	map.mapTypes.set('OSM', osmMapType);
112
 
112
 
113
	// écouteur sur changement de fond
113
	// écouteur sur changement de fond
114
	google.maps.event.addListener( map, 'maptypeid_changed', function() { 
114
	google.maps.event.addListener( map, 'maptypeid_changed', function() { 
115
		// licence par défaut
115
		// licence par défaut
116
		var mention = 'Observations du réseau <a href="https://api-botanica.org/site:botanique" ' +
116
		var mention = 'Observations du réseau <a href="https://api-botanica.org/site:botanique" ' +
117
				'onClick="ouvrirNouvelleFenetre(this, event)">' +
117
				'onClick="ouvrirNouvelleFenetre(this, event)">' +
118
				'Tela Botanica' +
118
				'Tela Botanica' +
119
			'</a> ';
119
			'</a> ';
120
		if (map.getMapTypeId() == 'OSM') {
120
		if (map.getMapTypeId() == 'OSM') {
121
			// ajout licence OSM
121
			// ajout licence OSM
122
			mention += ' - Carte : <a href="http://www.openstreetmap.org/copyright" target="_blank">© les contributeurs d’OpenStreetMap</a>' +
122
			mention += ' - Carte : <a href="http://www.openstreetmap.org/copyright" target="_blank">© les contributeurs d’OpenStreetMap</a>' +
123
				' - Tuiles : <a href="http://www.openstreetmap.fr" target="_blank">OsmFr</a>';
123
				' - Tuiles : <a href="http://www.openstreetmap.fr" target="_blank">OsmFr</a>';
124
		}
124
		}
125
		$('#origine-donnees').html(mention);
125
		$('#origine-donnees').html(mention);
126
	});
126
	});
127
}
127
}
128
 
128
 
129
 
129
 
130
function chargerLimitesCommunales() {
130
function chargerLimitesCommunales() {
131
	if (urlsLimitesCommunales != null) {
131
	if (urlsLimitesCommunales != null) {
132
		for (urlId in urlsLimitesCommunales) { 
132
		for (urlId in urlsLimitesCommunales) { 
133
			var url = urlsLimitesCommunales[urlId];
133
			var url = urlsLimitesCommunales[urlId];
134
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
134
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
135
			ctaLayer.setMap(map);
135
			ctaLayer.setMap(map);
136
		}
136
		}
137
	}
137
	}
138
}
138
}
139
 
139
 
140
function rafraichirCarte() {
140
function rafraichirCarte() {
141
	var points = [];
141
	var points = [];
142
	var bounds = new google.maps.LatLngBounds();
142
	var bounds = new google.maps.LatLngBounds();
143
	for (var i = 0; i < stations.stats.communes; ++i) {
143
	for (var i = 0; i < stations.stats.communes; ++i) {
144
		var maLatLng = new google.maps.LatLng(stations.points[i].latitude, stations.points[i].longitude);
144
		var maLatLng = new google.maps.LatLng(stations.points[i].latitude, stations.points[i].longitude);
145
		var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
145
		var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
146
		var point = new google.maps.Marker({
146
		var point = new google.maps.Marker({
147
			position: maLatLng,
147
			position: maLatLng,
148
			map: map,
148
			map: map,
149
			icon: pointImage,
149
			icon: pointImage,
150
			stationId: stations.points[i].id
150
			stationId: stations.points[i].id
151
		});
151
		});
152
 
152
 
153
		bounds.extend(maLatLng);
153
		bounds.extend(maLatLng);
154
		
154
		
155
		google.maps.event.addListener(point, 'click', function() {
155
		google.maps.event.addListener(point, 'click', function() {
156
			pointClique =  this;
156
			pointClique =  this;
157
			infoBulle.open(map, this);
157
			infoBulle.open(map, this);
158
			
158
			
159
			var limites = map.getBounds();
159
			var limites = map.getBounds();
160
			var centre = limites.getCenter();
160
			var centre = limites.getCenter();
161
			var nordEst = limites.getNorthEast();
161
			var nordEst = limites.getNorthEast();
162
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
162
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
163
			map.panTo(centreSudLatLng);
163
			map.panTo(centreSudLatLng);
164
			
164
			
165
			afficherInfoBulle();
165
			afficherInfoBulle();
166
			chargerObs(0, 0);
166
			chargerObs(0, 0);
167
		});
167
		});
168
		
168
		
169
		points.push(point);
169
		points.push(point);
170
	}
170
	}
171
 
171
 
172
	if (pointsOrigine == null && boundsOrigine == null) {
172
	if (pointsOrigine == null && boundsOrigine == null) {
173
		pointsOrigine = points;
173
		pointsOrigine = points;
174
		boundsOrigine = bounds;
174
		boundsOrigine = bounds;
175
	}
175
	}
176
	
176
	
177
	executerMarkerClusterer(points, bounds);
177
	executerMarkerClusterer(points, bounds);
178
}
178
}
179
 
179
 
180
function deplacerCartePointClique() {
180
function deplacerCartePointClique() {
181
	map.panTo(pointClique.position);
181
	map.panTo(pointClique.position);
182
}
182
}
183
 
183
 
184
function executerMarkerClusterer(points, bounds) {
184
function executerMarkerClusterer(points, bounds) {
185
	if (points.length > 0) {
185
	if (points.length > 0) {
186
		if (markerClusterer) {
186
		if (markerClusterer) {
187
			markerClusterer.clearMarkers();
187
			markerClusterer.clearMarkers();
188
		}
188
		}
-
 
189
		var options = {
-
 
190
			imagePath: 'https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m'
-
 
191
		};
189
		markerClusterer = new MarkerClusterer(map, points);
192
		markerClusterer = new MarkerClusterer(map, points, options);
190
		map.fitBounds(bounds);
193
		map.fitBounds(bounds);
191
	}
194
	}
192
}
195
}
193
 
196
 
194
/*+--------------------------------------------------------------------------------------------------------+*/
197
/*+--------------------------------------------------------------------------------------------------------+*/
195
// INFO BULLE
198
// INFO BULLE
196
 
199
 
197
function initialiserInfoBulle() {
200
function initialiserInfoBulle() {
198
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
201
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
199
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
202
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
200
}
203
}
201
 
204
 
202
function afficherInfoBulle() {
205
function afficherInfoBulle() {
203
	var obsHtml = $("#tpl-obs").html();
206
	var obsHtml = $("#tpl-obs").html();
204
	var largeur = definirLargeurInfoBulle();
207
	var largeur = definirLargeurInfoBulle();
205
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
208
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
206
	infoBulle.setContent(obsHtml);
209
	infoBulle.setContent(obsHtml);
207
}
210
}
208
 
211
 
209
function definirLargeurInfoBulle() {
212
function definirLargeurInfoBulle() {
210
	var largeurViewPort = $(window).width();
213
	var largeurViewPort = $(window).width();
211
	var lageurInfoBulle = null;
214
	var lageurInfoBulle = null;
212
	if (largeurViewPort < 800) {
215
	if (largeurViewPort < 800) {
213
		largeurInfoBulle = 400;
216
		largeurInfoBulle = 400;
214
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
217
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
215
		largeurInfoBulle = 500;
218
		largeurInfoBulle = 500;
216
	} else if (largeurViewPort >= 1200) {
219
	} else if (largeurViewPort >= 1200) {
217
		largeurInfoBulle = 600;
220
		largeurInfoBulle = 600;
218
	}
221
	}
219
	return largeurInfoBulle;
222
	return largeurInfoBulle;
220
}
223
}
221
 
224
 
222
function afficherMessageChargement(element) {
225
function afficherMessageChargement(element) {
223
	if ($('#chargement').get() == '') {
226
	if ($('#chargement').get() == '') {
224
		$('#tpl-chargement').tmpl().appendTo(element);
227
		$('#tpl-chargement').tmpl().appendTo(element);
225
	}
228
	}
226
}
229
}
227
 
230
 
228
function supprimerMessageChargement() {
231
function supprimerMessageChargement() {
229
	$('#chargement').remove();
232
	$('#chargement').remove();
230
}
233
}
231
 
234
 
232
function chargerObs(depart, total) {
235
function chargerObs(depart, total) {
233
	if (depart == 0 || depart < total) {
236
	if (depart == 0 || depart < total) {
234
		var limite = 300;
237
		var limite = 300;
235
		if (depart == 0) {
238
		if (depart == 0) {
236
			obsStation = new Array();
239
			obsStation = new Array();
237
		}
240
		}
238
		//console.log("Chargement de "+depart+" à "+(depart+limite));
241
		//console.log("Chargement de "+depart+" à "+(depart+limite));
239
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
242
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
240
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
243
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
241
		urlObs = urlObs.replace(/\{nt\}/g, nt);
244
		urlObs = urlObs.replace(/\{nt\}/g, nt);
242
		urlObs = urlObs.replace(/\{start\}/g, depart);
245
		urlObs = urlObs.replace(/\{start\}/g, depart);
243
		
246
		
244
		$.getJSON(urlObs, function(observations){
247
		$.getJSON(urlObs, function(observations){
245
			obsStation = obsStation.concat(observations.observations);
248
			obsStation = obsStation.concat(observations.observations);
246
			if (depart == 0) {
249
			if (depart == 0) {
247
				actualiserInfosStation(observations);
250
				actualiserInfosStation(observations);
248
				actualiserPagineur();
251
				actualiserPagineur();
249
				creerTitreInfoBulle();
252
				creerTitreInfoBulle();
250
			}
253
			}
251
			//console.log("Chargement ok");
254
			//console.log("Chargement ok");
252
			chargerObs(depart+limite, station.obsNbre);
255
			chargerObs(depart+limite, station.obsNbre);
253
		});
256
		});
254
	} else {
257
	} else {
255
		if (pagineur.limite < total) {
258
		if (pagineur.limite < total) {
256
			afficherPagination();
259
			afficherPagination();
257
		} else {
260
		} else {
258
			surClicPagePagination(0, null);
261
			surClicPagePagination(0, null);
259
			selectionnerOnglet("#obs-vue-"+pagineur.format);
262
			selectionnerOnglet("#obs-vue-"+pagineur.format);
260
		}
263
		}
261
	}
264
	}
262
}
265
}
263
 
266
 
264
function actualiserInfosStation(infos) {
267
function actualiserInfosStation(infos) {
265
	station.commune = infos.commune;
268
	station.commune = infos.commune;
266
	station.obsNbre = infos.total;
269
	station.obsNbre = infos.total;
267
}
270
}
268
 
271
 
269
function actualiserPagineur() {
272
function actualiserPagineur() {
270
	pagineur.stationId = pointClique.stationId;
273
	pagineur.stationId = pointClique.stationId;
271
	pagineur.total = station.obsNbre;
274
	pagineur.total = station.obsNbre;
272
	//console.log("Total pagineur: "+pagineur.total);
275
	//console.log("Total pagineur: "+pagineur.total);
273
	if (pagineur.total > 4) {
276
	if (pagineur.total > 4) {
274
		pagineur.format = 'tableau';
277
		pagineur.format = 'tableau';
275
	} else {
278
	} else {
276
		pagineur.format = 'liste';
279
		pagineur.format = 'liste';
277
	}
280
	}
278
}
281
}
279
 
282
 
280
function afficherPagination(observations) {
283
function afficherPagination(observations) {
281
	$(".navigation").pagination(pagineur.total, {
284
	$(".navigation").pagination(pagineur.total, {
282
		items_per_page:pagineur.limite,
285
		items_per_page:pagineur.limite,
283
		callback:surClicPagePagination,
286
		callback:surClicPagePagination,
284
		next_text:'Suivant',
287
		next_text:'Suivant',
285
		prev_text:'Précédent',
288
		prev_text:'Précédent',
286
		prev_show_always:false,
289
		prev_show_always:false,
287
		num_edge_entries:1,
290
		num_edge_entries:1,
288
		num_display_entries:4,
291
		num_display_entries:4,
289
		load_first_page:true
292
		load_first_page:true
290
	});
293
	});
291
}
294
}
292
 
295
 
293
function surClicPagePagination(pageIndex, paginationConteneur) {
296
function surClicPagePagination(pageIndex, paginationConteneur) {
294
	var index = pageIndex * pagineur.limite;
297
	var index = pageIndex * pagineur.limite;
295
	var indexMax = index + pagineur.limite;
298
	var indexMax = index + pagineur.limite;
296
	pagineur.depart = index;
299
	pagineur.depart = index;
297
	obsPage = new Array();
300
	obsPage = new Array();
298
    for(index; index < indexMax; index++) {
301
    for(index; index < indexMax; index++) {
299
    	obsPage.push(obsStation[index]);
302
    	obsPage.push(obsStation[index]);
300
    }
303
    }
301
    
304
    
302
    supprimerMessageChargement();
305
    supprimerMessageChargement();
303
    mettreAJourObservations();
306
    mettreAJourObservations();
304
	return false;
307
	return false;
305
}
308
}
306
 
309
 
307
function mettreAJourObservations() {
310
function mettreAJourObservations() {
308
	$("#obs-"+pagineur.format+"-lignes").empty();
311
	$("#obs-"+pagineur.format+"-lignes").empty();
309
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
312
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
310
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
313
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
311
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
314
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
312
	
315
	
313
	// Actualisation de Fancybox
316
	// Actualisation de Fancybox
314
	ajouterFomulaireContact("a.contact");
317
	ajouterFomulaireContact("a.contact");
315
	if (pagineur.format == 'liste') {
318
	if (pagineur.format == 'liste') {
316
		ajouterGaleriePhoto("a.cel-img");
319
		ajouterGaleriePhoto("a.cel-img");
317
	}
320
	}
318
}
321
}
319
 
322
 
320
function creerTitreInfoBulle() {
323
function creerTitreInfoBulle() {
321
	$("#obs-total").text(station.obsNbre);
324
	$("#obs-total").text(station.obsNbre);
322
	$("#obs-commune").text(station.commune);	
325
	$("#obs-commune").text(station.commune);	
323
}
326
}
324
 
327
 
325
function initialiserContenuInfoBulle() {
328
function initialiserContenuInfoBulle() {
326
	afficherOnglets();
329
	afficherOnglets();
327
	afficherMessageChargement('#observations');
330
	afficherMessageChargement('#observations');
328
	ajouterTableauTriable("#obs-tableau");
331
	ajouterTableauTriable("#obs-tableau");
329
	afficherTextStationId();
332
	afficherTextStationId();
330
	corrigerLargeurInfoWindow();
333
	corrigerLargeurInfoWindow();
331
}
334
}
332
 
335
 
333
function afficherOnglets() {
336
function afficherOnglets() {
334
	var $tabs = $('#obs').tabs();
337
	var $tabs = $('#obs').tabs();
335
	$('#obs').bind('tabsselect', function(event, ui) {
338
	$('#obs').bind('tabsselect', function(event, ui) {
336
		if (ui.panel.id == 'obs-vue-tableau') {
339
		if (ui.panel.id == 'obs-vue-tableau') {
337
			surClicAffichageTableau();
340
			surClicAffichageTableau();
338
		} else if (ui.panel.id == 'obs-vue-liste') {
341
		} else if (ui.panel.id == 'obs-vue-liste') {
339
			surClicAffichageListe();
342
			surClicAffichageListe();
340
		}
343
		}
341
	});
344
	});
342
	$tabs.tabs('select', "#obs-vue-"+pagineur.format);
345
	$tabs.tabs('select', "#obs-vue-"+pagineur.format);
343
}
346
}
344
 
347
 
345
function selectionnerOnglet(onglet) {
348
function selectionnerOnglet(onglet) {
346
	$('#obs').tabs('select', onglet);
349
	$('#obs').tabs('select', onglet);
347
}
350
}
348
 
351
 
349
function afficherTextStationId() {
352
function afficherTextStationId() {
350
	$('#obs-station-id').text(pointClique.stationId);
353
	$('#obs-station-id').text(pointClique.stationId);
351
}
354
}
352
 
355
 
353
function corrigerLargeurInfoWindow() {
356
function corrigerLargeurInfoWindow() {
354
	$("#info-bulle").width($("#info-bulle").width() - 17);
357
	$("#info-bulle").width($("#info-bulle").width() - 17);
355
}
358
}
356
 
359
 
357
function surClicAffichageTableau(event) {
360
function surClicAffichageTableau(event) {
358
	//console.log('tableau');
361
	//console.log('tableau');
359
	pagineur.format = 'tableau';
362
	pagineur.format = 'tableau';
360
	mettreAJourObservations();
363
	mettreAJourObservations();
361
	mettreAJourTableauTriable("#obs-tableau");
364
	mettreAJourTableauTriable("#obs-tableau");
362
}
365
}
363
 
366
 
364
function surClicAffichageListe(event) {
367
function surClicAffichageListe(event) {
365
	//console.log('liste');
368
	//console.log('liste');
366
	pagineur.format = 'liste';
369
	pagineur.format = 'liste';
367
	mettreAJourObservations();
370
	mettreAJourObservations();
368
	ajouterGaleriePhoto("a.cel-img");
371
	ajouterGaleriePhoto("a.cel-img");
369
}
372
}
370
 
373
 
371
function ajouterTableauTriable(element) {
374
function ajouterTableauTriable(element) {
372
	// add parser through the tablesorter addParser method 
375
	// add parser through the tablesorter addParser method 
373
	$.tablesorter.addParser({ 
376
	$.tablesorter.addParser({ 
374
		// Définition d'un id unique pour ce parsseur 
377
		// Définition d'un id unique pour ce parsseur 
375
		id: 'date_cel', 
378
		id: 'date_cel', 
376
		is: function(s) { 
379
		is: function(s) { 
377
			// doit retourner false si le parsseur n'est pas autodétecté
380
			// doit retourner false si le parsseur n'est pas autodétecté
378
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
381
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
379
		}, 
382
		}, 
380
		format: function(date) { 
383
		format: function(date) { 
381
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
384
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
382
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
385
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
383
			// Remplace la date par un nombre de millisecondes pour trier numériquement
386
			// Remplace la date par un nombre de millisecondes pour trier numériquement
384
			return $.tablesorter.formatFloat(new Date(date).getTime());
387
			return $.tablesorter.formatFloat(new Date(date).getTime());
385
		}, 
388
		}, 
386
		// set type, either numeric or text 
389
		// set type, either numeric or text 
387
		type: 'numeric' 
390
		type: 'numeric' 
388
	});
391
	});
389
	$(element).tablesorter({ 
392
	$(element).tablesorter({ 
390
        headers: { 
393
        headers: { 
391
			1: { 
394
			1: { 
392
            	sorter:'date_cel' 
395
            	sorter:'date_cel' 
393
        	} 
396
        	} 
394
    	} 
397
    	} 
395
	});
398
	});
396
}
399
}
397
 
400
 
398
function mettreAJourTableauTriable(element) {
401
function mettreAJourTableauTriable(element) {
399
	$(element).trigger('update');
402
	$(element).trigger('update');
400
}
403
}
401
 
404
 
402
function ajouterGaleriePhoto(element) {
405
function ajouterGaleriePhoto(element) {
403
	$(element).fancybox({
406
	$(element).fancybox({
404
		transitionIn:'elastic',
407
		transitionIn:'elastic',
405
		transitionOut:'elastic',
408
		transitionOut:'elastic',
406
		speedIn	:600, 
409
		speedIn	:600, 
407
		speedOut:200,
410
		speedOut:200,
408
		overlayShow:true,
411
		overlayShow:true,
409
		titleShow:true,
412
		titleShow:true,
410
		titlePosition:'inside',
413
		titlePosition:'inside',
411
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
414
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
412
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
415
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
413
			motif.exec(titre);
416
			motif.exec(titre);
414
			var id = RegExp.$1;
417
			var id = RegExp.$1;
415
			var info = $('#cel-info-'+id).clone().html();
418
			var info = $('#cel-info-'+id).clone().html();
416
			var tpl = 
419
			var tpl = 
417
				'<div class="cel-legende">'+
420
				'<div class="cel-legende">'+
418
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
421
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
419
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
422
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
420
				'<\/div>';
423
				'<\/div>';
421
			return tpl;
424
			return tpl;
422
		}
425
		}
423
		}).live('click', function(e) {
426
		}).live('click', function(e) {
424
			if (e.stopPropagation) {
427
			if (e.stopPropagation) {
425
				e.stopPropagation();
428
				e.stopPropagation();
426
			}
429
			}
427
			return false;
430
			return false;
428
		});
431
		});
429
}
432
}
430
 
433
 
431
function ajouterFomulaireContact(element) {
434
function ajouterFomulaireContact(element) {
432
	$(element).fancybox({
435
	$(element).fancybox({
433
		transitionIn:'elastic',
436
		transitionIn:'elastic',
434
		transitionOut:'elastic',
437
		transitionOut:'elastic',
435
		speedIn	:600, 
438
		speedIn	:600, 
436
		speedOut:200,
439
		speedOut:200,
437
		scrolling: 'no',
440
		scrolling: 'no',
438
		titleShow: false,
441
		titleShow: false,
439
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
442
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
440
			var element = selectedArray[selectedIndex];
443
			var element = selectedArray[selectedIndex];
441
 
444
 
442
			var motif = / contributeur-([0-9]+)$/;
445
			var motif = / contributeur-([0-9]+)$/;
443
			motif.exec($(element).attr('class'));
446
			motif.exec($(element).attr('class'));
444
			var id = RegExp.$1;
447
			var id = RegExp.$1;
445
			//console.log('Destinataire id : '+id);
448
			//console.log('Destinataire id : '+id);
446
			$("#fc_destinataire_id").attr('value', id);
449
			$("#fc_destinataire_id").attr('value', id);
447
		
450
		
448
			var motif = / obs-([0-9]+) /;
451
			var motif = / obs-([0-9]+) /;
449
			motif.exec($(element).attr('class'));
452
			motif.exec($(element).attr('class'));
450
			var id = RegExp.$1;
453
			var id = RegExp.$1;
451
			//console.log('Obs id : '+id);
454
			//console.log('Obs id : '+id);
452
			chargerInfoObsPourMessage(id);
455
			chargerInfoObsPourMessage(id);
453
		},
456
		},
454
		onCleanup: function() {
457
		onCleanup: function() {
455
			//console.log('Avant fermeture fancybox');
458
			//console.log('Avant fermeture fancybox');
456
			$("#fc_destinataire_id").attr('value', '');
459
			$("#fc_destinataire_id").attr('value', '');
457
			$("#fc_sujet").attr('value', '');
460
			$("#fc_sujet").attr('value', '');
458
			$("#fc_message").text('');
461
			$("#fc_message").text('');
459
		},
462
		},
460
		onClosed: function(e) {
463
		onClosed: function(e) {
461
			//console.log('Fermeture fancybox');
464
			//console.log('Fermeture fancybox');
462
			if (e.stopPropagation) {
465
			if (e.stopPropagation) {
463
				e.stopPropagation();
466
				e.stopPropagation();
464
			}
467
			}
465
			return false;
468
			return false;
466
		}
469
		}
467
	});
470
	});
468
}
471
}
469
 
472
 
470
function chargerInfoObsPourMessage(idObs) {
473
function chargerInfoObsPourMessage(idObs) {
471
	var nomSci = trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
474
	var nomSci = trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
472
	var date = trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
475
	var date = trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
473
	var lieu = trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
476
	var lieu = trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
474
	var sujet = "Observation #"+idObs+" de "+nomSci;
477
	var sujet = "Observation #"+idObs+" de "+nomSci;
475
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
478
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
476
	$("#fc_sujet").attr('value', sujet);
479
	$("#fc_sujet").attr('value', sujet);
477
	$("#fc_message").text(message);
480
	$("#fc_message").text(message);
478
}
481
}
479
 
482
 
480
function initialiserFormulaireContact() {
483
function initialiserFormulaireContact() {
481
	//console.log('Initialisation du form contact');
484
	//console.log('Initialisation du form contact');
482
	$("#form-contact").validate({
485
	$("#form-contact").validate({
483
		rules: {
486
		rules: {
484
			fc_sujet : "required",
487
			fc_sujet : "required",
485
			fc_message : "required",
488
			fc_message : "required",
486
			fc_utilisateur_courriel : {
489
			fc_utilisateur_courriel : {
487
				required : true,
490
				required : true,
488
				email : true}
491
				email : true}
489
		}
492
		}
490
	});
493
	});
491
	$("#form-contact").bind("submit", envoyerCourriel);
494
	$("#form-contact").bind("submit", envoyerCourriel);
492
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
495
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
493
	
496
	
494
}
497
}
495
 
498
 
496
function envoyerCourriel() {
499
function envoyerCourriel() {
497
	//console.log('Formulaire soumis');
500
	//console.log('Formulaire soumis');
498
	if ($("#form-contact").valid()) {
501
	if ($("#form-contact").valid()) {
499
		//console.log('Formulaire valide');
502
		//console.log('Formulaire valide');
500
		//$.fancybox.showActivity();
503
		//$.fancybox.showActivity();
501
		var destinataireId = $("#fc_destinataire_id").attr('value');
504
		var destinataireId = $("#fc_destinataire_id").attr('value');
502
		var urlMessage = "https://api-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
505
		var urlMessage = "https://api-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
503
		var erreurMsg = "";
506
		var erreurMsg = "";
504
		var donnees = new Array();
507
		var donnees = new Array();
505
		$.each($(this).serializeArray(), function (index, champ) {
508
		$.each($(this).serializeArray(), function (index, champ) {
506
			var cle = champ.name;
509
			var cle = champ.name;
507
			cle = cle.replace(/^fc_/, '');
510
			cle = cle.replace(/^fc_/, '');
508
			
511
			
509
			if (cle == 'sujet') {
512
			if (cle == 'sujet') {
510
				champ.value += " - Carnet en ligne - Tela Botanica";
513
				champ.value += " - Carnet en ligne - Tela Botanica";
511
			}
514
			}
512
			if (cle == 'message') {
515
			if (cle == 'message') {
513
				champ.value += "\n--\n"+
516
				champ.value += "\n--\n"+
514
					"Ce message vous est envoyé par l'intermédiaire du widget Cartographique "+
517
					"Ce message vous est envoyé par l'intermédiaire du widget Cartographique "+
515
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
518
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
516
					"https://api-botanica.org/widget:cel:carto";
519
					"https://api-botanica.org/widget:cel:carto";
517
			}
520
			}
518
			
521
			
519
			donnees[index] = {'name':cle,'value':champ.value};
522
			donnees[index] = {'name':cle,'value':champ.value};
520
		});
523
		});
521
		$.ajax({
524
		$.ajax({
522
			type : "POST",
525
			type : "POST",
523
			cache : false,
526
			cache : false,
524
			url : urlMessage,
527
			url : urlMessage,
525
			data : donnees,
528
			data : donnees,
526
			beforeSend : function() {
529
			beforeSend : function() {
527
				$(".msg").remove();
530
				$(".msg").remove();
528
			},
531
			},
529
			success : function(data) {
532
			success : function(data) {
530
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
533
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
531
			},
534
			},
532
			error : function(jqXHR, textStatus, errorThrown) {
535
			error : function(jqXHR, textStatus, errorThrown) {
533
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
536
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
534
				reponse = jQuery.parseJSON(jqXHR.responseText);
537
				reponse = jQuery.parseJSON(jqXHR.responseText);
535
				if (reponse != null) {
538
				if (reponse != null) {
536
					$.each(reponse, function (cle, valeur) {
539
					$.each(reponse, function (cle, valeur) {
537
						erreurMsg += valeur + "\n";
540
						erreurMsg += valeur + "\n";
538
					});
541
					});
539
				}				
542
				}				
540
			},
543
			},
541
			complete : function(jqXHR, textStatus) {
544
			complete : function(jqXHR, textStatus) {
542
				var debugMsg = '';
545
				var debugMsg = '';
543
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
546
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
544
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
547
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
545
					if (debugInfos != null) {
548
					if (debugInfos != null) {
546
						$.each(debugInfos, function (cle, valeur) {
549
						$.each(debugInfos, function (cle, valeur) {
547
							debugMsg += valeur + "\n";
550
							debugMsg += valeur + "\n";
548
						});
551
						});
549
					}
552
					}
550
				}
553
				}
551
				if (erreurMsg != '') {
554
				if (erreurMsg != '') {
552
					$("#fc-zone-dialogue").append('<p class="msg">'+
555
					$("#fc-zone-dialogue").append('<p class="msg">'+
553
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
556
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
554
							'Vous pouvez signaler le disfonctionnement à <a href="'+
557
							'Vous pouvez signaler le disfonctionnement à <a href="'+
555
							'mailto:cel@tela-botanica.org'+'?'+
558
							'mailto:cel@tela-botanica.org'+'?'+
556
							'subject=Disfonctionnement du widget de Cartographie'+
559
							'subject=Disfonctionnement du widget de Cartographie'+
557
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
560
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
558
							'">cel@tela-botanica.org</a>.'+
561
							'">cel@tela-botanica.org</a>.'+
559
							'</p>');
562
							'</p>');
560
				}
563
				}
561
				if (DEBUG) {
564
				if (DEBUG) {
562
					console.log('Débogage : '+debugMsg);
565
					console.log('Débogage : '+debugMsg);
563
				}
566
				}
564
				//console.log('Débogage : '+debugMsg);
567
				//console.log('Débogage : '+debugMsg);
565
				//console.log('Erreur : '+erreurMsg);
568
				//console.log('Erreur : '+erreurMsg);
566
			}
569
			}
567
		});
570
		});
568
	}
571
	}
569
	return false;
572
	return false;
570
}
573
}
571
/*+--------------------------------------------------------------------------------------------------------+*/
574
/*+--------------------------------------------------------------------------------------------------------+*/
572
// PANNEAU LATÉRAL
575
// PANNEAU LATÉRAL
573
 
576
 
574
function initialiserAffichagePanneauLateral() {
577
function initialiserAffichagePanneauLateral() {
575
	$('#panneau-lateral').height($(window).height() - 35);
578
	$('#panneau-lateral').height($(window).height() - 35);
576
	
579
	
577
	if (nt == '*') {
580
	if (nt == '*') {
578
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
581
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
579
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
582
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
580
	}
583
	}
581
	chargerTaxons(0, 0);
584
	chargerTaxons(0, 0);
582
}
585
}
583
 
586
 
584
function chargerTaxons(depart, total) {
587
function chargerTaxons(depart, total) {
585
	if (depart == 0 || depart < total) {
588
	if (depart == 0 || depart < total) {
586
		var limite = 7000;
589
		var limite = 7000;
587
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
590
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
588
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
591
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
589
		urlTax = urlTax.replace(/\{start\}/g, depart);
592
		urlTax = urlTax.replace(/\{start\}/g, depart);
590
		$.getJSON(urlTax, function(infos) {
593
		$.getJSON(urlTax, function(infos) {
591
			taxonsCarte = taxonsCarte.concat(infos.taxons);
594
			taxonsCarte = taxonsCarte.concat(infos.taxons);
592
			//console.log("Nbre taxons :"+taxonsCarte.length);
595
			//console.log("Nbre taxons :"+taxonsCarte.length);
593
			chargerTaxons(depart+limite, infos.total);
596
			chargerTaxons(depart+limite, infos.total);
594
		});
597
		});
595
	} else {
598
	} else {
596
		if (nt == '*') {
599
		if (nt == '*') {
597
			afficherTaxons();
600
			afficherTaxons();
598
		} else {
601
		} else {
599
			afficherNomPlante();
602
			afficherNomPlante();
600
		}
603
		}
601
	}
604
	}
602
}
605
}
603
 
606
 
604
function afficherTaxons() {
607
function afficherTaxons() {
605
	// Ajout du nombre de plantes au titre
608
	// Ajout du nombre de plantes au titre
606
	$('.plantes-nbre').text(taxonsCarte.length.formaterNombre());
609
	$('.plantes-nbre').text(taxonsCarte.length.formaterNombre());
607
	
610
	
608
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
611
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
609
	$('.taxon').live('click', filtrerParTaxon);
612
	$('.taxon').live('click', filtrerParTaxon);
610
}
613
}
611
 
614
 
612
function afficherNomPlante() {
615
function afficherNomPlante() {
613
	if (nt != '*') {
616
	if (nt != '*') {
614
		var taxon = taxonsCarte[0];
617
		var taxon = taxonsCarte[0];
615
		$('.plante-titre').text('pour '+taxon.nom);
618
		$('.plante-titre').text('pour '+taxon.nom);
616
	}
619
	}
617
}
620
}
618
 
621
 
619
function afficherPanneauLateral() {
622
function afficherPanneauLateral() {
620
	$('#panneau-lateral').width(300);
623
	$('#panneau-lateral').width(300);
621
	$('#pl-contenu').css('display', 'block');
624
	$('#pl-contenu').css('display', 'block');
622
	$('#pl-ouverture').css('display', 'none');
625
	$('#pl-ouverture').css('display', 'none');
623
	$('#pl-fermeture').css('display', 'block');
626
	$('#pl-fermeture').css('display', 'block');
624
	$('#carte').css('left', '300px');
627
	$('#carte').css('left', '300px');
625
 
628
 
626
	google.maps.event.trigger(map, 'resize');
629
	google.maps.event.trigger(map, 'resize');
627
};
630
};
628
 
631
 
629
function cacherPanneauLateral() {
632
function cacherPanneauLateral() {
630
	$('#panneau-lateral').width(24);
633
	$('#panneau-lateral').width(24);
631
	$('#pl-contenu').css('display', 'none');
634
	$('#pl-contenu').css('display', 'none');
632
	$('#pl-ouverture').css('display', 'block');
635
	$('#pl-ouverture').css('display', 'block');
633
	$('#pl-fermeture').css('display', 'none');
636
	$('#pl-fermeture').css('display', 'none');
634
	$('#carte').css('left', '24px');
637
	$('#carte').css('left', '24px');
635
	
638
	
636
	google.maps.event.trigger(map, 'resize');
639
	google.maps.event.trigger(map, 'resize');
637
};
640
};
638
 
641
 
639
function ouvrirPopUp(url, nom) {
642
function ouvrirPopUp(url, nom) {
640
	window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
643
	window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
641
};
644
};
642
 
645
 
643
function filtrerParTaxon() {
646
function filtrerParTaxon() {
644
	var ntAFiltrer = $('.nt', this).text();
647
	var ntAFiltrer = $('.nt', this).text();
645
	infoBulle.close();
648
	infoBulle.close();
646
	$('#taxon-'+nt).removeClass('taxon-actif');
649
	$('#taxon-'+nt).removeClass('taxon-actif');
647
	if (nt == ntAFiltrer) {
650
	if (nt == ntAFiltrer) {
648
		nt = '*';
651
		nt = '*';
649
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
652
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
650
	} else {
653
	} else {
651
		var url = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer)+
654
		var url = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer)+
652
			'&formatRetour=jsonP'+
655
			'&formatRetour=jsonP'+
653
			'&callback=?';
656
			'&callback=?';
654
		$.getJSON(url, function (stationsFiltrees) {
657
		$.getJSON(url, function (stationsFiltrees) {
655
			stations = stationsFiltrees;
658
			stations = stationsFiltrees;
656
			nt = ntAFiltrer;
659
			nt = ntAFiltrer;
657
			$('#taxon-'+nt).addClass('taxon-actif');
660
			$('#taxon-'+nt).addClass('taxon-actif');
658
			rafraichirCarte();
661
			rafraichirCarte();
659
		});
662
		});
660
	}
663
	}
661
};
664
};
662
 
665
 
663
/*+--------------------------------------------------------------------------------------------------------+*/
666
/*+--------------------------------------------------------------------------------------------------------+*/
664
// FONCTIONS UTILITAIRES
667
// FONCTIONS UTILITAIRES
665
 
668
 
666
function arreter(event) {
669
function arreter(event) {
667
	if (event.stopPropagation) {
670
	if (event.stopPropagation) {
668
		event.stopPropagation();
671
		event.stopPropagation();
669
	} else if (window.event) {
672
	} else if (window.event) {
670
		window.event.cancelBubble = true;
673
		window.event.cancelBubble = true;
671
	}
674
	}
672
	return false;
675
	return false;
673
}
676
}
674
 
677
 
675
/**
678
/**
676
 * +-------------------------------------+
679
 * +-------------------------------------+
677
 * Number.prototype.formaterNombre
680
 * Number.prototype.formaterNombre
678
 * +-------------------------------------+
681
 * +-------------------------------------+
679
 * Params (facultatifs):
682
 * Params (facultatifs):
680
 * - Int decimales: nombre de decimales (exemple: 2)
683
 * - Int decimales: nombre de decimales (exemple: 2)
681
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
684
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
682
 * - String separateurMilliers: comme son nom l'indique
685
 * - String separateurMilliers: comme son nom l'indique
683
 * Returns:
686
 * Returns:
684
 * - String chaine formatee
687
 * - String chaine formatee
685
 * @author	::mastahbenus::
688
 * @author	::mastahbenus::
686
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
689
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
687
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
690
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
688
 */
691
 */
689
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
692
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
690
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
693
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
691
	
694
	
692
	function is_int(nbre) {
695
	function is_int(nbre) {
693
		nbre = nbre.replace(',', '.');
696
		nbre = nbre.replace(',', '.');
694
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
697
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
695
	}
698
	}
696
 
699
 
697
	if (decimales == undefined) {
700
	if (decimales == undefined) {
698
		if (is_int(_sNombre)) {
701
		if (is_int(_sNombre)) {
699
			decimales = 0;
702
			decimales = 0;
700
		} else {
703
		} else {
701
			decimales = 2;
704
			decimales = 2;
702
		}
705
		}
703
	}
706
	}
704
	if (signe == undefined) {
707
	if (signe == undefined) {
705
		if (is_int(_sNombre)) {
708
		if (is_int(_sNombre)) {
706
			signe = '';
709
			signe = '';
707
		} else {
710
		} else {
708
			signe = '.';
711
			signe = '.';
709
		}
712
		}
710
	}
713
	}
711
	if (separateurMilliers == undefined) {
714
	if (separateurMilliers == undefined) {
712
		separateurMilliers = ' ';
715
		separateurMilliers = ' ';
713
	}
716
	}
714
	
717
	
715
	function separeMilliers (sNombre) {
718
	function separeMilliers (sNombre) {
716
		var sRetour = "";
719
		var sRetour = "";
717
		while (sNombre.length % 3 != 0) {
720
		while (sNombre.length % 3 != 0) {
718
			sNombre = "0"+sNombre;
721
			sNombre = "0"+sNombre;
719
		}
722
		}
720
		for (i = 0; i < sNombre.length; i += 3) {
723
		for (i = 0; i < sNombre.length; i += 3) {
721
			if (i == sNombre.length-1) separateurMilliers = '';
724
			if (i == sNombre.length-1) separateurMilliers = '';
722
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
725
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
723
		}
726
		}
724
		while (sRetour.substr(0, 1) == "0") {
727
		while (sRetour.substr(0, 1) == "0") {
725
			sRetour = sRetour.substr(1);
728
			sRetour = sRetour.substr(1);
726
		}
729
		}
727
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
730
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
728
	}
731
	}
729
	
732
	
730
	if (_sNombre.indexOf('.') == -1) {
733
	if (_sNombre.indexOf('.') == -1) {
731
		for (i = 0; i < decimales; i++) {
734
		for (i = 0; i < decimales; i++) {
732
			_sDecimales += "0";
735
			_sDecimales += "0";
733
		}
736
		}
734
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
737
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
735
	} else {
738
	} else {
736
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
739
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
737
		if (sDecimalesTmp.length > decimales) {
740
		if (sDecimalesTmp.length > decimales) {
738
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
741
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
739
			var nDiv = 1;
742
			var nDiv = 1;
740
			for (i = 0; i < nDecimalesManquantes; i++) {
743
			for (i = 0; i < nDecimalesManquantes; i++) {
741
				nDiv *= 10;
744
				nDiv *= 10;
742
			}
745
			}
743
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
746
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
744
		}
747
		}
745
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
748
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
746
	}
749
	}
747
	return _sRetour;
750
	return _sRetour;
748
}
751
}
749
 
752
 
750
function debug(objet) {
753
function debug(objet) {
751
	var msg = '';
754
	var msg = '';
752
	if (objet != null) {
755
	if (objet != null) {
753
		$.each(objet, function (cle, valeur) {
756
		$.each(objet, function (cle, valeur) {
754
			msg += cle+":"+valeur + "\n";
757
			msg += cle+":"+valeur + "\n";
755
		});
758
		});
756
	} else {
759
	} else {
757
		msg = "La variable vaut null.";
760
		msg = "La variable vaut null.";
758
	}
761
	}
759
	console.log(msg);
762
	console.log(msg);
760
}
763
}
761
 
764
 
762
function trim (chaine) {
765
function trim (chaine) {
763
	return chaine.replace(/^\s+/g, '').replace(/\s+$/g, '');
766
	return chaine.replace(/^\s+/g, '').replace(/\s+$/g, '');
764
}
767
}