Subversion Repositories eFlore/Applications.cel

Rev

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