Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1032 Rev 1035
Line 2... Line 2...
2
// PARAMÊTRES et CONSTANTES
2
// PARAMÊTRES et CONSTANTES
3
// Mettre à true pour afficher les messages de débogage
3
// Mettre à true pour afficher les messages de débogage
4
var DEBUG = false; 
4
var DEBUG = false; 
5
var communeImageUrl = 'http://www.tela-botanica.org/commun/icones/carto/commune.png';
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';
6
var pointImageUrl = 'http://www.tela-botanica.org/commun/icones/carto/point2.png';
7
var groupeImageUrlTpl = 'http://localhost/jrest/CelWidgetMap/icone-groupe?type={type}&nbre={nbre}'
7
var groupeImageUrlTpl = 'http://localhost/service:cel:CelWidgetMap/icone-groupe?type={type}&nbre={nbre}'
8
var pointsOrigine = null;
8
var pointsOrigine = null;
9
var boundsOrigine = null;
9
var boundsOrigine = null;
10
var markerClusterer = null;
10
var markerClusterer = null;
11
var map = null;
11
var map = null;
12
var infoBulle = new google.maps.InfoWindow();
12
var infoBulle = new google.maps.InfoWindow();
Line 43... Line 43...
43
var obsPage = new Array();
43
var obsPage = new Array();
44
var taxonsCarte = new Array();
44
var taxonsCarte = new Array();
45
var mgr = null;
45
var mgr = null;
46
var marqueursCache = new Array();
46
var marqueursCache = new Array();
47
var zonesCache = new Array();
47
var zonesCache = new Array();
-
 
48
var requeteChargementPoints;
48
/*+--------------------------------------------------------------------------------------------------------+*/
49
/*+--------------------------------------------------------------------------------------------------------+*/
49
// INITIALISATION DU CODE
50
// INITIALISATION DU CODE
Line 50... Line 51...
50
 
51
 
51
//Déclenchement d'actions quand JQuery et le document HTML sont OK
52
//Déclenchement d'actions quand JQuery et le document HTML sont OK
Line 150... Line 151...
150
	});
151
	});
151
}
152
}
152
function programmerRafraichissementCarte() {
153
function programmerRafraichissementCarte() {
153
	if(timer != null) {
154
	if(timer != null) {
154
        window.clearTimeout(timer);
155
        window.clearTimeout(timer);
155
    }   
156
    }
-
 
157
	if(requeteChargementPoints != null) {
-
 
158
		requeteChargementPoints.abort();
-
 
159
	}
156
	timer = window.setTimeout(function() {
160
	timer = window.setTimeout(function() {
157
		var zoom = map.getZoom();
161
		var zoom = map.getZoom();
158
		var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
162
		var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
159
		var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
163
		var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
160
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
164
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
161
    }, 400);		
165
    }, 400);		
162
}
166
}
Line 163... Line -...
163
 
-
 
164
function collecterBorduresEtChargerMarqueurs() {
-
 
165
 
-
 
166
}
-
 
167
 
167
 
168
var premierChargement = true;
168
var premierChargement = true;
169
var marqueurs = new Array();
169
var marqueurs = new Array();
170
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
170
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
171
	var url = stationsUrl+
171
	var url = stationsUrl+
Line 175... Line 175...
175
	
175
	
176
	if(infoBulleOuverte) {
176
	if(infoBulleOuverte) {
177
		return;
177
		return;
Line -... Line 178...
-
 
178
	}
-
 
179
	
-
 
180
	if(requeteChargementPoints != null) {
-
 
181
		requeteChargementPoints.abort();
-
 
182
	}
178
	}
183
	
-
 
184
	afficherMessageChargementPoints();
-
 
185
	requeteChargementPoints = $.getJSON(url, function(data) {
-
 
186
		rafraichirMarqueurs(data);
-
 
187
		cacherMessageChargementPoints();
-
 
188
	});
-
 
189
}
-
 
190
 
-
 
191
function afficherMessageChargementPoints() {
-
 
192
	$('#zone-chargement-point').css('display','block');
-
 
193
}
-
 
194
 
-
 
195
function cacherMessageChargementPoints() {
179
	
196
	$('#zone-chargement-point').css('display','none');
-
 
197
}
180
	$.getJSON(url, function(data) {
198
 
181
		
199
function rafraichirMarqueurs(data) {
182
		$.each(marqueurs, function(index, marqueur) {
200
	$.each(marqueurs, function(index, marqueur) {
183
			marqueur.setMap(null);
201
		marqueur.setMap(null);
184
		});
202
	});
185
		marqueurs = new Array();
203
	marqueurs = new Array();
186
		
204
	
187
		stations = data;
205
	stations = data;
188
		afficherTitreCarte();
206
	afficherTitreCarte();
189
		
207
	
190
		$.each(stations.points, function (index, station) {		
208
	$.each(stations.points, function (index, station) {		
191
			if(station != null) {
209
		if(station != null) {
192
				marqueurs.push(creerMarqueur(station));
-
 
193
			}
210
			marqueurs.push(creerMarqueur(station));
194
        });
211
		}
Line 195... Line 212...
195
	});
212
	});
196
}
213
}
Line 285... Line 302...
285
		google.maps.event.addListener(marqueur, 'click', surClickGroupe);
302
		google.maps.event.addListener(marqueur, 'click', surClickGroupe);
286
	}
303
	}
287
}
304
}
Line 288... Line 305...
288
 
305
 
-
 
306
function surClickMarqueur(event) {
289
function surClickMarqueur(event) {
307
	
290
	pointClique =  this;
308
	pointClique = this;
291
	infoBulle.open(map, this);
309
	infoBulle.open(map, this);
-
 
310
	actualiserPagineur();
-
 
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);
292
	actualiserPagineur();
317
	
293
	afficherInfoBulle();
-
 
294
	programmerRafraichissementCarte();
318
	afficherInfoBulle();
Line 295... Line 319...
295
}
319
}
296
 
320
 
297
function surClickGroupe() {
321
function surClickGroupe() {
Line 365... Line 389...
365
function afficherInfoBulle() {
389
function afficherInfoBulle() {
366
	var obsHtml = $("#tpl-obs").html();
390
	var obsHtml = $("#tpl-obs").html();
367
	var largeur = definirLargeurInfoBulle();
391
	var largeur = definirLargeurInfoBulle();
368
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
392
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
369
	infoBulle.setContent(obsHtml);
393
	infoBulle.setContent(obsHtml);
-
 
394
	chargerObs(0, 0);
370
	infoBulleOuverte = true;
395
	infoBulleOuverte = true;
371
}
396
}
Line 372... Line 397...
372
 
397
 
373
function definirLargeurInfoBulle() {
398
function definirLargeurInfoBulle() {
Line 387... Line 412...
387
	if ($('#chargement').get() == '') {
412
	if ($('#chargement').get() == '') {
388
		$('#tpl-chargement').tmpl().appendTo(element);
413
		$('#tpl-chargement').tmpl().appendTo(element);
389
	}
414
	}
390
}
415
}
Line -... Line 416...
-
 
416
 
-
 
417
function afficherMessageChargementTitreInfoBulle() {
-
 
418
	$("#obs-station-titre").text("Chargement des observations");	
-
 
419
}
391
 
420
 
392
function supprimerMessageChargement() {
421
function supprimerMessageChargement() {
393
	$('#chargement').remove();
422
	$('#chargement').remove();
Line 394... Line 423...
394
}
423
}
395
 
424
 
396
function chargerObs(depart, total) {
425
function chargerObs(depart, total) {
397
	if (depart == 0 || depart < total) {
426
	if (depart == 0 || depart < total) {
398
		var limite = 300;
427
		var limite = 300;
-
 
428
		if (depart == 0) {
399
		if (depart == 0) {
429
			obsStation = new Array();	
400
			obsStation = new Array();
-
 
-
 
430
			surClicPagePagination(0, null);
401
		}
431
		}
402
		//console.log("Chargement de "+depart+" à "+(depart+limite));
432
		
403
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
433
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
404
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationInfos.id);
434
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationInfos.id);
Line 405... Line 435...
405
		urlObs = urlObs.replace(/\{nt\}/g, nt);
435
		urlObs = urlObs.replace(/\{nt\}/g, nt);
406
		urlObs = urlObs.replace(/\{start\}/g, depart);
436
		urlObs = urlObs.replace(/\{start\}/g, depart);
-
 
437
		
-
 
438
		$.getJSON(urlObs, function(observations){
-
 
439
			obsStation = obsStation.concat(observations.observations);
-
 
440
			if (depart == 0) {
-
 
441
				actualiserInfosStation(observations);
407
		
442
				actualiserPagineur();
408
		$.getJSON(urlObs, function(observations){
443
				creerTitreInfoBulle();
409
			obsStation = obsStation.concat(observations.observations);
444
			}
410
			chargerObs(depart+limite, pointClique.stationInfos.nbre);
445
			chargerObs(depart+limite, observations.total);
411
		});
446
		});
412
	} else {
-
 
413
		if (pagineur.limite < total) {
-
 
414
			afficherPagination();
-
 
415
			surClicPagePagination(0, null);
-
 
416
		} else {
447
	} else {
-
 
448
		if (pagineur.limite < total) {
-
 
449
			afficherPagination();
-
 
450
		}
-
 
451
		selectionnerOnglet("#obs-vue-"+pagineur.format);
-
 
452
		surClicPagePagination(0, null);
-
 
453
	}
-
 
454
}
-
 
455
 
-
 
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)) {
417
			surClicPagePagination(0, null);
469
		nomStation = 'la commune : ';
-
 
470
	} else {
-
 
471
		nomStation = 'la station : ';
418
			selectionnerOnglet("#obs-vue-"+pagineur.format);
472
	}
Line 419... Line 473...
419
		}
473
	titre += pointClique.stationInfos.nom;
420
	}
474
	$("#obs-station-titre").text(titre);	
421
}
475
}
422
 
476
 
423
function actualiserPagineur() {
477
function actualiserPagineur() {
424
	pagineur.stationId = pointClique.stationInfos.id;
478
	pagineur.stationId = pointClique.stationInfos.id;
425
	pagineur.total = pointClique.stationInfos.nbre;
479
	pagineur.total = pointClique.stationInfos.obsNbre;
426
	if (pagineur.total > 4) {
480
	if (pagineur.total > 4) {
Line 468... Line 522...
468
	if (pagineur.format == 'liste') {
522
	if (pagineur.format == 'liste') {
469
		ajouterGaleriePhoto("a.cel-img");
523
		ajouterGaleriePhoto("a.cel-img");
470
	}
524
	}
471
}
525
}
Line 472... Line -...
472
 
-
 
473
function afficherTitreInfoBulle() {
-
 
474
	var titre = '';
-
 
475
	titre += pointClique.stationInfos.nbre+' observation';
-
 
476
	titre += (pointClique.stationInfos.nbre > 1) ? 's': '' ;
-
 
477
	titre += ' pour ';
-
 
478
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
-
 
479
		nomStation = 'la commune : ';
-
 
480
	} else {
-
 
481
		nomStation = 'la station : ';
-
 
482
	}
-
 
483
	titre += pointClique.stationInfos.nom;
-
 
484
	$("#obs-station-titre").text(titre);	
-
 
485
}
-
 
486
 
526
 
487
function initialiserContenuInfoBulle() {
-
 
488
	afficherTitreInfoBulle();
527
function initialiserContenuInfoBulle() {
489
	afficherMessageChargement('#observations');
528
	afficherMessageChargement('#observations');
490
	cacherContenuOnglets();
529
	cacherContenuOnglets();
491
	afficherOnglets();
530
	afficherOnglets();
492
	ajouterTableauTriable("#obs-tableau");
531
	ajouterTableauTriable("#obs-tableau");
Line 804... Line 843...
804
	var ntAFiltrer = $('.nt', this).text();
843
	var ntAFiltrer = $('.nt', this).text();
805
	infoBulle.close();
844
	infoBulle.close();
806
	$('#taxon-'+nt).removeClass('taxon-actif');
845
	$('#taxon-'+nt).removeClass('taxon-actif');
807
	if (nt == ntAFiltrer) {
846
	if (nt == ntAFiltrer) {
808
		nt = '*';
847
		nt = '*';
809
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
848
		//executerMarkerClusterer(pointsOrigine, boundsOrigine);
810
	} else {
849
	} else {
811
		var url = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
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;
812
		$.getJSON(url, function (stationsFiltrees) {
858
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
813
			stations = stationsFiltrees;
859
			stations = stationsFiltrees;
814
			nt = ntAFiltrer;
860
			nt = ntAFiltrer;
815
			$('#taxon-'+nt).addClass('taxon-actif');
861
			$('#taxon-'+nt).addClass('taxon-actif');
-
 
862
			rafraichirMarqueurs(stations);
816
		});
863
		});
817
	}
864
	}
818
};
865
};
Line 819... Line 866...
819
 
866