Subversion Repositories eFlore/Applications.cel

Compare Revisions

Regard whitespace Rev 1044 → Rev 2081

/trunk/widget/modules/carto/squelettes/scripts/carto.js
2,23 → 2,16
// PARAMÊTRES et CONSTANTES
// Mettre à true pour afficher les messages de débogage
var DEBUG = false;
/**
* Indication de certaines variables ajoutée par php
* var communeImageUrl ;
* var pointImageUrl ;
* var groupeImageUrlTpl ;
*/
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
var pointsOrigine = null;
var boundsOrigine = null;
var markerClusterer = null;
var map = null;
var infoBulle = new google.maps.InfoWindow();
var stations = null;
var pointClique = null;
var carteCentre = new google.maps.LatLng(25, 10);
var carteCentre = new google.maps.LatLng(46.4, 3.10);
var carteOptions = {
zoom: 3,
center:carteCentre,
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControlOptions: {
mapTypeIds: ['OSM',
28,6 → 21,7
google.maps.MapTypeId.TERRAIN]
}
};
var ctaLayer = null;
var osmMapType = new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
return "http://tile.openstreetmap.org/" +
39,16 → 33,11
name: "OSM",
maxZoom: 19
});
var ctaLayer = null;
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
var station = {'commune':'', 'obsNbre':0};
var obsStation = new Array();
var obsPage = new Array();
var taxonsCarte = new Array();
var mgr = null;
var marqueursCache = new Array();
var zonesCache = new Array();
var requeteChargementPoints;
/*+--------------------------------------------------------------------------------------------------------+*/
// INITIALISATION DU CODE
 
58,50 → 47,28
});
 
function initialiserWidget() {
afficherStats();
definirTailleTitre();
initialiserAffichageCarte();
initialiserAffichagePanneauLateral();
initialiserCarte();
initialiserGestionnaireMarqueurs()
initialiserInfoBulle();
initialiserFormulaireContact();
chargerLimitesCommunales();
attribuerListenerCarte();
programmerRafraichissementCarte();
rafraichirCarte();
}
 
/*+--------------------------------------------------------------------------------------------------------+*/
// AFFICHAGE GÉNÉRAL
 
function afficherTitreCarte() {
if (stations != null && taxonsCarte.length > 0) {
var obsNbre = stations.stats.observations;
var obsNbreFormate = stations.stats.observations.formaterNombre();
var plteNbre = taxonsCarte.length;
var plteNbreFormate = taxonsCarte.length.formaterNombre();
var communeNbre = stations.stats.communes;
var communeNbreFormate = stations.stats.communes.formaterNombre();
var titre = obsNbreFormate+' observation';
titre += (obsNbre > 1) ? 's' : '' ;
if (nt == '*') {
titre += ' de '+plteNbreFormate+' plante';
titre += (plteNbre > 1) ? 's' : '' ;
} else {
if (taxonsCarte[0]) {
var taxon = taxonsCarte[0];
titre += ' pour '+taxon.nom;
function afficherStats() {
// Ajout du nombre de communes où des observations ont eu lieu
$('#commune-nbre').text(stations.stats.communes.formaterNombre());
// Ajout du nombre d'observations
$('#obs-nbre').text(stations.stats.observations.formaterNombre());
}
}
titre += ' sur '+communeNbreFormate+' commune';
titre += (communeNbre > 1) ? 's' : '' ;
$('#carte-titre-infos').text(titre);
}
}
 
function definirTailleTitre() {
var largeurViewPort = $(window).width();
var taille = null;
133,207 → 100,35
map.mapTypes.set('OSM', osmMapType);
}
 
function initialiserGestionnaireMarqueurs() {
mgr = new MarkerManager(map);
}
 
function chargerLimitesCommunales() {
if (urlsLimitesCommunales != null) {
for (urlId in urlsLimitesCommunales) {
var url = urlsLimitesCommunales[urlId];
ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: false});
ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
ctaLayer.setMap(map);
}
}
}
 
var listener = null;
var timer = null;
function attribuerListenerCarte() {
listener = google.maps.event.addListener(map, 'bounds_changed', function(){
programmerRafraichissementCarte();
});
listener = google.maps.event.addListener(map, 'zoom_changed', function(){
programmerRafraichissementCarte();
});
}
function programmerRafraichissementCarte() {
if(timer != null) {
window.clearTimeout(timer);
}
if(requeteChargementPoints != null) {
requeteChargementPoints.abort();
}
timer = window.setTimeout(function() {
var zoom = map.getZoom();
var NELatLng = (map.getBounds().getNorthEast().lat())+'|'+(map.getBounds().getNorthEast().lng());
var SWLatLng = (map.getBounds().getSouthWest().lat())+'|'+(map.getBounds().getSouthWest().lng());
chargerMarqueurs(zoom, NELatLng, SWLatLng);
}, 400);
}
 
var marqueurs = new Array();
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
var url = stationsUrl+
'&zoom='+zoom+
'&ne='+NELatLng+
'&sw='+SWLatLng;
if(infoBulleOuverte) {
return;
}
if(requeteChargementPoints != null) {
requeteChargementPoints.abort();
cacherMessageChargementPoints();
}
afficherMessageChargementPoints();
requeteChargementPoints = $.getJSON(url, function(data) {
rafraichirMarqueurs(data);
cacherMessageChargementPoints();
});
}
 
function afficherMessageChargementPoints() {
$('#zone-chargement-point').css('display','block');
}
 
function cacherMessageChargementPoints() {
$('#zone-chargement-point').css('display','none');
}
 
function rafraichirMarqueurs(data) {
$.each(marqueurs, function(index, marqueur) {
marqueur.setMap(null);
});
marqueurs = new Array();
stations = data;
afficherTitreCarte();
$.each(stations.points, function (index, station) {
if(station != null) {
var nouveauMarqueur = creerMarqueur(station);
marqueurs.push(nouveauMarqueur);
}
});
}
 
function creerMarqueur(station) {
var titre = '';
if(station.nbreMarqueur) {
titre = station.nbreMarqueur+' points renseignés';
} else {
if(station.nom) {
titre = station.nom;
}
}
//var titre = station['nbreMarqueur'];
var icone = attribuerImageMarqueur(station['id'], station['nbreMarqueur']);
var latLng = new google.maps.LatLng(station['lat'], station['lng']);
var marqueur = new google.maps.Marker({
position: latLng,
icon: icone,
title: ''+titre,
map: map,
stationInfos: station
});
attribuerListenerClick(marqueur, station['id']);
marqueur.setMap(map);
return marqueur;
}
 
function rendrePointsVisibles(bounds) {
map.setCenter(bounds.getCenter());
map.fitBounds(bounds);
map.panToBounds(bounds);
}
 
function programmerRafraichissementCarteSauv() {
function rafraichirCarte() {
var points = [];
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < stations.points.length; ++i) {
var point = stations.points[i];
var maLatLng = new google.maps.LatLng(point.lat, point.lng);
var stationImage = attribuerImageMarqueur(point.id);
for (var i = 0; i < stations.stats.communes; ++i) {
var maLatLng = new google.maps.LatLng(stations.points[i].latitude, stations.points[i].longitude);
var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
var point = new google.maps.Marker({
position: maLatLng,
map: map,
icon: stationImage,
stationInfos: point
icon: pointImage,
stationId: stations.points[i].id
});
 
bounds.extend(maLatLng);
google.maps.event.addListener(point, 'click', surClickMarqueur);
points.push(point);
}
 
if (pointsOrigine == null && boundsOrigine == null) {
pointsOrigine = points;
boundsOrigine = bounds;
}
executerMarkerClusterer(points, bounds);
}
 
function attribuerImageMarqueur(id, nbreMarqueur) {
var marqueurImage = null;
if (etreMarqueurCommune(id)) {
marqueurImage = new google.maps.MarkerImage(communeImageUrl, new google.maps.Size(24, 32));
} else if (etreMarqueurStation(id)) {
marqueurImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(16, 16));
} else if (etreMarqueurGroupe(id)) {
var type = 0;
var largeur = 0;
var hauteur = 0;
if (nbreMarqueur != null) {
if (nbreMarqueur >= 2 && nbreMarqueur < 100 ) {
type = '1';
largeur = 53;
hauteur = 52;
} else if (nbreMarqueur >= 100 && nbreMarqueur < 1000 ) {
type = '2';
largeur = 56;
hauteur = 55;
} else if (nbreMarqueur >= 1000 && nbreMarqueur < 10000 ) {
type = '3';
largeur = 66;
hauteur = 65;
} else if (nbreMarqueur >= 10000 && nbreMarqueur < 20000 ) {
type = '4';
largeur = 78;
hauteur = 77;
} else if (nbreMarqueur >= 20000) {
type = '5';
largeur = 66;
hauteur = 65;
}
}
groupeImageUrl = groupeImageUrlTpl.replace(/\{type\}/, type);
groupeImageUrl = groupeImageUrl.replace(/\{nbre\}/, nbreMarqueur);
marqueurImage = new google.maps.MarkerImage(groupeImageUrl, new google.maps.Size(largeur, hauteur));
}
return marqueurImage
}
 
function attribuerListenerClick(marqueur, id) {
if (etreMarqueurCommune(id) || etreMarqueurStation(id)) {
google.maps.event.addListener(marqueur, 'click', surClickMarqueur);
} else if (etreMarqueurGroupe(id)) {
google.maps.event.addListener(marqueur, 'click', surClickGroupe);
}
}
 
function surClickMarqueur(event) {
 
if(infoBulleOuverte) {
infoBulle.close();
}
google.maps.event.addListener(point, 'click', function() {
pointClique = this;
infoBulle.open(map, this);
actualiserPagineur();
var limites = map.getBounds();
var centre = limites.getCenter();
342,43 → 137,21
map.panTo(centreSudLatLng);
afficherInfoBulle();
}
chargerObs(0, 0);
});
 
function surClickGroupe() {
map.setCenter(this.getPosition());
var nouveauZoom = map.getZoom() + 2;
map.setZoom(nouveauZoom);
mgr.clearMarkers();
points.push(point);
}
 
function etreMarqueurGroupe(id) {
var groupe = false;
var motif = /^GROUPE/;
if (motif.test(id)) {
groupe = true;
if (pointsOrigine == null && boundsOrigine == null) {
pointsOrigine = points;
boundsOrigine = bounds;
}
return groupe;
}
 
function etreMarqueurCommune(id) {
var commune = false;
var motif = /^COMMUNE:/;
if (motif.test(id)) {
commune = true;
executerMarkerClusterer(points, bounds);
}
return commune;
}
 
function etreMarqueurStation(id) {
var station = false;
var motif = /^STATION:/;
if (motif.test(id)) {
station = true;
}
return station;
}
 
function deplacerCarteSurPointClique() {
function deplacerCartePointClique() {
map.panTo(pointClique.position);
}
 
386,39 → 159,23
if (markerClusterer) {
markerClusterer.clearMarkers();
}
markerClusterer = new MarkerClusterer(map, points, {gridSize: 50, maxZoom: 18});
markerClusterer = new MarkerClusterer(map, points);
map.fitBounds(bounds);
}
 
/*+--------------------------------------------------------------------------------------------------------+*/
// INFO BULLE
var infoBulleOuverte = false;
 
function initialiserInfoBulle() {
google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle);
google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle);
google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
}
 
function surFermetureInfoBulle() {
infoBulleOuverte = false;
programmerRafraichissementCarte();
}
 
function centrerInfoBulle() {
var limites = map.getBounds();
var centre = limites.getCenter();
var nordEst = limites.getNorthEast();
var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
map.panTo(centreSudLatLng);
}
 
function afficherInfoBulle() {
var obsHtml = $("#tpl-obs").html();
var largeur = definirLargeurInfoBulle();
obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
infoBulle.setContent(obsHtml);
chargerObs(0, 0);
infoBulleOuverte = true;
}
 
function definirLargeurInfoBulle() {
440,10 → 197,6
}
}
 
function afficherMessageChargementTitreInfoBulle() {
$("#obs-station-titre").text("Chargement des observations");
}
 
function supprimerMessageChargement() {
$('#chargement').remove();
}
452,66 → 205,43
if (depart == 0 || depart < total) {
var limite = 300;
if (depart == 0) {
viderTableauObs();
obsStation = new Array();
}
//console.log("Chargement de "+depart+" à "+(depart+limite));
var urlObs = observationsUrl+'&start={start}&limit='+limite;
urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationInfos.id);
if (pointClique.stationInfos.type_emplacement == 'communes') {
urlObs = urlObs.replace(/commune=%2A/g, 'commune='+pointClique.stationInfos.nom);
}
urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
urlObs = urlObs.replace(/\{nt\}/g, nt);
urlObs = urlObs.replace(/\{start\}/g, depart);
$.getJSON(urlObs, function(observations){
surRetourChargementObs(observations, depart, total);
chargerObs(depart+limite, observations.total);
});
}
}
 
function viderTableauObs() {
obsStation = new Array();
surClicPagePagination(0, null);
}
 
function surRetourChargementObs(observations, depart, total) {
obsStation = obsStation.concat(observations.observations);
if (depart == 0) {
actualiserInfosStation(observations);
actualiserPagineur();
creerTitreInfoBulle();
surClicPagePagination(0, null);
}
//console.log("Chargement ok");
chargerObs(depart+limite, station.obsNbre);
});
} else {
if (pagineur.limite < total) {
afficherPagination();
actualiserPagineur();
} else {
surClicPagePagination(0, null);
selectionnerOnglet("#obs-vue-"+pagineur.format);
}
}
}
 
function actualiserInfosStation(infos) {
pointClique.stationInfos.commune = infos.commune;
pointClique.stationInfos.obsNbre = infos.total;
station.commune = infos.commune;
station.obsNbre = infos.total;
}
 
function creerTitreInfoBulle() {
$("#obs-total").text(station.obsNbre);
$("#obs-commune").text(station.commune);
var titre = '';
titre += pointClique.stationInfos.obsNbre+' observation';
titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
titre += ' pour ';
if (etreMarqueurCommune(pointClique.stationInfos.id)) {
nomStation = 'la commune : ';
} else {
nomStation = 'la station : ';
}
titre += pointClique.stationInfos.nom;
$("#obs-station-titre").text(titre);
}
 
function actualiserPagineur() {
pagineur.stationId = pointClique.stationInfos.id;
pagineur.total = pointClique.stationInfos.obsNbre;
pagineur.stationId = pointClique.stationId;
pagineur.total = station.obsNbre;
//console.log("Total pagineur: "+pagineur.total);
if (pagineur.total > 4) {
pagineur.format = 'tableau';
} else {
559,20 → 289,19
}
}
 
function creerTitreInfoBulle() {
$("#obs-total").text(station.obsNbre);
$("#obs-commune").text(station.commune);
}
 
function initialiserContenuInfoBulle() {
afficherOnglets();
afficherMessageChargement('#observations');
cacherContenuOnglets();
afficherOnglets();
ajouterTableauTriable("#obs-tableau");
afficherTextStationId();
corrigerLargeurInfoWindow();
}
 
function cacherContenuOnglets() {
$("#obs-vue-tableau").css("display", "none");
$("#obs-vue-liste").css("display", "none");
}
 
function afficherOnglets() {
var $tabs = $('#obs').tabs();
$('#obs').bind('tabsselect', function(event, ui) {
582,21 → 311,15
surClicAffichageListe();
}
});
if (pointClique.stationInfos.nbre > 4) {
$tabs.tabs('select', "#obs-vue-tableau");
} else {
$tabs.tabs('select', "#obs-vue-liste");
$tabs.tabs('select', "#obs-vue-"+pagineur.format);
}
}
 
function selectionnerOnglet(onglet) {
$(onglet).css('display', 'block');
$('#obs').tabs('select', onglet);
}
 
function afficherTextStationId() {
$('#obs-station-id').text(pointClique.stationInfos.id);
$('#obs-station-id').text(pointClique.stationId);
}
 
function corrigerLargeurInfoWindow() {
604,6 → 327,7
}
 
function surClicAffichageTableau(event) {
//console.log('tableau');
pagineur.format = 'tableau';
mettreAJourObservations();
mettreAJourTableauTriable("#obs-tableau");
610,6 → 334,7
}
 
function surClicAffichageListe(event) {
//console.log('liste');
pagineur.format = 'liste';
mettreAJourObservations();
ajouterGaleriePhoto("a.cel-img");
715,9 → 440,9
}
 
function chargerInfoObsPourMessage(idObs) {
var nomSci = jQuery.trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
var nomSci = trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
var date = trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
var lieu = trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
var sujet = "Observation #"+idObs+" de "+nomSci;
var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
$("#fc_sujet").attr('value', sujet);
758,7 → 483,7
}
if (cle == 'message') {
champ.value += "\n--\n"+
"Ce message vous est envoyé par l'intermédiaire du widget carto "+
"Ce message vous est envoyé par l'intermédiaire du widget Cartographique "+
"du Carnet en Ligne du réseau Tela Botanica.\n"+
"http://www.tela-botanica.org/widget:cel:carto";
}
800,7 → 525,7
'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
'Vous pouvez signaler le disfonctionnement à <a href="'+
'mailto:cel@tela-botanica.org'+'?'+
'subject=Disfonctionnement du widget carto'+
'subject=Disfonctionnement du widget de Cartographie'+
"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
'">cel@tela-botanica.org</a>.'+
'</p>');
842,17 → 567,26
} else {
if (nt == '*') {
afficherTaxons();
} else {
afficherNomPlante();
}
afficherTitreCarte();
}
}
 
function afficherTaxons() {
$(".plantes-nbre").text(taxonsCarte.length);
// Ajout du nombre de plantes au titre
$('.plantes-nbre').text(taxonsCarte.length.formaterNombre());
$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
$('.taxon').live('click', filtrerParTaxon);
}
 
function afficherNomPlante() {
if (nt != '*') {
var taxon = taxonsCarte[0];
$('.plante-titre').text('pour '+taxon.nom);
}
}
 
function afficherPanneauLateral() {
$('#panneau-lateral').width(300);
874,29 → 608,26
google.maps.event.trigger(map, 'resize');
};
 
function ouvrirPopUp(url, nom) {
window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
};
 
function filtrerParTaxon() {
var ntAFiltrer = $('.nt', this).text();
infoBulle.close();
var zoom = map.getZoom();
var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
$('#taxon-'+nt).removeClass('taxon-actif');
if (nt == ntAFiltrer) {
nt = '*';
stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+nt);
chargerMarqueurs(zoom, NELatLng, SWLatLng);
executerMarkerClusterer(pointsOrigine, boundsOrigine);
} else {
stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
url = stationsUrl;
url += '&zoom='+zoom+
'&ne='+NELatLng+
'&sw='+SWLatLng;
requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
var url = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer)+
'&formatRetour=jsonP'+
'&callback=?';
$.getJSON(url, function (stationsFiltrees) {
stations = stationsFiltrees;
nt = ntAFiltrer;
$('#taxon-'+nt).addClass('taxon-actif');
rafraichirMarqueurs(stations);
rafraichirCarte();
});
}
};
904,28 → 635,6
/*+--------------------------------------------------------------------------------------------------------+*/
// FONCTIONS UTILITAIRES
 
function ouvrirPopUp(element, nomPopUp, event) {
var options =
'width=650,'+
'height=600,'+
'scrollbars=yes,'+
'directories=no,'+
'location=no,'+
'menubar=no,'+
'status=no,'+
'toolbar=no';
var popUp = window.open(element.href, nomPopUp, options);
if (window.focus) {
popUp.focus();
}
return arreter(event);
};
 
function ouvrirNouvelleFenetre(element, event) {
window.open(element.href);
return arreter(event);
}
 
function arreter(event) {
if (event.stopPropagation) {
event.stopPropagation();
932,10 → 641,6
} else if (window.event) {
window.event.cancelBubble = true;
}
if (event.preventDefault) {
event.preventDefault();
}
event.returnValue = false;
return false;
}
 
1024,4 → 729,8
msg = "La variable vaut null.";
}
console.log(msg);
}
}
 
function trim (chaine) {
return chaine.replace(/^\s+/g, '').replace(/\s+$/g, '');
}