Subversion Repositories eFlore/Applications.cel

Rev

Rev 841 | Rev 939 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 841 Rev 915
Line 29... Line 29...
29
	isPng: true,
29
	isPng: true,
30
	alt: "OpenStreetMap",
30
	alt: "OpenStreetMap",
31
	name: "OSM",
31
	name: "OSM",
32
	maxZoom: 19
32
	maxZoom: 19
33
});
33
});
34
 
-
 
-
 
34
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
-
 
35
var station = {'commune':'', 'obsNbre':0};
-
 
36
var obsStation = new Array();
-
 
37
var obsPage = new Array();
35
/*+--------------------------------------------------------------------------------------------------------+*/
38
/*+--------------------------------------------------------------------------------------------------------+*/
36
// INITIALISATION DU CODE
39
// INITIALISATION DU CODE
Line 37... Line -...
37
 
-
 
38
 
40
 
39
//Déclenchement d'actions quand JQuery et le document HTML sont OK
41
//Déclenchement d'actions quand JQuery et le document HTML sont OK
40
$(document).ready(function() {
42
$(document).ready(function() {
41
	initialiserWidget();
43
	initialiserWidget();
42
});
-
 
43
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
Line 44... Line 44...
44
// FONCTIONS
44
});
45
 
45
 
46
function initialiserWidget() {
46
function initialiserWidget() {
47
	afficherStats();
47
	afficherStats();
Line 52... Line 52...
52
	initialiserInfoBulle();
52
	initialiserInfoBulle();
53
	chargerLimitesCommunales();
53
	chargerLimitesCommunales();
54
	rafraichirCarte();
54
	rafraichirCarte();
55
}
55
}
Line -... Line 56...
-
 
56
 
-
 
57
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
58
// AFFICHAGE GÉNÉRAL
56
 
59
 
57
function afficherStats() {
60
function afficherStats() {
58
	// Ajout du nombre de communes où des observations ont eu lieu
61
	// Ajout du nombre de communes où des observations ont eu lieu
59
	$('#commune-nbre').append(obs.stats.communes.formaterNombre());
62
	$('#commune-nbre').append(obs.stats.communes.formaterNombre());
60
	// Ajout du nombre d'observations
63
	// Ajout du nombre d'observations
61
	$('#obs-nbre').append(obs.stats.observations.formaterNombre());
64
	$('#obs-nbre').append(obs.stats.observations.formaterNombre());
62
	// Ajout du nombre de plantes
65
	// Ajout du nombre de plantes
63
	$('.plantes-nbre').append(plantesNbre.formaterNombre());
66
	$('.plantes-nbre').append(plantesNbre.formaterNombre());
Line -... Line 67...
-
 
67
}
-
 
68
 
-
 
69
/*+--------------------------------------------------------------------------------------------------------+*/
64
}
70
// CARTE
65
 
71
 
66
function initialiserAffichageCarte() {
72
function initialiserAffichageCarte() {
Line 67... Line 73...
67
	$('#carte').height($(window).height() - 35);
73
	$('#carte').height($(window).height() - 35);
68
	$('#carte').width($(window).width() - 24);
74
	$('#carte').width($(window).width() - 24);
69
	
75
	
70
	if (nt != '*') {
76
	if (nt != '*') {
Line 71... Line -...
71
		$('#carte').css('left', 0);
-
 
72
	}
-
 
73
}
-
 
74
 
-
 
75
function initialiserAffichagePanneauLateral() {
-
 
76
	$('#panneau-lateral').height($(window).height() - 35);
-
 
77
	
-
 
78
	if (nt == '*') {
-
 
79
		$('#pl-ouverture').bind('click', afficher);
-
 
80
		$('#pl-fermeture').bind('click', cacher);
-
 
81
		$('.taxon').live('click', filtrerParTaxon);
77
		$('#carte').css('left', 0);
82
	}
78
	}
83
}
79
}
84
 
80
 
85
function initialiserCarte() {
81
function initialiserCarte() {
Line 86... Line -...
86
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
-
 
87
	// Ajout de la couche OSM à la carte
-
 
88
	map.mapTypes.set('OSM', osmMapType);
-
 
89
}
-
 
Line 90... Line 82...
90
 
82
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
91
function initialiserInfoBulle() {
83
	// Ajout de la couche OSM à la carte
92
	google.maps.event.addListener(infoBulle, 'domready', modifierContenuInfoBulle);
84
	map.mapTypes.set('OSM', osmMapType);
93
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
85
}
Line 118... Line 110...
118
 
110
 
Line 119... Line 111...
119
		bounds.extend(maLatLng);
111
		bounds.extend(maLatLng);
120
		
112
		
121
		google.maps.event.addListener(point, 'click', function() {
-
 
122
			pointClique =  this;
113
		google.maps.event.addListener(point, 'click', function() {
Line 123... Line 114...
123
			
114
			pointClique =  this;
124
			infoBulle.open(map, this);
115
			infoBulle.open(map, this);
125
			
116
			
126
			var limites = map.getBounds();
117
			var limites = map.getBounds();
127
			var centre = limites.getCenter();
118
			var centre = limites.getCenter();
Line 128... Line 119...
128
			var nordEst = limites.getNorthEast();
119
			var nordEst = limites.getNorthEast();
129
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
120
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
130
			map.panTo(centreSudLatLng);
121
			map.panTo(centreSudLatLng);
Line 131... Line 122...
131
			
122
			
132
			afficherMsgChargement();
123
			afficherInfoBulle();
Line 142... Line 133...
142
	}
133
	}
Line 143... Line 134...
143
	
134
	
144
	executerMarkerClusterer(points, bounds);
135
	executerMarkerClusterer(points, bounds);
Line 145... Line 136...
145
}
136
}
-
 
137
 
-
 
138
function deplacerCartePointClique() {
-
 
139
	map.panTo(pointClique.position);
146
 
140
}
147
function modifierContenuInfoBulle() {
141
 
148
	// Onglet Tableau : Jquery => TableSorter
142
function executerMarkerClusterer(points, bounds) {
149
	if ($("#observations table").get() != '') {
143
	if (markerClusterer) {
-
 
144
		markerClusterer.clearMarkers();
-
 
145
	}
-
 
146
	markerClusterer = new MarkerClusterer(map, points);
-
 
147
	map.fitBounds(bounds);
-
 
148
}
-
 
149
 
-
 
150
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
151
// INFO BULLE
-
 
152
 
-
 
153
function initialiserInfoBulle() {
-
 
154
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
-
 
155
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
-
 
156
}
-
 
157
 
150
		ajouterTableauTriable("#observations table");
158
function afficherInfoBulle() {
-
 
159
	var obsHtml = $("#tpl-obs").html();
-
 
160
	infoBulle.setContent(obsHtml);
-
 
161
}
151
	}
162
 
-
 
163
function afficherMessageChargement(element) {
-
 
164
	if ($('#chargement').get() == '') {
-
 
165
		$('#tpl-chargement').tmpl().appendTo(element);
-
 
166
	}
-
 
167
}
-
 
168
 
-
 
169
function supprimerMessageChargement() {
-
 
170
	$('#chargement').remove();
-
 
171
}
-
 
172
 
-
 
173
function lancerChargementObs() {
-
 
174
	var urlObsNbre = urlObsStation;
-
 
175
	urlObsNbre = urlObsNbre.replace(/\{action\}/g, 'observations-nombre');
-
 
176
	urlObsNbre = urlObsNbre.replace(/\{stationId\}/g, pointClique.stationId);
-
 
177
	console.log("Lancement recup nombre");
-
 
178
	$.getJSON(urlObsNbre, function(infos){
-
 
179
		console.log("Lancement charger obs");
-
 
180
		chargerObs(0, infos.obsNbre);
-
 
181
		station = infos;
-
 
182
		actualiserPagineur();
-
 
183
		creerTitreInfoBulle();
-
 
184
	});
-
 
185
}
-
 
186
 
-
 
187
function actualiserPagineur() {
-
 
188
	pagineur.stationId = pointClique.stationId;
-
 
189
	pagineur.total = station.obsNbre;
-
 
190
	console.log(pagineur.total);
-
 
191
	if (pagineur.total > 4) {
-
 
192
		pagineur.format = 'tableau';
-
 
193
	} else {
-
 
194
		pagineur.format = 'liste';
-
 
195
	}
-
 
196
}
-
 
197
 
-
 
198
function chargerObs(depart, total) {
-
 
199
	if (depart < total) {
-
 
200
		var limite = 300;
-
 
201
		if (depart == 0) {
-
 
202
			obsStation = new Array();
-
 
203
		}
-
 
204
		console.log("Chargement de "+depart+" à "+(depart+limite));
-
 
205
		var urlObs = urlObsStation+'&start={start}&limit='+limite;
-
 
206
		urlObs = urlObs.replace(/\{action\}/g, 'observations');
-
 
207
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
-
 
208
		urlObs = urlObs.replace(/\{start\}/g, depart);
-
 
209
		
-
 
210
		$.getJSON(urlObs, function(observations){
-
 
211
			obsStation = obsStation.concat(observations.observations);
-
 
212
			console.log("Chargement ok");
-
 
213
			chargerObs(depart+limite, total);
-
 
214
		});
-
 
215
	} else {
-
 
216
		if (pagineur.limite < total) {
-
 
217
			afficherPagination();
-
 
218
		} else {
-
 
219
			surClicPagePagination(0, null);
-
 
220
		}
-
 
221
	}
-
 
222
}
-
 
223
 
-
 
224
 
-
 
225
function afficherPagination(observations) {
-
 
226
	$(".navigation").pagination(pagineur.total, {
-
 
227
		items_per_page:pagineur.limite,
-
 
228
		callback:surClicPagePagination,
-
 
229
		next_text:'Suivant',
-
 
230
		prev_text:'Précédent',
-
 
231
		prev_show_always:false,
-
 
232
		num_edge_entries:1,
-
 
233
		num_display_entries:5,
-
 
234
		load_first_page:true
-
 
235
	});
-
 
236
}
-
 
237
 
-
 
238
function surClicPagePagination(pageIndex, paginationConteneur) {
-
 
239
	var index = pageIndex * pagineur.limite;
-
 
240
	var indexMax = index + pagineur.limite;
-
 
241
	pagineur.depart = index;
-
 
242
	obsPage = new Array();
-
 
243
    for(index; index < indexMax; index++) {
-
 
244
    	obsPage.push(obsStation[index]);
-
 
245
    }
-
 
246
    
-
 
247
    supprimerMessageChargement();
-
 
248
    mettreAJourObservations();
-
 
249
	return false;
-
 
250
}
-
 
251
 
-
 
252
function mettreAJourObservations() {
-
 
253
	$("#obs-"+pagineur.format+"-lignes").empty();
-
 
254
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
-
 
255
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
-
 
256
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
-
 
257
	
152
	// Onglet Liste : Jquery => FancyBox
258
	// Actualisation de Fancybox
153
	if ($("#observations ol").get() != '') {
259
	if (pagineur.format == 'liste') {
154
		ajouterGaleriePhoto("a.cel-img");
260
		ajouterGaleriePhoto("a.cel-img");
Line -... Line 261...
-
 
261
	}
-
 
262
}
-
 
263
 
-
 
264
function creerTitreInfoBulle() {
-
 
265
	$("#obs-total").append(station.obsNbre);
-
 
266
	$("#obs-commune").append(station.commune);	
-
 
267
}
-
 
268
 
-
 
269
function initialiserContenuInfoBulle() {
-
 
270
	afficherOnglets();
-
 
271
	afficherMessageChargement('#observations');
-
 
272
	ajouterTableauTriable("#obs-tableau");
-
 
273
	afficherTextStationId();
-
 
274
	corrigerLargeurInfoWindow();
-
 
275
}
-
 
276
 
-
 
277
function afficherOnglets() {
-
 
278
	var $tabs = $('#obs').tabs();
-
 
279
	$('#obs').bind('tabsselect', function(event, ui) {
-
 
280
		if (ui.panel.id == 'obs-vue-tableau') {
-
 
281
			surClicAffichageTableau();
-
 
282
		} else if (ui.panel.id == 'obs-vue-liste') {
-
 
283
			surClicAffichageListe();
-
 
284
		}
-
 
285
	});
-
 
286
	$tabs.tabs('select', "#obs-vue-"+pagineur.format);
-
 
287
}
-
 
288
 
-
 
289
function afficherTextStationId() {
-
 
290
	$('#obs-station-id').text(pointClique.stationId);
-
 
291
}
-
 
292
 
-
 
293
function corrigerLargeurInfoWindow() {
-
 
294
	$("#info-bulle").width($("#info-bulle").width() - 16);
-
 
295
}
-
 
296
 
-
 
297
function surClicAffichageTableau(event) {
-
 
298
	console.log('tableau');
-
 
299
	pagineur.format = 'tableau';
-
 
300
	mettreAJourObservations();
-
 
301
	mettreAJourTableauTriable("#obs-tableau");
-
 
302
}
-
 
303
 
-
 
304
function surClicAffichageListe(event) {
-
 
305
	console.log('liste');
-
 
306
	pagineur.format = 'liste';
-
 
307
	mettreAJourObservations();
155
	}
308
	ajouterGaleriePhoto("a.cel-img");
156
}
309
}
157
 
310
 
158
function ajouterTableauTriable(element) {
311
function ajouterTableauTriable(element) {
159
	// add parser through the tablesorter addParser method 
312
	// add parser through the tablesorter addParser method 
160
	$.tablesorter.addParser({ 
313
	$.tablesorter.addParser({ 
161
		// Définition d'un id unique pour ce parsseur 
314
		// Définition d'un id unique pour ce parsseur 
162
		id: 'date_cel', 
315
		id: 'date_cel', 
163
		is: function(s) { 
316
		is: function(s) { 
164
			// retourne false si le parsseur n'est pas autodétecté 
317
			// doit retourner false si le parsseur n'est pas autodétecté
165
			return false; 
318
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
166
		}, 
319
		}, 
167
		format: function(s) { 
320
		format: function(date) { 
168
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
321
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
169
			s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
322
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
170
			// Remplace la date par un nombre de millisecondes pour trier numériquement
323
			// Remplace la date par un nombre de millisecondes pour trier numériquement
171
			return $.tablesorter.formatFloat(new Date(s).getTime());
324
			return $.tablesorter.formatFloat(new Date(date).getTime());
172
		}, 
325
		}, 
173
		// set type, either numeric or text 
326
		// set type, either numeric or text 
174
		type: 'numeric' 
327
		type: 'numeric' 
175
	});
328
	});
176
	$(element).tablesorter({ 
329
	$(element).tablesorter({ 
177
        headers: { 
-
 
178
            1: { 
330
        headers: { 
179
                sorter:'date_cel' 
331
			1: { 
180
            } 
-
 
181
        } 
-
 
182
    });
-
 
183
}
-
 
184
 
-
 
185
function ajouterGaleriePhoto(element) {
-
 
186
	$(element).fancybox({
-
 
187
		transitionIn : 'elastic',
-
 
188
		transitionOut : 'elastic',
-
 
189
		speedIn	 : 600, 
-
 
190
		speedOut : 200, 
-
 
191
		overlayShow : true
-
 
192
	}).live('click', function(e) {
-
 
193
		if (e.stopPropagation) {
-
 
194
			e.stopPropagation();
332
            	sorter:'date_cel' 
195
		}
333
        	} 
Line 196... Line 334...
196
		return false;
334
    	} 
197
	});
335
	});
198
}
336
}
Line 199... Line 337...
199
 
337
 
200
function deplacerCartePointClique() {
338
function mettreAJourTableauTriable(element) {
201
	map.panTo(pointClique.position);
339
	$(element).trigger('update');
-
 
340
}
-
 
341
 
202
}
342
function ajouterGaleriePhoto(element) {
-
 
343
	$(element).fancybox({
-
 
344
		transitionIn:'elastic',
-
 
345
		transitionOut:'elastic',
203
 
346
		speedIn	:600, 
-
 
347
		speedOut:200,
204
function executerMarkerClusterer(points, bounds) {
348
		overlayShow:true,
-
 
349
		titleShow:true,
-
 
350
		titlePosition:'inside',
-
 
351
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
-
 
352
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
-
 
353
			motif.exec(titre);
-
 
354
			var id = RegExp.$1;
-
 
355
			var info = $('#cel-info-'+id).clone().html();
-
 
356
			var tpl = 
205
	if (markerClusterer) {
357
				'<div class="cel-legende">'+
206
		markerClusterer.clearMarkers();
-
 
207
	}
358
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
208
	markerClusterer = new MarkerClusterer(map, points);
359
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
209
	map.fitBounds(bounds);
360
				'<\/div>';
-
 
361
			return tpl;
210
}
362
		}
-
 
363
		}).live('click', function(e) {
211
 
364
			if (e.stopPropagation) {
Line 212... Line -...
212
function afficherMsgChargement() {
-
 
213
	var chargement = document.getElementById('chargement').cloneNode(true);
-
 
214
	chargement.setAttribute('id', 'chargement-copie');
-
 
215
	infoBulle.setContent(chargement);
-
 
216
}
365
				e.stopPropagation();
217
 
-
 
218
var pagineur = {'limite':150, 'obsTotal':0, 'stationId':null, 'format':null};
-
 
219
 
-
 
220
function handlePaginationClick(new_page_index, pagination_container) {
366
			}
221
	$('.obs-liste-conteneur').css('display', 'none');
-
 
222
	$('#chargement').clone().attr('id', 'chargement-copie').appendTo('#observations').css('display', 'block');
-
 
223
	console.log($('#chargement').get());
-
 
224
	
-
 
225
	var start = new_page_index * pagineur.limite;
-
 
226
	var url = urlObs+
-
 
227
	'&format='+pagineur.format+
-
 
228
	'&station='+pagineur.stationId+
-
 
229
	'&start='+start+
-
 
230
	'&limit='+pagineur.limite;
-
 
231
	$.get(url, function(observations) {
-
 
232
		$('#chargement-copie').remove();
-
 
Line 233... Line 367...
233
		$('.obs-liste-conteneur').css('display', 'block');
367
			return false;
234
		$('#obs-liste').empty();
368
		});
235
		$('#obs-liste').append(observations);
-
 
236
	});
-
 
Line 237... Line -...
237
	return false;
-
 
238
}
-
 
239
 
-
 
240
function chargerFormatObs(stationId, format) {
-
 
241
	pagineur.obsTotal = parseInt($('#obs-total').text());
369
}
242
	pagineur.stationId = stationId;
-
 
243
	pagineur.format = format;
370
 
244
	
-
 
245
	var start = 1 * pagineur.limite;
-
 
246
	var url = urlStation+
-
 
247
		'&format='+format+
371
/*+--------------------------------------------------------------------------------------------------------+*/
248
		'&station='+stationId+
-
 
249
		'&start='+start+
-
 
250
		'&limit='+pagineur.limite;
-
 
251
	$.get(url, function(observations){
-
 
252
		infoBulle.setContent(observations);
-
 
253
		// First Parameter: number of items
-
 
254
		// Second Parameter: options object
-
 
255
		$("#pagination").pagination(pagineur.obsTotal, {
-
 
256
			items_per_page:pagineur.limite,
-
 
257
			callback:handlePaginationClick
-
 
258
		});
372
// PANNEAU LATÉRAL
259
	});
373
 
260
}
-
 
261
 
374
function initialiserAffichagePanneauLateral() {
Line 262... Line 375...
262
function arreter(event) {
375
	$('#panneau-lateral').height($(window).height() - 35);
263
	if (event.stopPropagation) {
376
	
264
		event.stopPropagation();
377
	if (nt == '*') {
265
	} else if (window.event) {
378
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
266
		window.event.cancelBubble = true;
379
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
267
	}
380
		$('.taxon').live('click', filtrerParTaxon);
Line 268... Line 381...
268
	return false;
381
	}
269
}
382
}
Line 270... Line 383...
270
 
383
 
271
function afficher() {
384
function afficherPanneauLateral() {
272
	$('#panneau-lateral').width(300);
385
	$('#panneau-lateral').width(300);
273
	$('#pl-contenu').css('display', 'block');
386
	$('#pl-contenu').css('display', 'block');
274
	$('#pl-ouverture').css('display', 'none');
387
	$('#pl-ouverture').css('display', 'none');
275
	$('#pl-fermeture').css('display', 'block');
388
	$('#pl-fermeture').css('display', 'block');
Line 311... Line 424...
311
			rafraichirCarte();
424
			rafraichirCarte();
312
		});
425
		});
313
	}
426
	}
314
};
427
};
Line -... Line 428...
-
 
428
 
-
 
429
/*+--------------------------------------------------------------------------------------------------------+*/
-
 
430
// FONCTIONS UTILITAIRES
-
 
431
 
-
 
432
function arreter(event) {
-
 
433
	if (event.stopPropagation) {
-
 
434
		event.stopPropagation();
-
 
435
	} else if (window.event) {
-
 
436
		window.event.cancelBubble = true;
-
 
437
	}
-
 
438
	return false;
-
 
439
}
315
 
440
 
316
/**
441
/**
317
 * +-------------------------------------+
442
 * +-------------------------------------+
318
 * Number.prototype.formaterNombre
443
 * Number.prototype.formaterNombre
319
 * +-------------------------------------+
444
 * +-------------------------------------+
Line 384... Line 509...
384
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
509
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
385
		}
510
		}
386
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
511
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
387
	}
512
	}
388
	return _sRetour;
513
	return _sRetour;
-
 
514
}
-
 
515
 
-
 
516
function debug(objet) {
-
 
517
	var msg = '';
-
 
518
	if (objet != null) {
-
 
519
		$.each(objet, function (cle, valeur) {
-
 
520
			msg += cle+":"+valeur + "\n";
-
 
521
		});
-
 
522
	} else {
-
 
523
		msg = "La variable vaut null.";
-
 
524
	}
-
 
525
	console.log(msg);
389
}
526
}
390
527