Subversion Repositories eFlore/Applications.cel

Rev

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

Rev Author Line No. Line
836 jpm 1
/*+--------------------------------------------------------------------------------------------------------+*/
2
// PARAMÊTRES et CONSTANTES
941 jpm 3
// Mettre à true pour afficher les messages de débogage
950 jpm 4
var DEBUG = false;
980 jpm 5
var communeImageUrl = 'http://www.tela-botanica.org/commun/icones/carto/commune.png';
6
var pointImageUrl = 'http://www.tela-botanica.org/commun/icones/carto/point2.png';
1035 aurelien 7
var groupeImageUrlTpl = 'http://localhost/service:cel:CelWidgetMap/icone-groupe?type={type}&nbre={nbre}'
836 jpm 8
var pointsOrigine = null;
9
var boundsOrigine = null;
10
var markerClusterer = null;
11
var map = null;
12
var infoBulle = new google.maps.InfoWindow();
980 jpm 13
var stations = null;
836 jpm 14
var pointClique = null;
980 jpm 15
var carteCentre = new google.maps.LatLng(25, 10);
836 jpm 16
var carteOptions = {
980 jpm 17
	zoom: 3,
18
	center:carteCentre,
836 jpm 19
	mapTypeId: google.maps.MapTypeId.ROADMAP,
20
	mapTypeControlOptions: {
21
		mapTypeIds: ['OSM',
22
		             google.maps.MapTypeId.ROADMAP,
23
		             google.maps.MapTypeId.HYBRID,
24
		             google.maps.MapTypeId.SATELLITE,
25
		             google.maps.MapTypeId.TERRAIN]
26
	}
27
};
28
var osmMapType = new google.maps.ImageMapType({
29
	getTileUrl: function(coord, zoom) {
30
		return "http://tile.openstreetmap.org/" +
31
		zoom + "/" + coord.x + "/" + coord.y + ".png";
32
	},
33
	tileSize: new google.maps.Size(256, 256),
34
	isPng: true,
35
	alt: "OpenStreetMap",
36
	name: "OSM",
37
	maxZoom: 19
38
});
980 jpm 39
var ctaLayer = null;
915 jpm 40
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
41
var station = {'commune':'', 'obsNbre':0};
42
var obsStation = new Array();
43
var obsPage = new Array();
939 jpm 44
var taxonsCarte = new Array();
980 jpm 45
var mgr = null;
46
var marqueursCache = new Array();
47
var zonesCache = new Array();
1035 aurelien 48
var requeteChargementPoints;
836 jpm 49
/*+--------------------------------------------------------------------------------------------------------+*/
50
// INITIALISATION DU CODE
51
 
52
//Déclenchement d'actions quand JQuery et le document HTML sont OK
53
$(document).ready(function() {
54
	initialiserWidget();
55
});
56
 
57
function initialiserWidget() {
980 jpm 58
	definirTailleTitre();
836 jpm 59
	initialiserAffichageCarte();
60
	initialiserAffichagePanneauLateral();
61
	initialiserCarte();
980 jpm 62
	initialiserGestionnaireMarqueurs()
836 jpm 63
	initialiserInfoBulle();
941 jpm 64
	initialiserFormulaireContact();
836 jpm 65
	chargerLimitesCommunales();
1032 aurelien 66
	attribuerListenerCarte();
67
	programmerRafraichissementCarte();
836 jpm 68
}
69
 
915 jpm 70
/*+--------------------------------------------------------------------------------------------------------+*/
71
// AFFICHAGE GÉNÉRAL
72
 
980 jpm 73
function afficherTitreCarte() {
74
	if (stations != null && taxonsCarte.length > 0) {
75
		var obsNbre = stations.stats.observations.formaterNombre();
76
		var plteNbre = taxonsCarte.length.formaterNombre();
77
		var communeNbre = stations.stats.communes.formaterNombre();
78
 
79
		var titre = obsNbre+' observation';
80
		titre += (obsNbre > 1) ? 's' : '' ;
81
 
82
		if (nt == '*') {
83
			titre += ' de '+plteNbre+' plante';
84
			titre += (plteNbre > 1) ? 's' : '' ;
85
		} else {
86
			if (taxonsCarte[0]) {
87
				var taxon = taxonsCarte[0];
88
				titre += ' pour '+taxon.nom;
89
			}
90
		}
91
 
92
		titre += ' sur '+communeNbre+' commune';
93
		titre += (communeNbre > 1) ? 's' : '' ;
94
 
95
		$('#carte-titre-infos').text(titre);
96
	}
836 jpm 97
}
98
 
980 jpm 99
function definirTailleTitre() {
100
	var largeurViewPort = $(window).width();
101
	var taille = null;
102
	if (largeurViewPort < 400) {
103
		taille = '0.8';
104
	} else if (largeurViewPort >= 400 && largeurViewPort < 800) {
105
		taille = '1.0';
106
	} else if (largeurViewPort >= 800) {
107
		taille = '1.6';
108
	}
109
	$("#carte-titre").css('font-size', taille+'em');
110
}
111
 
915 jpm 112
/*+--------------------------------------------------------------------------------------------------------+*/
113
// CARTE
114
 
836 jpm 115
function initialiserAffichageCarte() {
116
	$('#carte').height($(window).height() - 35);
117
	$('#carte').width($(window).width() - 24);
980 jpm 118
 
836 jpm 119
	if (nt != '*') {
120
		$('#carte').css('left', 0);
121
	}
122
}
123
 
124
function initialiserCarte() {
125
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
126
	// Ajout de la couche OSM à la carte
127
	map.mapTypes.set('OSM', osmMapType);
128
}
129
 
980 jpm 130
function initialiserGestionnaireMarqueurs() {
131
	mgr = new MarkerManager(map);
132
}
836 jpm 133
 
134
function chargerLimitesCommunales() {
135
	if (urlsLimitesCommunales != null) {
136
		for (urlId in urlsLimitesCommunales) {
137
			var url = urlsLimitesCommunales[urlId];
138
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
139
			ctaLayer.setMap(map);
140
		}
141
	}
142
}
980 jpm 143
var listener = null;
144
var timer = null;
1032 aurelien 145
function attribuerListenerCarte() {
980 jpm 146
	listener = google.maps.event.addListener(map, 'bounds_changed', function(){
1032 aurelien 147
		programmerRafraichissementCarte();
980 jpm 148
	});
1032 aurelien 149
	listener = google.maps.event.addListener(map, 'zoom_changed', function(){
150
		programmerRafraichissementCarte();
151
	});
980 jpm 152
}
1032 aurelien 153
function programmerRafraichissementCarte() {
154
	if(timer != null) {
155
        window.clearTimeout(timer);
1035 aurelien 156
    }
157
	if(requeteChargementPoints != null) {
158
		requeteChargementPoints.abort();
159
	}
1032 aurelien 160
	timer = window.setTimeout(function() {
161
		var zoom = map.getZoom();
162
		var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
163
		var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
164
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
165
    }, 400);
166
}
836 jpm 167
 
980 jpm 168
var premierChargement = true;
169
var marqueurs = new Array();
170
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
171
	var url = stationsUrl+
172
		'&zoom='+zoom+
173
		'&ne='+NELatLng+
174
		'&sw='+SWLatLng;
175
 
1032 aurelien 176
	if(infoBulleOuverte) {
177
		return;
178
	}
179
 
1035 aurelien 180
	if(requeteChargementPoints != null) {
181
		requeteChargementPoints.abort();
182
	}
183
 
184
	afficherMessageChargementPoints();
185
	requeteChargementPoints = $.getJSON(url, function(data) {
186
		rafraichirMarqueurs(data);
187
		cacherMessageChargementPoints();
980 jpm 188
	});
189
}
190
 
1035 aurelien 191
function afficherMessageChargementPoints() {
192
	$('#zone-chargement-point').css('display','block');
193
}
194
 
195
function cacherMessageChargementPoints() {
196
	$('#zone-chargement-point').css('display','none');
197
}
198
 
199
function rafraichirMarqueurs(data) {
200
	$.each(marqueurs, function(index, marqueur) {
201
		marqueur.setMap(null);
202
	});
203
	marqueurs = new Array();
204
 
205
	stations = data;
206
	afficherTitreCarte();
207
 
208
	$.each(stations.points, function (index, station) {
209
		if(station != null) {
210
			marqueurs.push(creerMarqueur(station));
211
		}
212
	});
213
}
214
 
980 jpm 215
function creerMarqueur(station) {
216
	var titre = station['nbreMarqueur'];
217
	var icone = attribuerImageMarqueur(station['id'], station['nbreMarqueur']);
218
	var latLng = new google.maps.LatLng(station['lat'], station['lng']);
219
	var marqueur = new google.maps.Marker({
220
		position: latLng,
221
		icon: icone,
222
		title: ''+titre,
223
		map: map,
224
		stationInfos: station
225
	});
226
	attribuerListenerClick(marqueur, station['id']);
227
	marqueur.setMap(map);
228
    return marqueur;
229
}
230
 
1032 aurelien 231
function programmerRafraichissementCarteSauv() {
980 jpm 232
 
836 jpm 233
	var points = [];
234
	var bounds = new google.maps.LatLngBounds();
980 jpm 235
	for (var i = 0; i < stations.points.length; ++i) {
236
		var point = stations.points[i];
237
		var maLatLng = new google.maps.LatLng(point.lat, point.lng);
238
		var stationImage = attribuerImageMarqueur(point.id);
836 jpm 239
		var point = new google.maps.Marker({
240
			position: maLatLng,
241
			map: map,
980 jpm 242
			icon: stationImage,
243
			stationInfos: point
836 jpm 244
		});
245
		bounds.extend(maLatLng);
980 jpm 246
		google.maps.event.addListener(point, 'click', surClickMarqueur);
836 jpm 247
		points.push(point);
248
	}
249
 
250
	if (pointsOrigine == null && boundsOrigine == null) {
251
		pointsOrigine = points;
252
		boundsOrigine = bounds;
253
	}
254
 
255
	executerMarkerClusterer(points, bounds);
256
}
257
 
980 jpm 258
function attribuerImageMarqueur(id, nbreMarqueur) {
259
	var marqueurImage = null;
260
	if (etreMarqueurCommune(id)) {
261
		marqueurImage = new google.maps.MarkerImage(communeImageUrl, new google.maps.Size(24, 32));
262
	} else if (etreMarqueurStation(id)) {
263
		marqueurImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(16, 16));
264
	} else if (etreMarqueurGroupe(id)) {
265
		var type = 0;
266
		var largeur = 0;
267
		var hauteur = 0;
268
		if (nbreMarqueur != null) {
269
			if (nbreMarqueur >= 2 && nbreMarqueur < 100 ) {
270
				type = '1';
271
				largeur = 53;
272
				hauteur = 52;
273
			} else if (nbreMarqueur >= 100 && nbreMarqueur < 1000 ) {
274
				type = '2';
275
				largeur = 56;
276
				hauteur = 55;
277
			} else if (nbreMarqueur >= 1000 && nbreMarqueur < 10000 ) {
278
				type = '3';
279
				largeur = 66;
280
				hauteur = 65;
281
			} else if (nbreMarqueur >= 10000 && nbreMarqueur < 20000 ) {
282
				type = '4';
283
				largeur = 78;
284
				hauteur = 77;
285
			} else if (nbreMarqueur >= 20000) {
286
				type = '5';
287
				largeur = 66;
288
				hauteur = 65;
289
			}
290
		}
291
		groupeImageUrl = groupeImageUrlTpl.replace(/\{type\}/, type);
292
		groupeImageUrl = groupeImageUrl.replace(/\{nbre\}/, nbreMarqueur);
293
		marqueurImage = new google.maps.MarkerImage(groupeImageUrl, new google.maps.Size(largeur, hauteur));
294
	}
295
	return marqueurImage
296
}
297
 
298
function attribuerListenerClick(marqueur, id) {
299
	if (etreMarqueurCommune(id) || etreMarqueurStation(id)) {
300
		google.maps.event.addListener(marqueur, 'click', surClickMarqueur);
301
	} else if (etreMarqueurGroupe(id)) {
302
		google.maps.event.addListener(marqueur, 'click', surClickGroupe);
303
	}
304
}
305
 
1032 aurelien 306
function surClickMarqueur(event) {
1035 aurelien 307
 
308
	pointClique = this;
980 jpm 309
	infoBulle.open(map, this);
310
	actualiserPagineur();
1035 aurelien 311
 
312
	var limites = map.getBounds();
313
	var centre = limites.getCenter();
314
	var nordEst = limites.getNorthEast();
315
	var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
316
	map.panTo(centreSudLatLng);
317
 
980 jpm 318
	afficherInfoBulle();
319
}
320
 
321
function surClickGroupe() {
322
	map.setCenter(this.getPosition());
323
	var nouveauZoom = map.getZoom() + 2;
324
	map.setZoom(nouveauZoom);
325
	mgr.clearMarkers();
326
}
327
 
328
function etreMarqueurGroupe(id) {
329
	var groupe = false;
330
	var motif = /^GROUPE/;
331
	if (motif.test(id)) {
332
		groupe = true;
333
	}
334
	return groupe;
335
}
336
 
337
function etreMarqueurCommune(id) {
338
	var commune = false;
339
	var motif = /^COMMUNE:/;
340
	if (motif.test(id)) {
341
		commune = true;
342
	}
343
	return commune;
344
}
345
 
346
function etreMarqueurStation(id) {
347
	var station = false;
348
	var motif = /^STATION:/;
349
	if (motif.test(id)) {
350
		station = true;
351
	}
352
	return station;
353
}
354
 
355
function deplacerCarteSurPointClique() {
915 jpm 356
	map.panTo(pointClique.position);
357
}
358
 
359
function executerMarkerClusterer(points, bounds) {
360
	if (markerClusterer) {
361
		markerClusterer.clearMarkers();
836 jpm 362
	}
980 jpm 363
	markerClusterer = new MarkerClusterer(map, points, {gridSize: 50, maxZoom: 18});
915 jpm 364
	map.fitBounds(bounds);
365
}
366
 
367
/*+--------------------------------------------------------------------------------------------------------+*/
368
// INFO BULLE
1032 aurelien 369
var infoBulleOuverte = false;
915 jpm 370
function initialiserInfoBulle() {
371
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
980 jpm 372
	google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle);
373
	google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle);
915 jpm 374
}
375
 
980 jpm 376
function surFermetureInfoBulle() {
1032 aurelien 377
	infoBulleOuverte = false;
378
	programmerRafraichissementCarte();
980 jpm 379
}
380
 
381
function centrerInfoBulle() {
382
	var limites = map.getBounds();
383
	var centre = limites.getCenter();
384
	var nordEst = limites.getNorthEast();
385
	var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
386
	map.panTo(centreSudLatLng);
387
}
388
 
915 jpm 389
function afficherInfoBulle() {
390
	var obsHtml = $("#tpl-obs").html();
980 jpm 391
	var largeur = definirLargeurInfoBulle();
392
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
915 jpm 393
	infoBulle.setContent(obsHtml);
1035 aurelien 394
	chargerObs(0, 0);
1032 aurelien 395
	infoBulleOuverte = true;
915 jpm 396
}
397
 
980 jpm 398
function definirLargeurInfoBulle() {
399
	var largeurViewPort = $(window).width();
400
	var lageurInfoBulle = null;
401
	if (largeurViewPort < 800) {
402
		largeurInfoBulle = 400;
403
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
404
		largeurInfoBulle = 500;
405
	} else if (largeurViewPort >= 1200) {
406
		largeurInfoBulle = 600;
407
	}
408
	return largeurInfoBulle;
409
}
410
 
915 jpm 411
function afficherMessageChargement(element) {
412
	if ($('#chargement').get() == '') {
413
		$('#tpl-chargement').tmpl().appendTo(element);
414
	}
415
}
416
 
1035 aurelien 417
function afficherMessageChargementTitreInfoBulle() {
418
	$("#obs-station-titre").text("Chargement des observations");
419
}
420
 
915 jpm 421
function supprimerMessageChargement() {
422
	$('#chargement').remove();
423
}
424
 
425
function chargerObs(depart, total) {
939 jpm 426
	if (depart == 0 || depart < total) {
915 jpm 427
		var limite = 300;
428
		if (depart == 0) {
1035 aurelien 429
			obsStation = new Array();
430
			surClicPagePagination(0, null);
915 jpm 431
		}
1035 aurelien 432
 
939 jpm 433
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
980 jpm 434
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationInfos.id);
939 jpm 435
		urlObs = urlObs.replace(/\{nt\}/g, nt);
915 jpm 436
		urlObs = urlObs.replace(/\{start\}/g, depart);
437
 
438
		$.getJSON(urlObs, function(observations){
439
			obsStation = obsStation.concat(observations.observations);
1035 aurelien 440
			if (depart == 0) {
441
				actualiserInfosStation(observations);
442
				actualiserPagineur();
443
				creerTitreInfoBulle();
444
			}
445
			chargerObs(depart+limite, observations.total);
915 jpm 446
		});
447
	} else {
448
		if (pagineur.limite < total) {
449
			afficherPagination();
450
		}
1035 aurelien 451
		selectionnerOnglet("#obs-vue-"+pagineur.format);
452
		surClicPagePagination(0, null);
915 jpm 453
	}
454
}
455
 
1035 aurelien 456
function actualiserInfosStation(infos) {
457
	pointClique.stationInfos.commune = infos.commune;
458
	pointClique.stationInfos.obsNbre = infos.total;
459
}
460
 
461
function creerTitreInfoBulle() {
462
	$("#obs-total").text(station.obsNbre);
463
	$("#obs-commune").text(station.commune);
464
	var titre = '';
465
	titre += pointClique.stationInfos.obsNbre+' observation';
466
	titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
467
	titre += ' pour ';
468
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
469
		nomStation = 'la commune : ';
470
	} else {
471
		nomStation = 'la station : ';
472
	}
473
	titre += pointClique.stationInfos.nom;
474
	$("#obs-station-titre").text(titre);
475
}
476
 
939 jpm 477
function actualiserPagineur() {
980 jpm 478
	pagineur.stationId = pointClique.stationInfos.id;
1035 aurelien 479
	pagineur.total = pointClique.stationInfos.obsNbre;
939 jpm 480
	if (pagineur.total > 4) {
481
		pagineur.format = 'tableau';
482
	} else {
483
		pagineur.format = 'liste';
484
	}
485
}
486
 
915 jpm 487
function afficherPagination(observations) {
488
	$(".navigation").pagination(pagineur.total, {
489
		items_per_page:pagineur.limite,
490
		callback:surClicPagePagination,
491
		next_text:'Suivant',
492
		prev_text:'Précédent',
493
		prev_show_always:false,
494
		num_edge_entries:1,
953 jpm 495
		num_display_entries:4,
915 jpm 496
		load_first_page:true
497
	});
498
}
499
 
500
function surClicPagePagination(pageIndex, paginationConteneur) {
501
	var index = pageIndex * pagineur.limite;
502
	var indexMax = index + pagineur.limite;
503
	pagineur.depart = index;
504
	obsPage = new Array();
505
    for(index; index < indexMax; index++) {
506
    	obsPage.push(obsStation[index]);
507
    }
508
 
509
    supprimerMessageChargement();
510
    mettreAJourObservations();
511
	return false;
512
}
513
 
514
function mettreAJourObservations() {
515
	$("#obs-"+pagineur.format+"-lignes").empty();
516
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
517
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
518
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
519
 
520
	// Actualisation de Fancybox
941 jpm 521
	ajouterFomulaireContact("a.contact");
915 jpm 522
	if (pagineur.format == 'liste') {
836 jpm 523
		ajouterGaleriePhoto("a.cel-img");
524
	}
525
}
526
 
915 jpm 527
function initialiserContenuInfoBulle() {
980 jpm 528
	afficherMessageChargement('#observations');
529
	cacherContenuOnglets();
915 jpm 530
	afficherOnglets();
531
	ajouterTableauTriable("#obs-tableau");
532
	afficherTextStationId();
533
	corrigerLargeurInfoWindow();
534
}
535
 
980 jpm 536
function cacherContenuOnglets() {
537
	$("#obs-vue-tableau").css("display", "none");
538
	$("#obs-vue-liste").css("display", "none");
539
}
540
 
915 jpm 541
function afficherOnglets() {
542
	var $tabs = $('#obs').tabs();
543
	$('#obs').bind('tabsselect', function(event, ui) {
544
		if (ui.panel.id == 'obs-vue-tableau') {
545
			surClicAffichageTableau();
546
		} else if (ui.panel.id == 'obs-vue-liste') {
547
			surClicAffichageListe();
548
		}
549
	});
980 jpm 550
	if (pointClique.stationInfos.nbre > 4) {
551
		$tabs.tabs('select', "#obs-vue-tableau");
552
	} else {
553
		$tabs.tabs('select', "#obs-vue-liste");
554
	}
555
 
915 jpm 556
}
557
 
939 jpm 558
function selectionnerOnglet(onglet) {
980 jpm 559
	$(onglet).css('display', 'block');
939 jpm 560
	$('#obs').tabs('select', onglet);
561
}
562
 
915 jpm 563
function afficherTextStationId() {
980 jpm 564
	$('#obs-station-id').text(pointClique.stationInfos.id);
915 jpm 565
}
566
 
567
function corrigerLargeurInfoWindow() {
953 jpm 568
	$("#info-bulle").width($("#info-bulle").width() - 17);
915 jpm 569
}
570
 
571
function surClicAffichageTableau(event) {
572
	pagineur.format = 'tableau';
573
	mettreAJourObservations();
574
	mettreAJourTableauTriable("#obs-tableau");
575
}
576
 
577
function surClicAffichageListe(event) {
578
	pagineur.format = 'liste';
579
	mettreAJourObservations();
580
	ajouterGaleriePhoto("a.cel-img");
581
}
582
 
836 jpm 583
function ajouterTableauTriable(element) {
584
	// add parser through the tablesorter addParser method
585
	$.tablesorter.addParser({
586
		// Définition d'un id unique pour ce parsseur
587
		id: 'date_cel',
588
		is: function(s) {
915 jpm 589
			// doit retourner false si le parsseur n'est pas autodétecté
590
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
836 jpm 591
		},
915 jpm 592
		format: function(date) {
836 jpm 593
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
915 jpm 594
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
836 jpm 595
			// Remplace la date par un nombre de millisecondes pour trier numériquement
915 jpm 596
			return $.tablesorter.formatFloat(new Date(date).getTime());
836 jpm 597
		},
598
		// set type, either numeric or text
599
		type: 'numeric'
600
	});
601
	$(element).tablesorter({
602
        headers: {
915 jpm 603
			1: {
604
            	sorter:'date_cel'
605
        	}
606
    	}
607
	});
836 jpm 608
}
609
 
915 jpm 610
function mettreAJourTableauTriable(element) {
611
	$(element).trigger('update');
612
}
613
 
836 jpm 614
function ajouterGaleriePhoto(element) {
615
	$(element).fancybox({
915 jpm 616
		transitionIn:'elastic',
617
		transitionOut:'elastic',
618
		speedIn	:600,
619
		speedOut:200,
620
		overlayShow:true,
621
		titleShow:true,
622
		titlePosition:'inside',
623
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
624
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
625
			motif.exec(titre);
626
			var id = RegExp.$1;
627
			var info = $('#cel-info-'+id).clone().html();
628
			var tpl =
629
				'<div class="cel-legende">'+
630
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+
631
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
632
				'<\/div>';
633
			return tpl;
836 jpm 634
		}
1032 aurelien 635
	}).live('click', function(e) {
636
		if (e.stopPropagation) {
637
			e.stopPropagation();
638
		}
639
		return false;
640
	});
836 jpm 641
}
642
 
941 jpm 643
function ajouterFomulaireContact(element) {
644
	$(element).fancybox({
645
		transitionIn:'elastic',
646
		transitionOut:'elastic',
647
		speedIn	:600,
648
		speedOut:200,
649
		scrolling: 'no',
650
		titleShow: false,
651
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
652
			var element = selectedArray[selectedIndex];
653
 
654
			var motif = / contributeur-([0-9]+)$/;
655
			motif.exec($(element).attr('class'));
656
			var id = RegExp.$1;
950 jpm 657
			//console.log('Destinataire id : '+id);
941 jpm 658
			$("#fc_destinataire_id").attr('value', id);
659
 
660
			var motif = / obs-([0-9]+) /;
661
			motif.exec($(element).attr('class'));
662
			var id = RegExp.$1;
950 jpm 663
			//console.log('Obs id : '+id);
941 jpm 664
			chargerInfoObsPourMessage(id);
665
		},
666
		onCleanup: function() {
950 jpm 667
			//console.log('Avant fermeture fancybox');
941 jpm 668
			$("#fc_destinataire_id").attr('value', '');
669
			$("#fc_sujet").attr('value', '');
670
			$("#fc_message").text('');
671
		},
672
		onClosed: function(e) {
950 jpm 673
			//console.log('Fermeture fancybox');
941 jpm 674
			if (e.stopPropagation) {
675
				e.stopPropagation();
676
			}
677
			return false;
678
		}
679
	});
680
}
681
 
682
function chargerInfoObsPourMessage(idObs) {
980 jpm 683
	var nomSci = jQuery.trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
684
	var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
685
	var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
953 jpm 686
	var sujet = "Observation #"+idObs+" de "+nomSci;
687
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
941 jpm 688
	$("#fc_sujet").attr('value', sujet);
689
	$("#fc_message").text(message);
690
}
691
 
692
function initialiserFormulaireContact() {
950 jpm 693
	//console.log('Initialisation du form contact');
941 jpm 694
	$("#form-contact").validate({
695
		rules: {
696
			fc_sujet : "required",
697
			fc_message : "required",
953 jpm 698
			fc_utilisateur_courriel : {
699
				required : true,
700
				email : true}
941 jpm 701
		}
702
	});
703
	$("#form-contact").bind("submit", envoyerCourriel);
950 jpm 704
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
941 jpm 705
 
706
}
707
 
708
function envoyerCourriel() {
950 jpm 709
	//console.log('Formulaire soumis');
941 jpm 710
	if ($("#form-contact").valid()) {
950 jpm 711
		//console.log('Formulaire valide');
941 jpm 712
		//$.fancybox.showActivity();
713
		var destinataireId = $("#fc_destinataire_id").attr('value');
714
		var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
715
		var erreurMsg = "";
716
		var donnees = new Array();
717
		$.each($(this).serializeArray(), function (index, champ) {
718
			var cle = champ.name;
719
			cle = cle.replace(/^fc_/, '');
953 jpm 720
 
980 jpm 721
			if (cle == 'sujet') {
953 jpm 722
				champ.value += " - Carnet en ligne - Tela Botanica";
723
			}
724
			if (cle == 'message') {
725
				champ.value += "\n--\n"+
980 jpm 726
					"Ce message vous est envoyé par l'intermédiaire du widget carto "+
953 jpm 727
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
728
					"http://www.tela-botanica.org/widget:cel:carto";
729
			}
730
 
941 jpm 731
			donnees[index] = {'name':cle,'value':champ.value};
732
		});
733
		$.ajax({
734
			type : "POST",
735
			cache : false,
736
			url : urlMessage,
737
			data : donnees,
738
			beforeSend : function() {
739
				$(".msg").remove();
740
			},
741
			success : function(data) {
742
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
743
			},
744
			error : function(jqXHR, textStatus, errorThrown) {
745
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
746
				reponse = jQuery.parseJSON(jqXHR.responseText);
747
				if (reponse != null) {
748
					$.each(reponse, function (cle, valeur) {
749
						erreurMsg += valeur + "\n";
750
					});
751
				}
752
			},
753
			complete : function(jqXHR, textStatus) {
754
				var debugMsg = '';
755
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
756
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
757
					if (debugInfos != null) {
758
						$.each(debugInfos, function (cle, valeur) {
759
							debugMsg += valeur + "\n";
760
						});
761
					}
762
				}
763
				if (erreurMsg != '') {
764
					$("#fc-zone-dialogue").append('<p class="msg">'+
765
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
766
							'Vous pouvez signaler le disfonctionnement à <a href="'+
767
							'mailto:cel@tela-botanica.org'+'?'+
980 jpm 768
							'subject=Disfonctionnement du widget carto'+
941 jpm 769
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
770
							'">cel@tela-botanica.org</a>.'+
771
							'</p>');
772
				}
773
				if (DEBUG) {
774
					console.log('Débogage : '+debugMsg);
775
				}
950 jpm 776
				//console.log('Débogage : '+debugMsg);
777
				//console.log('Erreur : '+erreurMsg);
941 jpm 778
			}
779
		});
780
	}
781
	return false;
782
}
915 jpm 783
/*+--------------------------------------------------------------------------------------------------------+*/
784
// PANNEAU LATÉRAL
836 jpm 785
 
915 jpm 786
function initialiserAffichagePanneauLateral() {
787
	$('#panneau-lateral').height($(window).height() - 35);
841 jpm 788
 
915 jpm 789
	if (nt == '*') {
790
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
791
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
836 jpm 792
	}
939 jpm 793
	chargerTaxons(0, 0);
836 jpm 794
}
795
 
939 jpm 796
function chargerTaxons(depart, total) {
797
	if (depart == 0 || depart < total) {
798
		var limite = 7000;
950 jpm 799
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
939 jpm 800
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
801
		urlTax = urlTax.replace(/\{start\}/g, depart);
802
		$.getJSON(urlTax, function(infos) {
803
			taxonsCarte = taxonsCarte.concat(infos.taxons);
950 jpm 804
			//console.log("Nbre taxons :"+taxonsCarte.length);
939 jpm 805
			chargerTaxons(depart+limite, infos.total);
806
		});
807
	} else {
808
		if (nt == '*') {
809
			afficherTaxons();
810
		}
980 jpm 811
		afficherTitreCarte();
939 jpm 812
	}
813
}
814
 
815
function afficherTaxons() {
980 jpm 816
	$(".plantes-nbre").text(taxonsCarte.length);
939 jpm 817
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
818
	$('.taxon').live('click', filtrerParTaxon);
819
}
820
 
821
 
915 jpm 822
function afficherPanneauLateral() {
836 jpm 823
	$('#panneau-lateral').width(300);
824
	$('#pl-contenu').css('display', 'block');
825
	$('#pl-ouverture').css('display', 'none');
826
	$('#pl-fermeture').css('display', 'block');
827
	$('#carte').css('left', '300px');
828
 
829
	google.maps.event.trigger(map, 'resize');
830
};
831
 
915 jpm 832
function cacherPanneauLateral() {
836 jpm 833
	$('#panneau-lateral').width(24);
834
	$('#pl-contenu').css('display', 'none');
835
	$('#pl-ouverture').css('display', 'block');
836
	$('#pl-fermeture').css('display', 'none');
837
	$('#carte').css('left', '24px');
838
 
839
	google.maps.event.trigger(map, 'resize');
840
};
841
 
842
function filtrerParTaxon() {
843
	var ntAFiltrer = $('.nt', this).text();
844
	infoBulle.close();
845
	$('#taxon-'+nt).removeClass('taxon-actif');
846
	if (nt == ntAFiltrer) {
847
		nt = '*';
1035 aurelien 848
		//executerMarkerClusterer(pointsOrigine, boundsOrigine);
836 jpm 849
	} else {
1035 aurelien 850
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
851
		url = stationsUrl;
852
		var zoom = map.getZoom();
853
		var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
854
		var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
855
		url += '&zoom='+zoom+
856
			'&ne='+NELatLng+
857
			'&sw='+SWLatLng;
858
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
939 jpm 859
			stations = stationsFiltrees;
836 jpm 860
			nt = ntAFiltrer;
861
			$('#taxon-'+nt).addClass('taxon-actif');
1035 aurelien 862
			rafraichirMarqueurs(stations);
836 jpm 863
		});
864
	}
865
};
866
 
915 jpm 867
/*+--------------------------------------------------------------------------------------------------------+*/
868
// FONCTIONS UTILITAIRES
869
 
980 jpm 870
function ouvrirPopUp(element, nomPopUp, event) {
871
	var options =
872
		'width=650,'+
873
		'height=600,'+
874
		'scrollbars=yes,'+
875
		'directories=no,'+
876
		'location=no,'+
877
		'menubar=no,'+
878
		'status=no,'+
879
		'toolbar=no';
880
	var popUp = window.open(element.href, nomPopUp, options);
881
	if (window.focus) {
882
		popUp.focus();
883
	}
884
	return arreter(event);
885
};
886
 
887
function ouvrirNouvelleFenetre(element, event) {
888
	window.open(element.href);
889
	return arreter(event);
890
}
891
 
915 jpm 892
function arreter(event) {
893
	if (event.stopPropagation) {
894
		event.stopPropagation();
895
	} else if (window.event) {
896
		window.event.cancelBubble = true;
897
	}
980 jpm 898
	if (event.preventDefault) {
899
		event.preventDefault();
900
	}
901
	event.returnValue = false;
915 jpm 902
	return false;
903
}
904
 
836 jpm 905
/**
906
 * +-------------------------------------+
907
 * Number.prototype.formaterNombre
908
 * +-------------------------------------+
909
 * Params (facultatifs):
910
 * - Int decimales: nombre de decimales (exemple: 2)
911
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
912
 * - String separateurMilliers: comme son nom l'indique
913
 * Returns:
914
 * - String chaine formatee
915
 * @author	::mastahbenus::
916
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
917
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
918
 */
919
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
920
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
921
 
922
	function is_int(nbre) {
923
		nbre = nbre.replace(',', '.');
924
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
925
	}
926
 
927
	if (decimales == undefined) {
928
		if (is_int(_sNombre)) {
929
			decimales = 0;
930
		} else {
931
			decimales = 2;
932
		}
933
	}
934
	if (signe == undefined) {
935
		if (is_int(_sNombre)) {
936
			signe = '';
937
		} else {
938
			signe = '.';
939
		}
940
	}
941
	if (separateurMilliers == undefined) {
942
		separateurMilliers = ' ';
943
	}
944
 
945
	function separeMilliers (sNombre) {
946
		var sRetour = "";
947
		while (sNombre.length % 3 != 0) {
948
			sNombre = "0"+sNombre;
949
		}
950
		for (i = 0; i < sNombre.length; i += 3) {
951
			if (i == sNombre.length-1) separateurMilliers = '';
952
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
953
		}
954
		while (sRetour.substr(0, 1) == "0") {
955
			sRetour = sRetour.substr(1);
956
		}
957
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
958
	}
959
 
960
	if (_sNombre.indexOf('.') == -1) {
961
		for (i = 0; i < decimales; i++) {
962
			_sDecimales += "0";
963
		}
964
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
965
	} else {
966
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
967
		if (sDecimalesTmp.length > decimales) {
968
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
969
			var nDiv = 1;
970
			for (i = 0; i < nDecimalesManquantes; i++) {
971
				nDiv *= 10;
972
			}
973
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
974
		}
975
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
976
	}
977
	return _sRetour;
915 jpm 978
}
979
 
980
function debug(objet) {
981
	var msg = '';
982
	if (objet != null) {
983
		$.each(objet, function (cle, valeur) {
984
			msg += cle+":"+valeur + "\n";
985
		});
986
	} else {
987
		msg = "La variable vaut null.";
988
	}
989
	console.log(msg);
836 jpm 990
}