Subversion Repositories eFlore/Applications.cel

Rev

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

Rev Author Line No. Line
836 jpm 1
/*+--------------------------------------------------------------------------------------------------------+*/
2
// PARAMÊTRES et CONSTANTES
941 jpm 3
// Mettre à true pour afficher les messages de débogage
950 jpm 4
var DEBUG = false;
1041 aurelien 5
/**
6
 * Indication de certaines variables ajoutée par php
7
* var communeImageUrl ;
8
* var pointImageUrl ;
9
* var groupeImageUrlTpl ;
10
*/
836 jpm 11
var pointsOrigine = null;
12
var boundsOrigine = null;
13
var markerClusterer = null;
14
var map = null;
15
var infoBulle = new google.maps.InfoWindow();
980 jpm 16
var stations = null;
836 jpm 17
var pointClique = null;
980 jpm 18
var carteCentre = new google.maps.LatLng(25, 10);
836 jpm 19
var carteOptions = {
980 jpm 20
	zoom: 3,
21
	center:carteCentre,
836 jpm 22
	mapTypeId: google.maps.MapTypeId.ROADMAP,
23
	mapTypeControlOptions: {
24
		mapTypeIds: ['OSM',
25
		             google.maps.MapTypeId.ROADMAP,
26
		             google.maps.MapTypeId.HYBRID,
27
		             google.maps.MapTypeId.SATELLITE,
28
		             google.maps.MapTypeId.TERRAIN]
1438 aurelien 29
	},
30
	zoomControlOptions: {
31
        style: google.maps.ZoomControlStyle.LARGE,
32
        position: google.maps.ControlPosition.LEFT_CENTER
33
    },
34
    panControl: false
836 jpm 35
};
36
var osmMapType = new google.maps.ImageMapType({
37
	getTileUrl: function(coord, zoom) {
38
		return "http://tile.openstreetmap.org/" +
39
		zoom + "/" + coord.x + "/" + coord.y + ".png";
40
	},
41
	tileSize: new google.maps.Size(256, 256),
42
	isPng: true,
43
	alt: "OpenStreetMap",
44
	name: "OSM",
45
	maxZoom: 19
46
});
980 jpm 47
var ctaLayer = null;
1271 aurelien 48
var pagineur = {'limite':300, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
915 jpm 49
var station = {'commune':'', 'obsNbre':0};
50
var obsStation = new Array();
51
var obsPage = new Array();
939 jpm 52
var taxonsCarte = new Array();
980 jpm 53
var mgr = null;
54
var marqueursCache = new Array();
55
var zonesCache = new Array();
1035 aurelien 56
var requeteChargementPoints;
1142 aurelien 57
var urlVars = null;
836 jpm 58
/*+--------------------------------------------------------------------------------------------------------+*/
59
// INITIALISATION DU CODE
60
 
61
//Déclenchement d'actions quand JQuery et le document HTML sont OK
62
$(document).ready(function() {
63
	initialiserWidget();
64
});
65
 
66
function initialiserWidget() {
1142 aurelien 67
	urlVars = getUrlVars();
1448 aurelien 68
	initialiserCarte();
69
	dimensionnerCarte();
1442 aurelien 70
	definirTailleOverlay();
71
	attribuerListenersOverlay();
1438 aurelien 72
	centrerTitreEtStats();
836 jpm 73
	initialiserAffichagePanneauLateral();
980 jpm 74
	initialiserGestionnaireMarqueurs()
836 jpm 75
	initialiserInfoBulle();
941 jpm 76
	initialiserFormulaireContact();
836 jpm 77
	chargerLimitesCommunales();
1032 aurelien 78
	attribuerListenerCarte();
836 jpm 79
}
80
 
1142 aurelien 81
function getUrlVars()
82
{
83
    var vars = [], hash;
1151 aurelien 84
    if(window.location.href.indexOf('?') != -1) {
85
	    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
86
	    for(var i = 0; i < hashes.length; i++)
87
	    {
88
	        hash = hashes[i].split('=');
89
	        vars.push(hash[0]);
90
	        vars[hash[0]] = hash[1];
91
	    }
1142 aurelien 92
    }
93
    return vars;
94
}
95
 
915 jpm 96
/*+--------------------------------------------------------------------------------------------------------+*/
97
// AFFICHAGE GÉNÉRAL
98
 
1438 aurelien 99
function afficherTitreCarteEtStats() {
980 jpm 100
	if (stations != null && taxonsCarte.length > 0) {
1039 aurelien 101
		var obsNbre = stations.stats.observations;
1173 aurelien 102
		var obsNbreFormate = obsNbre;
103
		if(obsNbre != 0) {
104
		    obsNbreFormate = stations.stats.observations.formaterNombre();
105
		}
1039 aurelien 106
		var plteNbre = taxonsCarte.length;
1173 aurelien 107
		var plteNbreFormate = plteNbre;
108
		if(plteNbre != 0) {
109
		    plteNbreFormate = taxonsCarte.length.formaterNombre();
110
		}
1039 aurelien 111
		var communeNbre = stations.stats.communes;
1173 aurelien 112
		var communeNbreFormate = communeNbre;
113
		if(communeNbre != 0) {
114
		   communeNbreFormate = stations.stats.communes.formaterNombre();
115
		}
1172 aurelien 116
		var stationNbre = stations.stats.stations;
1173 aurelien 117
		var stationNbreFormate = stationNbre;
118
		if(stationNbre != 0) {
119
		  	stationNbreFormate = stations.stats.stations.formaterNombre();
120
		}
980 jpm 121
 
1438 aurelien 122
		var stats = obsNbreFormate+' observation';
123
		stats += (obsNbre > 1) ? 's' : '' ;
1434 aurelien 124
 
1438 aurelien 125
		if(photos != null && photos == 1) {
126
			stats += ' avec photos ';
1434 aurelien 127
		}
980 jpm 128
 
1438 aurelien 129
		stats += ' sur '+(stationNbre+ communeNbre)+' station';
130
		stats += (stationNbre > 1) ? 's' : '' ;
1447 aurelien 131
 
980 jpm 132
		if (nt == '*') {
1438 aurelien 133
			stats += ' parmi '+plteNbreFormate+' plante';
134
			stats += (plteNbre > 1) ? 's' : '' ;
980 jpm 135
		} else {
1430 aurelien 136
			if($('.taxon-actif .taxon').text() != '') {
137
				var element = $('.taxon-actif .taxon').clone();
138
				element.children().remove();
139
		        var taxon = element.text();
1438 aurelien 140
		        stats += ' pour '+taxon;
1430 aurelien 141
			} else {
142
				if (taxonsCarte[0]) {
143
					var taxon = taxonsCarte[0];
1438 aurelien 144
					stats += ' pour '+taxon.nom;
1430 aurelien 145
				}
980 jpm 146
			}
147
		}
148
 
1438 aurelien 149
		$('#zone-stats').show();
1448 aurelien 150
	} else {
151
		stats = "Aucune observation pour ces critères ou pour cette zone";
980 jpm 152
	}
1448 aurelien 153
 
154
	$('#zone-stats > h1').text(stats);
1438 aurelien 155
	centrerTitreEtStats();
836 jpm 156
}
157
 
1442 aurelien 158
function attribuerListenersOverlay() {
159
 
160
	$(window).resize(function() {
1445 aurelien 161
		google.maps.event.trigger($('#carte'), 'resize');
1448 aurelien 162
		dimensionnerCarte();
1442 aurelien 163
		definirTailleOverlay();
164
		centrerTitreEtStats();
1445 aurelien 165
		programmerRafraichissementCarte();
1442 aurelien 166
	});
167
 
168
	$('#lien_plein_ecran a').click(function(event) {
169
		window.open(window.location.href);
1445 aurelien 170
		event.preventDefault();
1442 aurelien 171
	});
172
 
1447 aurelien 173
	$('#lien-voir-cc a').click(function(event) {
174
		ouvrirPopUp(this, 'Avertissement', event);
1445 aurelien 175
		event.preventDefault();
1442 aurelien 176
	});
177
}
178
 
179
function definirTailleOverlay() {
980 jpm 180
	var largeurViewPort = $(window).width();
1445 aurelien 181
	var taille = '1.6';
1447 aurelien 182
	var tailleMaxLogo = 60;
183
	var tailleMaxIcones = 10;
1442 aurelien 184
	var padding_icones = 8;
1445 aurelien 185
	var tailleFiltre = 80;
1448 aurelien 186
	if (largeurViewPort <= 450) {
187
		taille = '1';
188
		tailleMaxIcones = 10;
189
		tailleFiltre = 65;
190
		padding_icones = 2;
191
		var tailleMaxLogo = 50;
192
	} else if (largeurViewPort <= 500) {
1447 aurelien 193
		taille = '1.2';
1442 aurelien 194
		tailleMaxIcones = 10;
1447 aurelien 195
		tailleFiltre = 65;
196
		padding_icones = 2;
1448 aurelien 197
		var tailleMaxLogo = 50;
1442 aurelien 198
	} else if (largeurViewPort > 500 && largeurViewPort <= 800) {
1447 aurelien 199
		taille = '1.4';
1442 aurelien 200
		tailleMaxIcones = 15;
201
		padding_icones = 6;
1447 aurelien 202
		tailleFiltre = 65;
1448 aurelien 203
		var tailleMaxLogo = 55;
1442 aurelien 204
	} else if (largeurViewPort > 800) {
980 jpm 205
		taille = '1.6';
1442 aurelien 206
		tailleMaxIcones = 20;
207
		padding_icones = 8;
1445 aurelien 208
		tailleFiltre = 80;
980 jpm 209
	}
1438 aurelien 210
 
211
	// Aménagement de la taille de police selon l'écran
980 jpm 212
	$("#carte-titre").css('font-size', taille+'em');
1442 aurelien 213
 
1448 aurelien 214
	$("#zone-stats h1").css('font-size', Math.round((taille*0.75*100))/100+'em');
1447 aurelien 215
	$("#zone-stats").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");
216
	$('#zone-stats').height(tailleMaxIcones*1.5);
1438 aurelien 217
 
1447 aurelien 218
	$("#zone-titre h1").css('font-size', (taille)+'em');
219
	$("#zone-titre").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");
220
	$('#zone-titre').height(tailleMaxIcones*2);
221
 
1442 aurelien 222
	$('.icone').height(tailleMaxIcones);
223
	$('#lien_plein_ecran').css("padding", padding_icones+"px "+padding_icones+"px "+Math.ceil(padding_icones/2)+"px");
224
 
1447 aurelien 225
	$('#lien-voir-cc').css("font-size", taille+"em");
226
	$('#lien-voir-cc').css("padding", padding_icones+"px");
1442 aurelien 227
 
1447 aurelien 228
	$("#panneau-lateral").css('font-size', (taille*0.9)+'em');
229
	$("#pl-contenu").css('font-size', (taille/2)+'em');
230
 
1445 aurelien 231
	$("#panneau-lateral").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");
1447 aurelien 232
	$('#pl-ouverture').height(((padding_icones*2)+$('#panneau-lateral').height())+"px");
1445 aurelien 233
	$("#panneau-lateral").width(tailleFiltre);
1448 aurelien 234
 
235
	dimensionnerLogo(tailleMaxLogo);
236
	dimensionnerImage(largeurViewPort);
237
	redimensionnerControleTypeCarte(largeurViewPort);
238
}
239
 
240
function dimensionnerLogo(tailleMaxLogo) {
241
	// Dimensionnement du logo
1447 aurelien 242
	hauteurLogo = $('.image-logo').height();
243
	// Redimensionnement du logo s'il est trop grand
244
	// on perd en qualité mais ça vaut mieux que de casser l'affichage
245
	if(hauteurLogo > tailleMaxLogo) {
246
		hauteurLogo = tailleMaxLogo;
247
		$('.image-logo').css("top", "5px");
248
		$('.image-logo').height(tailleMaxLogo);
1438 aurelien 249
	}
1447 aurelien 250
 
251
	if(hauteurLogo == 0) {
252
		$('.image-logo').load(function(event) {
253
			definirTailleOverlay();
254
		});
255
		return;
256
	}
257
 
258
	largeurLogo = $('#logo img').width();
980 jpm 259
}
260
 
1448 aurelien 261
function dimensionnerImage(largeurViewPort) {
262
	// Dimensionnement de l'image
263
	if(largeurViewPort > 500) {
264
		largeurLogo = 155;
265
	} else {
266
		largeurLogo = 70;
267
	}
268
 
269
	$('#image-utilisateur img').width(largeurLogo);
270
}
271
 
272
function redimensionnerControleTypeCarte(largeurViewPort) {
273
	if (largeurViewPort <= 500) {
274
		carteOptions.mapTypeControlOptions.style = google.maps.MapTypeControlStyle.DROPDOWN_MENU;
275
	} else {
276
		carteOptions.mapTypeControlOptions.style = google.maps.MapTypeControlStyle.DEFAULT;
277
	}
278
 
279
	map.setOptions(carteOptions);
280
}
281
 
1438 aurelien 282
function centrerTitreEtStats() {
1442 aurelien 283
	centrerTitre();
284
	centrerStats();
285
}
286
 
287
function centrerTitre() {
1438 aurelien 288
	var largeurViewPort = $(window).width();
289
	var largeurTitre = $('#zone-titre').width();
290
	var marge = (largeurViewPort - largeurTitre)/2;
291
	$('#zone-titre').css("margin-left",marge);
1445 aurelien 292
	var tailleRestante = largeurViewPort - (marge + largeurTitre);
293
	if(tailleRestante <= 170) {
294
		$('#zone-titre').css("top", "25px");
295
	} else {
296
		$('#zone-titre').css("top", "5px");
297
	}
1442 aurelien 298
}
299
 
300
function centrerStats() {
301
	var largeurViewPort = $(window).width();
1438 aurelien 302
	var largeurStats = $('#zone-stats').width();
1448 aurelien 303
	var marge = ((largeurViewPort - largeurStats)/2);
304
	$('#zone-stats').css("margin-left",marge);
1438 aurelien 305
}
306
 
915 jpm 307
/*+--------------------------------------------------------------------------------------------------------+*/
308
// CARTE
309
 
1448 aurelien 310
function dimensionnerCarte() {
1438 aurelien 311
	$('#carte').height($(window).height());
312
	$('#carte').width($(window).width());
836 jpm 313
}
314
 
315
function initialiserCarte() {
316
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
317
	// Ajout de la couche OSM à la carte
318
	map.mapTypes.set('OSM', osmMapType);
319
}
320
 
980 jpm 321
function initialiserGestionnaireMarqueurs() {
322
	mgr = new MarkerManager(map);
323
}
836 jpm 324
 
325
function chargerLimitesCommunales() {
326
	if (urlsLimitesCommunales != null) {
327
		for (urlId in urlsLimitesCommunales) {
328
			var url = urlsLimitesCommunales[urlId];
1107 aurelien 329
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
836 jpm 330
			ctaLayer.setMap(map);
331
		}
332
	}
333
}
1039 aurelien 334
 
980 jpm 335
var listener = null;
336
var timer = null;
1032 aurelien 337
function attribuerListenerCarte() {
980 jpm 338
	listener = google.maps.event.addListener(map, 'bounds_changed', function(){
1032 aurelien 339
		programmerRafraichissementCarte();
980 jpm 340
	});
1032 aurelien 341
	listener = google.maps.event.addListener(map, 'zoom_changed', function(){
342
		programmerRafraichissementCarte();
343
	});
980 jpm 344
}
1032 aurelien 345
function programmerRafraichissementCarte() {
346
	if(timer != null) {
347
        window.clearTimeout(timer);
1035 aurelien 348
    }
349
	if(requeteChargementPoints != null) {
350
		requeteChargementPoints.abort();
351
	}
1032 aurelien 352
	timer = window.setTimeout(function() {
1342 aurelien 353
		if(map.getBounds() != undefined) {
354
			var zoom = map.getZoom();
1434 aurelien 355
			var lngNE = map.getBounds().getNorthEast().lng();
356
			var lngSW = map.getBounds().getSouthWest().lng()
357
			if(map.getBounds().getNorthEast().lng() < map.getBounds().getSouthWest().lng()) {
358
				lngNE = 176;
359
				lngSW = -156;
360
			}
361
			var NELatLng = (map.getBounds().getNorthEast().lat())+'|'+(lngNE);
362
			var SWLatLng = (map.getBounds().getSouthWest().lat())+'|'+(lngSW);
1342 aurelien 363
			chargerMarqueurs(zoom, NELatLng, SWLatLng);
364
		} else {
365
			programmerRafraichissementCarte();
366
		}
1032 aurelien 367
    }, 400);
368
}
836 jpm 369
 
980 jpm 370
var marqueurs = new Array();
371
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
1445 aurelien 372
	cacherMessageAucuneObs()
980 jpm 373
	var url = stationsUrl+
374
		'&zoom='+zoom+
375
		'&ne='+NELatLng+
376
		'&sw='+SWLatLng;
377
 
1032 aurelien 378
	if(infoBulleOuverte) {
379
		return;
380
	}
381
 
1035 aurelien 382
	if(requeteChargementPoints != null) {
383
		requeteChargementPoints.abort();
1037 aurelien 384
		cacherMessageChargementPoints();
1035 aurelien 385
	}
386
 
387
	afficherMessageChargementPoints();
388
	requeteChargementPoints = $.getJSON(url, function(data) {
389
		rafraichirMarqueurs(data);
390
		cacherMessageChargementPoints();
980 jpm 391
	});
392
}
393
 
1442 aurelien 394
function centrerDansLaPage(selecteur) {
395
	var largeurViewport = $(window).width();
396
	var hauteurViewport = $(window).height();
397
	selecteur.css('display','block');
398
	var left = (largeurViewport/2) - (selecteur.width())/2;
399
	var top = (hauteurViewport/2) - (selecteur.height())/2
400
	selecteur.css('left',left);
401
	selecteur.css('top',top);
402
}
403
 
1035 aurelien 404
function afficherMessageChargementPoints() {
1442 aurelien 405
	centrerDansLaPage($('#zone-chargement-point'));
1035 aurelien 406
	$('#zone-chargement-point').css('display','block');
407
}
408
 
409
function cacherMessageChargementPoints() {
410
	$('#zone-chargement-point').css('display','none');
411
}
412
 
1442 aurelien 413
function afficherMessageAucuneObs() {
414
	centrerDansLaPage($('#message-aucune-obs'));
1445 aurelien 415
	$('#message-aucune-obs').show();
1442 aurelien 416
}
417
 
1445 aurelien 418
function cacherMessageAucuneObs() {
419
	centrerDansLaPage($('#message-aucune-obs'));
420
	$('#message-aucune-obs').hide();
421
}
422
 
1107 aurelien 423
premierChargement = true;
1142 aurelien 424
function doitCentrerCarte() {
425
	return premierChargement && urlVars != null && urlVars.length > 0;
426
}
1107 aurelien 427
 
1035 aurelien 428
function rafraichirMarqueurs(data) {
1448 aurelien 429
 
430
	marqueurs = new Array();
431
	stations = null;
432
 
1442 aurelien 433
	if(data.points.length > 0) {
434
		$.each(marqueurs, function(index, marqueur) {
435
			marqueur.setMap(null);
436
		});
437
		marqueurs = new Array();
438
 
439
		stations = data;
440
 
441
		$.each(stations.points, function (index, station) {
442
			if(station != null) {
443
				var nouveauMarqueur = creerMarqueur(station);
444
				marqueurs.push(nouveauMarqueur);
445
			}
446
		});
447
 
448
		if(doitCentrerCarte()) {
449
			premierChargement = false;
450
			var bounds = new google.maps.LatLngBounds();
451
			var latMax = new google.maps.LatLng(data.stats.coordmax.latMax, data.stats.coordmax.lngMax);
452
			var latMin = new google.maps.LatLng(data.stats.coordmax.latMin, data.stats.coordmax.lngMin);
453
			bounds.extend(latMax);
454
			bounds.extend(latMin);
455
			rendrePointsVisibles(bounds);
1035 aurelien 456
		}
1107 aurelien 457
	}
1448 aurelien 458
 
459
	afficherTitreCarteEtStats();
1035 aurelien 460
}
461
 
980 jpm 462
function creerMarqueur(station) {
1037 aurelien 463
	var titre = '';
464
	if(station.nbreMarqueur) {
465
		titre = station.nbreMarqueur+' points renseignés';
466
	} else {
467
		if(station.nom) {
468
			titre = station.nom;
469
		}
470
	}
1434 aurelien 471
 
980 jpm 472
	var icone = attribuerImageMarqueur(station['id'], station['nbreMarqueur']);
473
	var latLng = new google.maps.LatLng(station['lat'], station['lng']);
474
	var marqueur = new google.maps.Marker({
475
		position: latLng,
476
		icon: icone,
477
		title: ''+titre,
478
		map: map,
479
		stationInfos: station
480
	});
481
	attribuerListenerClick(marqueur, station['id']);
482
	marqueur.setMap(map);
483
    return marqueur;
484
}
485
 
1039 aurelien 486
function rendrePointsVisibles(bounds) {
487
	map.setCenter(bounds.getCenter());
488
	map.fitBounds(bounds);
489
}
490
 
980 jpm 491
function attribuerImageMarqueur(id, nbreMarqueur) {
492
	var marqueurImage = null;
493
	if (etreMarqueurCommune(id)) {
494
		marqueurImage = new google.maps.MarkerImage(communeImageUrl, new google.maps.Size(24, 32));
495
	} else if (etreMarqueurStation(id)) {
496
		marqueurImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(16, 16));
497
	} else if (etreMarqueurGroupe(id)) {
498
		var type = 0;
499
		var largeur = 0;
500
		var hauteur = 0;
501
		if (nbreMarqueur != null) {
502
			if (nbreMarqueur >= 2 && nbreMarqueur < 100 ) {
503
				type = '1';
504
				largeur = 53;
505
				hauteur = 52;
506
			} else if (nbreMarqueur >= 100 && nbreMarqueur < 1000 ) {
507
				type = '2';
508
				largeur = 56;
509
				hauteur = 55;
510
			} else if (nbreMarqueur >= 1000 && nbreMarqueur < 10000 ) {
511
				type = '3';
512
				largeur = 66;
513
				hauteur = 65;
514
			} else if (nbreMarqueur >= 10000 && nbreMarqueur < 20000 ) {
515
				type = '4';
516
				largeur = 78;
517
				hauteur = 77;
518
			} else if (nbreMarqueur >= 20000) {
519
				type = '5';
520
				largeur = 66;
521
				hauteur = 65;
522
			}
523
		}
524
		groupeImageUrl = groupeImageUrlTpl.replace(/\{type\}/, type);
525
		groupeImageUrl = groupeImageUrl.replace(/\{nbre\}/, nbreMarqueur);
526
		marqueurImage = new google.maps.MarkerImage(groupeImageUrl, new google.maps.Size(largeur, hauteur));
527
	}
528
	return marqueurImage
529
}
530
 
531
function attribuerListenerClick(marqueur, id) {
532
	if (etreMarqueurCommune(id) || etreMarqueurStation(id)) {
533
		google.maps.event.addListener(marqueur, 'click', surClickMarqueur);
534
	} else if (etreMarqueurGroupe(id)) {
535
		google.maps.event.addListener(marqueur, 'click', surClickGroupe);
536
	}
537
}
538
 
1445 aurelien 539
var pointCentreAvantAffichageInfoBulle = null;
1032 aurelien 540
function surClickMarqueur(event) {
1445 aurelien 541
	pointCentreAvantAffichageInfoBulle = map.getCenter();
542
 
1039 aurelien 543
	if(infoBulleOuverte) {
544
	    infoBulle.close();
545
	}
546
 
1035 aurelien 547
	pointClique = this;
980 jpm 548
	infoBulle.open(map, this);
549
	actualiserPagineur();
1035 aurelien 550
 
551
	var limites = map.getBounds();
552
	var centre = limites.getCenter();
553
	var nordEst = limites.getNorthEast();
554
	var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
555
	map.panTo(centreSudLatLng);
556
 
980 jpm 557
	afficherInfoBulle();
558
}
559
 
560
function surClickGroupe() {
561
	map.setCenter(this.getPosition());
562
	var nouveauZoom = map.getZoom() + 2;
563
	map.setZoom(nouveauZoom);
564
	mgr.clearMarkers();
565
}
566
 
567
function etreMarqueurGroupe(id) {
568
	var groupe = false;
569
	var motif = /^GROUPE/;
570
	if (motif.test(id)) {
571
		groupe = true;
572
	}
573
	return groupe;
574
}
575
 
576
function etreMarqueurCommune(id) {
577
	var commune = false;
578
	var motif = /^COMMUNE:/;
579
	if (motif.test(id)) {
580
		commune = true;
581
	}
582
	return commune;
583
}
584
 
585
function etreMarqueurStation(id) {
586
	var station = false;
587
	var motif = /^STATION:/;
588
	if (motif.test(id)) {
589
		station = true;
590
	}
591
	return station;
592
}
593
 
594
function deplacerCarteSurPointClique() {
915 jpm 595
	map.panTo(pointClique.position);
596
}
597
 
598
/*+--------------------------------------------------------------------------------------------------------+*/
599
// INFO BULLE
1032 aurelien 600
var infoBulleOuverte = false;
915 jpm 601
function initialiserInfoBulle() {
602
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
980 jpm 603
	google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle);
604
	google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle);
915 jpm 605
}
606
 
980 jpm 607
function surFermetureInfoBulle() {
1032 aurelien 608
	infoBulleOuverte = false;
1445 aurelien 609
	map.panTo(pointCentreAvantAffichageInfoBulle);
1032 aurelien 610
	programmerRafraichissementCarte();
980 jpm 611
}
612
 
613
function centrerInfoBulle() {
614
	var limites = map.getBounds();
615
	var centre = limites.getCenter();
616
	var nordEst = limites.getNorthEast();
617
	var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
618
	map.panTo(centreSudLatLng);
619
}
620
 
915 jpm 621
function afficherInfoBulle() {
622
	var obsHtml = $("#tpl-obs").html();
980 jpm 623
	var largeur = definirLargeurInfoBulle();
1445 aurelien 624
	var taillePolice = definirTaillePoliceInfoBulle();
980 jpm 625
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
915 jpm 626
	infoBulle.setContent(obsHtml);
1445 aurelien 627
	$('#observations').css('font-size',taillePolice+'em');
1035 aurelien 628
	chargerObs(0, 0);
1032 aurelien 629
	infoBulleOuverte = true;
915 jpm 630
}
631
 
980 jpm 632
function definirLargeurInfoBulle() {
633
	var largeurViewPort = $(window).width();
1445 aurelien 634
	var largeurInfoBulle = null;
635
	if (largeurViewPort < 400) {
636
		largeurInfoBulle = 300;
637
	} else if (largeurViewPort < 800) {
980 jpm 638
		largeurInfoBulle = 400;
639
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
640
		largeurInfoBulle = 500;
641
	} else if (largeurViewPort >= 1200) {
642
		largeurInfoBulle = 600;
643
	}
644
	return largeurInfoBulle;
645
}
646
 
1445 aurelien 647
function definirTaillePoliceInfoBulle() {
648
	var largeurViewPort = $(window).width();
649
	var taillePolice = null;
650
	if (largeurViewPort < 400) {
651
		taillePolice = 0.8;
652
	} else if (largeurViewPort < 800) {
653
		taillePolice = 1;
654
	}
655
	return taillePolice;
656
}
657
 
915 jpm 658
function afficherMessageChargement(element) {
659
	if ($('#chargement').get() == '') {
660
		$('#tpl-chargement').tmpl().appendTo(element);
661
	}
662
}
663
 
1035 aurelien 664
function afficherMessageChargementTitreInfoBulle() {
665
	$("#obs-station-titre").text("Chargement des observations");
666
}
667
 
915 jpm 668
function supprimerMessageChargement() {
669
	$('#chargement').remove();
670
}
671
 
672
function chargerObs(depart, total) {
939 jpm 673
	if (depart == 0 || depart < total) {
915 jpm 674
		var limite = 300;
675
		if (depart == 0) {
1036 aurelien 676
			viderTableauObs();
915 jpm 677
		}
1035 aurelien 678
 
939 jpm 679
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
1166 aurelien 680
		urlObs = urlObs.replace(/\{stationId\}/g, encodeURIComponent(pointClique.stationInfos.id));
1044 aurelien 681
		if (pointClique.stationInfos.type_emplacement == 'communes') {
1342 aurelien 682
			urlObs = urlObs.replace(/commune=%2A/g, formaterParametreCommunePourRequete(pointClique.stationInfos.nom));
1042 aurelien 683
		}
939 jpm 684
		urlObs = urlObs.replace(/\{nt\}/g, nt);
915 jpm 685
		urlObs = urlObs.replace(/\{start\}/g, depart);
686
 
687
		$.getJSON(urlObs, function(observations){
1036 aurelien 688
			surRetourChargementObs(observations, depart, total);
1035 aurelien 689
			chargerObs(depart+limite, observations.total);
915 jpm 690
		});
1036 aurelien 691
	}
692
}
693
 
1342 aurelien 694
function formaterParametreCommunePourRequete(nomCommune) {
695
	var chaineRequete = "";
696
	if(nomCommune.indexOf("(", 0) !== false) {
697
		var infosCommune = nomCommune.split("(");
698
		var commune = infosCommune[0];
699
		chaineRequete = 'commune='+encodeURIComponent($.trim(commune));
700
	} else {
701
		chaineRequete = 'commune='+encodeURIComponent($.trim(nomCommune));
702
	}
703
	return chaineRequete;
704
}
705
 
1036 aurelien 706
function viderTableauObs() {
707
	obsStation = new Array();
708
	surClicPagePagination(0, null);
709
}
710
 
711
function surRetourChargementObs(observations, depart, total) {
712
	obsStation = obsStation.concat(observations.observations);
713
	if (depart == 0) {
714
		actualiserInfosStation(observations);
715
		creerTitreInfoBulle();
1041 aurelien 716
		surClicPagePagination(0, null);
915 jpm 717
	}
1036 aurelien 718
 
1039 aurelien 719
	afficherPagination();
1036 aurelien 720
	actualiserPagineur();
1041 aurelien 721
	selectionnerOnglet("#obs-vue-"+pagineur.format);
915 jpm 722
}
723
 
1035 aurelien 724
function actualiserInfosStation(infos) {
725
	pointClique.stationInfos.commune = infos.commune;
726
	pointClique.stationInfos.obsNbre = infos.total;
727
}
728
 
729
function creerTitreInfoBulle() {
730
	$("#obs-total").text(station.obsNbre);
731
	$("#obs-commune").text(station.commune);
732
	var titre = '';
733
	titre += pointClique.stationInfos.obsNbre+' observation';
734
	titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
735
	titre += ' pour ';
736
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
737
		nomStation = 'la commune : ';
738
	} else {
739
		nomStation = 'la station : ';
740
	}
741
	titre += pointClique.stationInfos.nom;
742
	$("#obs-station-titre").text(titre);
743
}
744
 
939 jpm 745
function actualiserPagineur() {
980 jpm 746
	pagineur.stationId = pointClique.stationInfos.id;
1035 aurelien 747
	pagineur.total = pointClique.stationInfos.obsNbre;
1435 aurelien 748
	// Si on est en mode photo on reste en mode liste quelque soit le
749
	// nombre de résultats
1438 aurelien 750
	if (pagineur.total > 4 && photos != 1) {
939 jpm 751
		pagineur.format = 'tableau';
752
	} else {
753
		pagineur.format = 'liste';
754
	}
755
}
756
 
915 jpm 757
function afficherPagination(observations) {
758
	$(".navigation").pagination(pagineur.total, {
759
		items_per_page:pagineur.limite,
760
		callback:surClicPagePagination,
761
		next_text:'Suivant',
762
		prev_text:'Précédent',
763
		prev_show_always:false,
764
		num_edge_entries:1,
953 jpm 765
		num_display_entries:4,
915 jpm 766
		load_first_page:true
767
	});
768
}
769
 
770
function surClicPagePagination(pageIndex, paginationConteneur) {
771
	var index = pageIndex * pagineur.limite;
772
	var indexMax = index + pagineur.limite;
773
	pagineur.depart = index;
774
	obsPage = new Array();
775
    for(index; index < indexMax; index++) {
776
    	obsPage.push(obsStation[index]);
777
    }
778
 
779
    supprimerMessageChargement();
780
    mettreAJourObservations();
781
	return false;
782
}
783
 
784
function mettreAJourObservations() {
785
	$("#obs-"+pagineur.format+"-lignes").empty();
786
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
787
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
788
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
789
 
790
	// Actualisation de Fancybox
1414 aurelien 791
	ajouterFormulaireContact("a.contact");
915 jpm 792
	if (pagineur.format == 'liste') {
836 jpm 793
		ajouterGaleriePhoto("a.cel-img");
794
	}
795
}
796
 
915 jpm 797
function initialiserContenuInfoBulle() {
980 jpm 798
	afficherMessageChargement('#observations');
799
	cacherContenuOnglets();
915 jpm 800
	afficherOnglets();
801
	ajouterTableauTriable("#obs-tableau");
802
	afficherTextStationId();
803
	corrigerLargeurInfoWindow();
804
}
805
 
980 jpm 806
function cacherContenuOnglets() {
807
	$("#obs-vue-tableau").css("display", "none");
808
	$("#obs-vue-liste").css("display", "none");
809
}
810
 
915 jpm 811
function afficherOnglets() {
812
	var $tabs = $('#obs').tabs();
813
	$('#obs').bind('tabsselect', function(event, ui) {
814
		if (ui.panel.id == 'obs-vue-tableau') {
815
			surClicAffichageTableau();
816
		} else if (ui.panel.id == 'obs-vue-liste') {
817
			surClicAffichageListe();
818
		}
819
	});
980 jpm 820
	if (pointClique.stationInfos.nbre > 4) {
821
		$tabs.tabs('select', "#obs-vue-tableau");
822
	} else {
823
		$tabs.tabs('select', "#obs-vue-liste");
824
	}
825
 
915 jpm 826
}
827
 
939 jpm 828
function selectionnerOnglet(onglet) {
980 jpm 829
	$(onglet).css('display', 'block');
939 jpm 830
	$('#obs').tabs('select', onglet);
831
}
832
 
915 jpm 833
function afficherTextStationId() {
980 jpm 834
	$('#obs-station-id').text(pointClique.stationInfos.id);
915 jpm 835
}
836
 
837
function corrigerLargeurInfoWindow() {
953 jpm 838
	$("#info-bulle").width($("#info-bulle").width() - 17);
915 jpm 839
}
840
 
841
function surClicAffichageTableau(event) {
842
	pagineur.format = 'tableau';
843
	mettreAJourObservations();
844
	mettreAJourTableauTriable("#obs-tableau");
845
}
846
 
847
function surClicAffichageListe(event) {
848
	pagineur.format = 'liste';
849
	mettreAJourObservations();
850
	ajouterGaleriePhoto("a.cel-img");
851
}
852
 
836 jpm 853
function ajouterTableauTriable(element) {
854
	// add parser through the tablesorter addParser method
855
	$.tablesorter.addParser({
856
		// Définition d'un id unique pour ce parsseur
857
		id: 'date_cel',
858
		is: function(s) {
915 jpm 859
			// doit retourner false si le parsseur n'est pas autodétecté
860
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
836 jpm 861
		},
915 jpm 862
		format: function(date) {
836 jpm 863
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
915 jpm 864
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
836 jpm 865
			// Remplace la date par un nombre de millisecondes pour trier numériquement
915 jpm 866
			return $.tablesorter.formatFloat(new Date(date).getTime());
836 jpm 867
		},
868
		// set type, either numeric or text
869
		type: 'numeric'
870
	});
871
	$(element).tablesorter({
872
        headers: {
915 jpm 873
			1: {
874
            	sorter:'date_cel'
875
        	}
876
    	}
877
	});
836 jpm 878
}
879
 
915 jpm 880
function mettreAJourTableauTriable(element) {
881
	$(element).trigger('update');
882
}
883
 
836 jpm 884
function ajouterGaleriePhoto(element) {
885
	$(element).fancybox({
915 jpm 886
		transitionIn:'elastic',
887
		transitionOut:'elastic',
888
		speedIn	:600,
889
		speedOut:200,
890
		overlayShow:true,
891
		titleShow:true,
892
		titlePosition:'inside',
893
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
894
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
895
			motif.exec(titre);
896
			var id = RegExp.$1;
897
			var info = $('#cel-info-'+id).clone().html();
898
			var tpl =
899
				'<div class="cel-legende">'+
900
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+
901
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
902
				'<\/div>';
903
			return tpl;
836 jpm 904
		}
1032 aurelien 905
	}).live('click', function(e) {
906
		if (e.stopPropagation) {
907
			e.stopPropagation();
908
		}
909
		return false;
910
	});
836 jpm 911
}
912
 
1414 aurelien 913
function ajouterFormulaireContact(element) {
941 jpm 914
	$(element).fancybox({
915
		transitionIn:'elastic',
916
		transitionOut:'elastic',
917
		speedIn	:600,
918
		speedOut:200,
919
		scrolling: 'no',
920
		titleShow: false,
921
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
922
			var element = selectedArray[selectedIndex];
923
 
924
			var motif = / contributeur-([0-9]+)$/;
925
			motif.exec($(element).attr('class'));
926
			var id = RegExp.$1;
950 jpm 927
			//console.log('Destinataire id : '+id);
941 jpm 928
			$("#fc_destinataire_id").attr('value', id);
929
 
930
			var motif = / obs-([0-9]+) /;
931
			motif.exec($(element).attr('class'));
932
			var id = RegExp.$1;
950 jpm 933
			//console.log('Obs id : '+id);
941 jpm 934
			chargerInfoObsPourMessage(id);
935
		},
936
		onCleanup: function() {
950 jpm 937
			//console.log('Avant fermeture fancybox');
941 jpm 938
			$("#fc_destinataire_id").attr('value', '');
939
			$("#fc_sujet").attr('value', '');
940
			$("#fc_message").text('');
941
		},
942
		onClosed: function(e) {
950 jpm 943
			//console.log('Fermeture fancybox');
941 jpm 944
			if (e.stopPropagation) {
945
				e.stopPropagation();
946
			}
947
			return false;
948
		}
949
	});
950
}
951
 
952
function chargerInfoObsPourMessage(idObs) {
980 jpm 953
	var nomSci = jQuery.trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
954
	var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
955
	var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
953 jpm 956
	var sujet = "Observation #"+idObs+" de "+nomSci;
957
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
941 jpm 958
	$("#fc_sujet").attr('value', sujet);
959
	$("#fc_message").text(message);
960
}
961
 
962
function initialiserFormulaireContact() {
950 jpm 963
	//console.log('Initialisation du form contact');
941 jpm 964
	$("#form-contact").validate({
965
		rules: {
966
			fc_sujet : "required",
967
			fc_message : "required",
953 jpm 968
			fc_utilisateur_courriel : {
969
				required : true,
970
				email : true}
941 jpm 971
		}
972
	});
973
	$("#form-contact").bind("submit", envoyerCourriel);
950 jpm 974
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
941 jpm 975
 
976
}
977
 
978
function envoyerCourriel() {
950 jpm 979
	//console.log('Formulaire soumis');
941 jpm 980
	if ($("#form-contact").valid()) {
950 jpm 981
		//console.log('Formulaire valide');
941 jpm 982
		//$.fancybox.showActivity();
983
		var destinataireId = $("#fc_destinataire_id").attr('value');
984
		var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
985
		var erreurMsg = "";
986
		var donnees = new Array();
987
		$.each($(this).serializeArray(), function (index, champ) {
988
			var cle = champ.name;
989
			cle = cle.replace(/^fc_/, '');
953 jpm 990
 
980 jpm 991
			if (cle == 'sujet') {
953 jpm 992
				champ.value += " - Carnet en ligne - Tela Botanica";
993
			}
994
			if (cle == 'message') {
995
				champ.value += "\n--\n"+
980 jpm 996
					"Ce message vous est envoyé par l'intermédiaire du widget carto "+
953 jpm 997
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
998
					"http://www.tela-botanica.org/widget:cel:carto";
999
			}
1000
 
941 jpm 1001
			donnees[index] = {'name':cle,'value':champ.value};
1002
		});
1003
		$.ajax({
1004
			type : "POST",
1005
			cache : false,
1006
			url : urlMessage,
1007
			data : donnees,
1008
			beforeSend : function() {
1009
				$(".msg").remove();
1010
			},
1011
			success : function(data) {
1012
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
1013
			},
1014
			error : function(jqXHR, textStatus, errorThrown) {
1015
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
1016
				reponse = jQuery.parseJSON(jqXHR.responseText);
1017
				if (reponse != null) {
1018
					$.each(reponse, function (cle, valeur) {
1019
						erreurMsg += valeur + "\n";
1020
					});
1021
				}
1022
			},
1023
			complete : function(jqXHR, textStatus) {
1024
				var debugMsg = '';
1025
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
1026
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
1027
					if (debugInfos != null) {
1028
						$.each(debugInfos, function (cle, valeur) {
1029
							debugMsg += valeur + "\n";
1030
						});
1031
					}
1032
				}
1033
				if (erreurMsg != '') {
1034
					$("#fc-zone-dialogue").append('<p class="msg">'+
1035
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
1036
							'Vous pouvez signaler le disfonctionnement à <a href="'+
1037
							'mailto:cel@tela-botanica.org'+'?'+
980 jpm 1038
							'subject=Disfonctionnement du widget carto'+
941 jpm 1039
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
1040
							'">cel@tela-botanica.org</a>.'+
1041
							'</p>');
1042
				}
1043
				if (DEBUG) {
1044
					console.log('Débogage : '+debugMsg);
1045
				}
950 jpm 1046
				//console.log('Débogage : '+debugMsg);
1047
				//console.log('Erreur : '+erreurMsg);
941 jpm 1048
			}
1049
		});
1050
	}
1051
	return false;
1052
}
915 jpm 1053
/*+--------------------------------------------------------------------------------------------------------+*/
1054
// PANNEAU LATÉRAL
836 jpm 1055
 
1438 aurelien 1056
function initialiserAffichagePanneauLateral() {
915 jpm 1057
	if (nt == '*') {
1058
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
1059
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
1430 aurelien 1060
	} else {
1061
		$('#panneau-lateral').width(0);
1062
		$('#carte').width('100%');
836 jpm 1063
	}
939 jpm 1064
	chargerTaxons(0, 0);
836 jpm 1065
}
1066
 
939 jpm 1067
function chargerTaxons(depart, total) {
1068
	if (depart == 0 || depart < total) {
1069
		var limite = 7000;
950 jpm 1070
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
939 jpm 1071
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
1072
		urlTax = urlTax.replace(/\{start\}/g, depart);
1073
		$.getJSON(urlTax, function(infos) {
1074
			taxonsCarte = taxonsCarte.concat(infos.taxons);
950 jpm 1075
			//console.log("Nbre taxons :"+taxonsCarte.length);
939 jpm 1076
			chargerTaxons(depart+limite, infos.total);
1077
		});
1078
	} else {
1079
		if (nt == '*') {
1080
			afficherTaxons();
1081
		}
1438 aurelien 1082
		afficherTitreCarteEtStats();
939 jpm 1083
	}
1084
}
1085
 
1086
function afficherTaxons() {
980 jpm 1087
	$(".plantes-nbre").text(taxonsCarte.length);
939 jpm 1088
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
1089
	$('.taxon').live('click', filtrerParTaxon);
1445 aurelien 1090
	$('.raz-filtre-taxons').live('click', viderFiltreTaxon);
939 jpm 1091
}
1092
 
1445 aurelien 1093
var largeurPanneauLateralFerme = null;
915 jpm 1094
function afficherPanneauLateral() {
1447 aurelien 1095
	// fixer la hauteur
1445 aurelien 1096
	$('#panneau-lateral').height($(window).height() - $('#panneau-lateral').offset().top);
1097
	largeurPanneauLateralFerme = $('#panneau-lateral').width();
836 jpm 1098
	$('#panneau-lateral').width(300);
1099
	$('#pl-contenu').css('display', 'block');
1100
	$('#pl-ouverture').css('display', 'none');
1101
	$('#pl-fermeture').css('display', 'block');
1445 aurelien 1102
	// correction pour la taille de la liste des taxons
1103
	$('#pl-corps').height($(window).height() - $('#pl-corps').offset().top);
836 jpm 1104
 
1105
	google.maps.event.trigger(map, 'resize');
1106
};
1107
 
915 jpm 1108
function cacherPanneauLateral() {
1447 aurelien 1109
	$('#panneau-lateral').height(25+"px");
1445 aurelien 1110
	$('#panneau-lateral').width(largeurPanneauLateralFerme+"px");
836 jpm 1111
	$('#pl-contenu').css('display', 'none');
1112
	$('#pl-ouverture').css('display', 'block');
1113
	$('#pl-fermeture').css('display', 'none');
1114
 
1115
	google.maps.event.trigger(map, 'resize');
1116
};
1117
 
1445 aurelien 1118
function viderFiltreTaxon() {
1119
	$('.taxon-actif .taxon').click();
1120
}
1121
 
836 jpm 1122
function filtrerParTaxon() {
1123
	var ntAFiltrer = $('.nt', this).text();
1124
	infoBulle.close();
1037 aurelien 1125
	var zoom = map.getZoom();
1126
	var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
1127
	var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
1128
 
1447 aurelien 1129
	$('.raz-filtre-taxons').removeClass('taxon-actif');
836 jpm 1130
	$('#taxon-'+nt).removeClass('taxon-actif');
1447 aurelien 1131
 
836 jpm 1132
	if (nt == ntAFiltrer) {
1133
		nt = '*';
1037 aurelien 1134
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+nt);
1135
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
836 jpm 1136
	} else {
1035 aurelien 1137
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
1138
		url = stationsUrl;
1139
		url += '&zoom='+zoom+
1140
			'&ne='+NELatLng+
1141
			'&sw='+SWLatLng;
1142
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
939 jpm 1143
			stations = stationsFiltrees;
836 jpm 1144
			nt = ntAFiltrer;
1145
			$('#taxon-'+nt).addClass('taxon-actif');
1035 aurelien 1146
			rafraichirMarqueurs(stations);
836 jpm 1147
		});
1148
	}
1149
};
1150
 
915 jpm 1151
/*+--------------------------------------------------------------------------------------------------------+*/
1152
// FONCTIONS UTILITAIRES
1153
 
980 jpm 1154
function ouvrirPopUp(element, nomPopUp, event) {
1155
	var options =
1156
		'width=650,'+
1157
		'height=600,'+
1158
		'scrollbars=yes,'+
1159
		'directories=no,'+
1160
		'location=no,'+
1161
		'menubar=no,'+
1162
		'status=no,'+
1163
		'toolbar=no';
1164
	var popUp = window.open(element.href, nomPopUp, options);
1165
	if (window.focus) {
1166
		popUp.focus();
1167
	}
1168
	return arreter(event);
1169
};
1170
 
1171
function ouvrirNouvelleFenetre(element, event) {
1172
	window.open(element.href);
1173
	return arreter(event);
1174
}
1175
 
915 jpm 1176
function arreter(event) {
1177
	if (event.stopPropagation) {
1178
		event.stopPropagation();
1179
	} else if (window.event) {
1180
		window.event.cancelBubble = true;
1181
	}
980 jpm 1182
	if (event.preventDefault) {
1183
		event.preventDefault();
1184
	}
1185
	event.returnValue = false;
915 jpm 1186
	return false;
1187
}
1188
 
836 jpm 1189
/**
1190
 * +-------------------------------------+
1191
 * Number.prototype.formaterNombre
1192
 * +-------------------------------------+
1193
 * Params (facultatifs):
1194
 * - Int decimales: nombre de decimales (exemple: 2)
1195
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
1196
 * - String separateurMilliers: comme son nom l'indique
1197
 * Returns:
1198
 * - String chaine formatee
1199
 * @author	::mastahbenus::
1200
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
1201
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
1202
 */
1203
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
1204
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
1205
 
1206
	function is_int(nbre) {
1207
		nbre = nbre.replace(',', '.');
1208
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
1209
	}
1210
 
1211
	if (decimales == undefined) {
1212
		if (is_int(_sNombre)) {
1213
			decimales = 0;
1214
		} else {
1215
			decimales = 2;
1216
		}
1217
	}
1218
	if (signe == undefined) {
1219
		if (is_int(_sNombre)) {
1220
			signe = '';
1221
		} else {
1222
			signe = '.';
1223
		}
1224
	}
1225
	if (separateurMilliers == undefined) {
1226
		separateurMilliers = ' ';
1227
	}
1228
 
1229
	function separeMilliers (sNombre) {
1230
		var sRetour = "";
1231
		while (sNombre.length % 3 != 0) {
1232
			sNombre = "0"+sNombre;
1233
		}
1234
		for (i = 0; i < sNombre.length; i += 3) {
1235
			if (i == sNombre.length-1) separateurMilliers = '';
1236
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
1237
		}
1238
		while (sRetour.substr(0, 1) == "0") {
1239
			sRetour = sRetour.substr(1);
1240
		}
1241
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
1242
	}
1243
 
1244
	if (_sNombre.indexOf('.') == -1) {
1245
		for (i = 0; i < decimales; i++) {
1246
			_sDecimales += "0";
1247
		}
1248
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
1249
	} else {
1250
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
1251
		if (sDecimalesTmp.length > decimales) {
1252
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
1253
			var nDiv = 1;
1254
			for (i = 0; i < nDecimalesManquantes; i++) {
1255
				nDiv *= 10;
1256
			}
1257
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
1258
		}
1259
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
1260
	}
1261
	return _sRetour;
915 jpm 1262
}
1263
 
1264
function debug(objet) {
1265
	var msg = '';
1266
	if (objet != null) {
1267
		$.each(objet, function (cle, valeur) {
1268
			msg += cle+":"+valeur + "\n";
1269
		});
1270
	} else {
1271
		msg = "La variable vaut null.";
1272
	}
1273
	console.log(msg);
836 jpm 1274
}