Subversion Repositories eFlore/Applications.cel

Rev

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