2,16 → 2,20 |
// PARAMÊTRES et CONSTANTES |
// Mettre à true pour afficher les messages de débogage |
var DEBUG = false; |
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png'; |
var communeImageUrl = 'http://www.tela-botanica.org/commun/icones/carto/commune.png'; |
var pointImageUrl = 'http://www.tela-botanica.org/commun/icones/carto/point2.png'; |
var groupeImageUrlTpl = 'http://localhost/cel-jrest/CelWidgetMap/icone-groupe?type={type}&nbre={nbre}' |
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(46.4, 3.10); |
var carteCentre = new google.maps.LatLng(25, 10); |
var carteOptions = { |
zoom: 6, |
zoom: 3, |
center:carteCentre, |
mapTypeId: google.maps.MapTypeId.ROADMAP, |
mapTypeControlOptions: { |
mapTypeIds: ['OSM', |
21,7 → 25,6 |
google.maps.MapTypeId.TERRAIN] |
} |
}; |
var ctaLayer = null; |
var osmMapType = new google.maps.ImageMapType({ |
getTileUrl: function(coord, zoom) { |
return "http://tile.openstreetmap.org/" + |
33,11 → 36,15 |
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(); |
/*+--------------------------------------------------------------------------------------------------------+*/ |
// INITIALISATION DU CODE |
|
47,11 → 54,11 |
}); |
|
function initialiserWidget() { |
afficherStats(); |
definirTailleTitre(); |
initialiserAffichageCarte(); |
initialiserAffichagePanneauLateral(); |
|
initialiserCarte(); |
initialiserGestionnaireMarqueurs() |
initialiserInfoBulle(); |
initialiserFormulaireContact(); |
chargerLimitesCommunales(); |
61,13 → 68,45 |
/*+--------------------------------------------------------------------------------------------------------+*/ |
// AFFICHAGE GÉNÉRAL |
|
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()); |
function afficherTitreCarte() { |
if (stations != null && taxonsCarte.length > 0) { |
var obsNbre = stations.stats.observations.formaterNombre(); |
var plteNbre = taxonsCarte.length.formaterNombre(); |
var communeNbre = stations.stats.communes.formaterNombre(); |
|
var titre = obsNbre+' observation'; |
titre += (obsNbre > 1) ? 's' : '' ; |
|
if (nt == '*') { |
titre += ' de '+plteNbre+' plante'; |
titre += (plteNbre > 1) ? 's' : '' ; |
} else { |
if (taxonsCarte[0]) { |
var taxon = taxonsCarte[0]; |
titre += ' pour '+taxon.nom; |
} |
} |
|
titre += ' sur '+communeNbre+' commune'; |
titre += (communeNbre > 1) ? 's' : '' ; |
|
$('#carte-titre-infos').text(titre); |
} |
} |
|
function definirTailleTitre() { |
var largeurViewPort = $(window).width(); |
var taille = null; |
if (largeurViewPort < 400) { |
taille = '0.8'; |
} else if (largeurViewPort >= 400 && largeurViewPort < 800) { |
taille = '1.0'; |
} else if (largeurViewPort >= 800) { |
taille = '1.6'; |
} |
$("#carte-titre").css('font-size', taille+'em'); |
} |
|
/*+--------------------------------------------------------------------------------------------------------+*/ |
// CARTE |
|
74,7 → 113,7 |
function initialiserAffichageCarte() { |
$('#carte').height($(window).height() - 35); |
$('#carte').width($(window).width() - 24); |
|
|
if (nt != '*') { |
$('#carte').css('left', 0); |
} |
86,6 → 125,9 |
map.mapTypes.set('OSM', osmMapType); |
} |
|
function initialiserGestionnaireMarqueurs() { |
mgr = new MarkerManager(map); |
} |
|
function chargerLimitesCommunales() { |
if (urlsLimitesCommunales != null) { |
96,36 → 138,104 |
} |
} |
} |
var listener = null; |
var timer = null; |
function rafraichirCarte() { |
|
listener = google.maps.event.addListener(map, 'bounds_changed', function(){ |
|
if(timer != null) { |
window.clearTimeout(timer); |
} |
|
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); |
}, 300); |
}); |
} |
|
function rafraichirCarte() { |
function collecterBorduresEtChargerMarqueurs() { |
|
} |
|
var premierChargement = true; |
var marqueurs = new Array(); |
function chargerMarqueurs(zoom, NELatLng, SWLatLng) { |
google.maps.event.removeListener(listener); |
var url = stationsUrl+ |
'&zoom='+zoom+ |
'&ne='+NELatLng+ |
'&sw='+SWLatLng; |
|
$.getJSON(url, function(data) { |
|
$.each(marqueurs, function(index, marqueur) { |
marqueur.setMap(null); |
}); |
marqueurs = new Array(); |
|
stations = data; |
afficherTitreCarte(); |
/*if(premierChargement) { |
var bounds = new google.maps.LatLngBounds(); |
}*/ |
|
$.each(stations.points, function (index, station) { |
|
/*if(premierChargement) { |
var maLatLng = null; |
maLatLng = new google.maps.LatLng(station['lat'], station['lng']); |
bounds.extend(maLatLng); |
}*/ |
|
if(station != null) { |
marqueurs.push(creerMarqueur(station)); |
} |
}); |
|
/*if(premierChargement) { |
map.fitBounds(bounds); |
premierChargement = false; |
}*/ |
rafraichirCarte(); |
}); |
} |
|
function creerMarqueur(station) { |
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 rafraichirCarteSauv() { |
|
var points = []; |
var bounds = new google.maps.LatLngBounds(); |
for (var i = 0; i < stations.stats.communes; ++i) { |
var maLatLng = new google.maps.LatLng(stations.points[i].coord_x, stations.points[i].coord_y); |
var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32)); |
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); |
var point = new google.maps.Marker({ |
position: maLatLng, |
map: map, |
icon: pointImage, |
stationId: stations.points[i].id |
icon: stationImage, |
stationInfos: point |
}); |
|
bounds.extend(maLatLng); |
|
google.maps.event.addListener(point, 'click', function() { |
pointClique = this; |
infoBulle.open(map, this); |
|
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); |
|
afficherInfoBulle(); |
chargerObs(0, 0); |
}); |
|
google.maps.event.addListener(point, 'click', surClickMarqueur); |
points.push(point); |
} |
|
137,7 → 247,98 |
executerMarkerClusterer(points, bounds); |
} |
|
function deplacerCartePointClique() { |
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() { |
pointClique = this; |
infoBulle.open(map, this); |
//centrerInfoBulle(); |
actualiserPagineur(); |
afficherInfoBulle(); |
chargerObs(0, 0); |
} |
|
function surClickGroupe() { |
map.setCenter(this.getPosition()); |
var nouveauZoom = map.getZoom() + 2; |
map.setZoom(nouveauZoom); |
mgr.clearMarkers(); |
} |
|
function etreMarqueurGroupe(id) { |
var groupe = false; |
var motif = /^GROUPE/; |
if (motif.test(id)) { |
groupe = true; |
} |
return groupe; |
} |
|
function etreMarqueurCommune(id) { |
var commune = false; |
var motif = /^COMMUNE:/; |
if (motif.test(id)) { |
commune = true; |
} |
return commune; |
} |
|
function etreMarqueurStation(id) { |
var station = false; |
var motif = /^STATION:/; |
if (motif.test(id)) { |
station = true; |
} |
return station; |
} |
|
function deplacerCarteSurPointClique() { |
map.panTo(pointClique.position); |
} |
|
145,7 → 346,7 |
if (markerClusterer) { |
markerClusterer.clearMarkers(); |
} |
markerClusterer = new MarkerClusterer(map, points); |
markerClusterer = new MarkerClusterer(map, points, {gridSize: 50, maxZoom: 18}); |
map.fitBounds(bounds); |
} |
|
154,14 → 355,42 |
|
function initialiserInfoBulle() { |
google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle); |
google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique); |
google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle); |
google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle); |
} |
|
function surFermetureInfoBulle() { |
//deplacerCarteSurPointClique(); |
} |
|
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); |
} |
|
function definirLargeurInfoBulle() { |
var largeurViewPort = $(window).width(); |
var lageurInfoBulle = null; |
if (largeurViewPort < 800) { |
largeurInfoBulle = 400; |
} else if (largeurViewPort >= 800 && largeurViewPort < 1200) { |
largeurInfoBulle = 500; |
} else if (largeurViewPort >= 1200) { |
largeurInfoBulle = 600; |
} |
return largeurInfoBulle; |
} |
|
function afficherMessageChargement(element) { |
if ($('#chargement').get() == '') { |
$('#tpl-chargement').tmpl().appendTo(element); |
180,23 → 409,18 |
} |
//console.log("Chargement de "+depart+" à "+(depart+limite)); |
var urlObs = observationsUrl+'&start={start}&limit='+limite; |
urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId); |
urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationInfos.id); |
urlObs = urlObs.replace(/\{nt\}/g, nt); |
urlObs = urlObs.replace(/\{start\}/g, depart); |
|
$.getJSON(urlObs, function(observations){ |
obsStation = obsStation.concat(observations.observations); |
if (depart == 0) { |
actualiserInfosStation(observations); |
actualiserPagineur(); |
creerTitreInfoBulle(); |
} |
//console.log("Chargement ok"); |
chargerObs(depart+limite, station.obsNbre); |
chargerObs(depart+limite, pointClique.stationInfos.nbre); |
}); |
} else { |
if (pagineur.limite < total) { |
afficherPagination(); |
surClicPagePagination(0, null); |
} else { |
surClicPagePagination(0, null); |
selectionnerOnglet("#obs-vue-"+pagineur.format); |
204,15 → 428,9 |
} |
} |
|
function actualiserInfosStation(infos) { |
station.commune = infos.commune; |
station.obsNbre = infos.total; |
} |
|
function actualiserPagineur() { |
pagineur.stationId = pointClique.stationId; |
pagineur.total = station.obsNbre; |
//console.log("Total pagineur: "+pagineur.total); |
pagineur.stationId = pointClique.stationInfos.id; |
pagineur.total = pointClique.stationInfos.nbre; |
if (pagineur.total > 4) { |
pagineur.format = 'tableau'; |
} else { |
260,19 → 478,35 |
} |
} |
|
function creerTitreInfoBulle() { |
$("#obs-total").text(station.obsNbre); |
$("#obs-commune").text(station.commune); |
function afficherTitreInfoBulle() { |
var titre = ''; |
titre += pointClique.stationInfos.nbre+' observation'; |
titre += (pointClique.stationInfos.nbre > 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 initialiserContenuInfoBulle() { |
afficherTitreInfoBulle(); |
afficherMessageChargement('#observations'); |
cacherContenuOnglets(); |
afficherOnglets(); |
afficherMessageChargement('#observations'); |
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) { |
282,15 → 516,21 |
surClicAffichageListe(); |
} |
}); |
$tabs.tabs('select', "#obs-vue-"+pagineur.format); |
if (pointClique.stationInfos.nbre > 4) { |
$tabs.tabs('select', "#obs-vue-tableau"); |
} else { |
$tabs.tabs('select', "#obs-vue-liste"); |
} |
|
} |
|
function selectionnerOnglet(onglet) { |
$(onglet).css('display', 'block'); |
$('#obs').tabs('select', onglet); |
} |
|
function afficherTextStationId() { |
$('#obs-station-id').text(pointClique.stationId); |
$('#obs-station-id').text(pointClique.stationInfos.id); |
} |
|
function corrigerLargeurInfoWindow() { |
298,7 → 538,6 |
} |
|
function surClicAffichageTableau(event) { |
//console.log('tableau'); |
pagineur.format = 'tableau'; |
mettreAJourObservations(); |
mettreAJourTableauTriable("#obs-tableau"); |
305,7 → 544,6 |
} |
|
function surClicAffichageListe(event) { |
//console.log('liste'); |
pagineur.format = 'liste'; |
mettreAJourObservations(); |
ajouterGaleriePhoto("a.cel-img"); |
411,9 → 649,9 |
} |
|
function chargerInfoObsPourMessage(idObs) { |
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 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 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); |
449,12 → 687,12 |
var cle = champ.name; |
cle = cle.replace(/^fc_/, ''); |
|
if (cle = 'sujet') { |
if (cle == 'sujet') { |
champ.value += " - Carnet en ligne - Tela Botanica"; |
} |
if (cle == 'message') { |
champ.value += "\n--\n"+ |
"Ce message vous est envoyé par l'intermédiaire du widget Cartographique "+ |
"Ce message vous est envoyé par l'intermédiaire du widget carto "+ |
"du Carnet en Ligne du réseau Tela Botanica.\n"+ |
"http://www.tela-botanica.org/widget:cel:carto"; |
} |
496,7 → 734,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 de Cartographie'+ |
'subject=Disfonctionnement du widget carto'+ |
"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+ |
'">cel@tela-botanica.org</a>.'+ |
'</p>'); |
538,26 → 776,17 |
} else { |
if (nt == '*') { |
afficherTaxons(); |
} else { |
afficherNomPlante(); |
} |
afficherTitreCarte(); |
} |
} |
|
function afficherTaxons() { |
// Ajout du nombre de plantes au titre |
$('.plantes-nbre').text(taxonsCarte.length.formaterNombre()); |
|
$(".plantes-nbre").text(taxonsCarte.length); |
$("#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); |
579,10 → 808,6 |
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(); |
591,9 → 816,7 |
nt = '*'; |
executerMarkerClusterer(pointsOrigine, boundsOrigine); |
} else { |
var url = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer)+ |
'&formatRetour=jsonP'+ |
'&callback=?'; |
var url = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer); |
$.getJSON(url, function (stationsFiltrees) { |
stations = stationsFiltrees; |
nt = ntAFiltrer; |
606,6 → 829,28 |
/*+--------------------------------------------------------------------------------------------------------+*/ |
// 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(); |
612,6 → 857,10 |
} else if (window.event) { |
window.event.cancelBubble = true; |
} |
if (event.preventDefault) { |
event.preventDefault(); |
} |
event.returnValue = false; |
return false; |
} |
|
700,8 → 949,4 |
msg = "La variable vaut null."; |
} |
console.log(msg); |
} |
|
function trim (chaine) { |
return chaine.replace(/^\s+/g, '').replace(/\s+$/g, ''); |
} |