Subversion Repositories eFlore/Applications.cel

Rev

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