Subversion Repositories eFlore/Applications.cel

Rev

Rev 2323 | Rev 2520 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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