Subversion Repositories eFlore/Applications.cel

Rev

Rev 3857 | Details | Compare with Previous | Last modification | View Log | RSS feed

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