1,62 → 1,3 |
// Javascript Document |
|
|
// =================================================================================== |
// FONCTIONS ADDITIONNELLES POUR GERER LES URLS ET L'OUVERTRURE DE NOUVELLE FENETRE |
function convertirEnParametresUrl(objet) { |
var parametresUrl = ''; |
for (attribut in objet) { |
if (typeof(objet[attribut]) == 'function' || typeof(objet[attribut]) == 'undefined' || |
objet[attribut] == null || objet[attribut] == '*' || objet[attribut] == 0) |
continue; |
parametresUrl += (parametresUrl == '' ? '' : '&') + attribut + "=" + objet[attribut]; |
} |
return parametresUrl; |
}; |
|
function recupererParametreDansUrl(nomParametre, chaineRecherche) { |
var split = chaineRecherche.split('?'); |
chaineRecherche = split[split.length-1]; |
var valeurParametre = null; |
var listeParametres = chaineRecherche.split("&"); |
for (var index = 0; index < listeParametres.length; index ++) { |
var split = listeParametres[index].split("="); |
if (split[0] == nomParametre) { |
valeurParametre = split[1]; |
break; |
} |
} |
return valeurParametre; |
}; |
|
function estValeurDansTableau(tableau, valeur) { |
var index; |
for (index = 0; index < tableau.length && tableau[index] != valeur; index ++); |
return (tableau.length > 0 && index != tableau.length); |
} |
|
function ouvrirNouvelleFenetre(element, event) { |
window.open(element.href); |
return arreter(event); |
} |
|
function arreter(event) { |
if (event.stopPropagation) { |
event.stopPropagation(); |
} else if (window.event) { |
window.event.cancelBubble = true; |
} |
if (event.preventDefault) { |
event.preventDefault(); |
} |
event.returnValue = false; |
return false; |
} |
|
|
|
// ============================================================= |
|
var map = null, |
optionsCoucheOSM = { |
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,' |
67,12 → 8,12 |
attribution: 'Map data ©'+new Date().getFullYear()+' <a href="http://maps.google.com">Google</a>', |
maxZoom: 18 |
}, |
coucheOSM = new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", |
coucheOSM = new L.TileLayer("http://a.tile.openstreetmap.org/{z}/{x}/{y}.png", |
optionsCoucheOSM), |
couchePlanGoogle = new L.TileLayer("http://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}", |
coucheRelief = new L.TileLayer("http://c.tile3.opencyclemap.org/landscape/{z}/{x}/{y}.png", |
optionsCoucheOSM), |
coucheSatellite = new L.TileLayer("http://mt1.google.com/vt/lyrs=y@218131653&hl=fr&src=app&x={x}&y={y}&z={z}", |
optionsCoucheGoogle), |
coucheSatelliteGoogle = new L.TileLayer("http://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}", |
optionsCoucheGoogle), |
optionsCarte = { |
center : new L.LatLng(46, 2), |
zoom : 6, |
85,19 → 26,15 |
coucheDepartement = null, |
infoBulle = null; |
|
var coucheSites = new L.FeatureGroup(), |
points = new Array(), |
coucheSites = new L.FeatureGroup(), |
var coucheSites = null, |
sources = new Object(), |
formeDonnees = '', |
popupMaille = null; |
typeSite = 'maille', |
overlays = []; |
|
var requeteChargementPoints = null, |
chargementMaillesEnCours = false, |
doitRafraichirCarte = true, |
chargementCommunesEnCours = false, |
timer = null, |
ancienneRequete = null, |
deplacement = true, |
url = ''; |
|
|
107,50 → 44,27 |
initialiserWidget(); |
}); |
|
$(window).resize(function() { |
dimensionnerCarte(); |
}); |
|
function initialiserWidget() { |
initialiserCarte(); |
dimensionnerOverlay(); |
chargerLimitesCommunales(); |
initialiserPanneauControle(); |
initialiserSources(); |
initialiserListeners(); |
chargerLimitesCommunales(); |
chargerMaillesVides(); |
programmerRafraichissementCarte(); |
chargerLocalisations(); |
} |
|
$(window).resize(function() { |
dimensionnerCarte(); |
if (infoBulle != null) { |
redimensionnerPopup(); |
} |
}); |
|
function dimensionnerOverlay() { |
var taille = '1.6'; |
var tailleMaxIcones = 20; |
var padding_icones = 8; |
$("#zone-titre h1").css('font-size', (taille)+'em'); |
$("#zone-titre").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px"); |
$('#zone-titre').height(tailleMaxIcones*2); |
var left = ($(window).width()-$('#zone-titre').width())/2; |
$('#zone-titre').css('left',left); |
} |
|
|
function dimensionnerCarte() { |
$('#map').height($(window).height()); |
$('#map').width($(window).width()); |
} |
|
function initialiserCarte() { |
dimensionnerCarte(); |
map = L.map('map', optionsCarte); |
coucheSites.addTo(map); |
coucheSatellite.addTo(map); |
coucheRelief.addTo(map); |
coucheOSM.addTo(map); |
couchePlanGoogle.addTo(map); |
coucheSatelliteGoogle.addTo(map); |
var echelle = new L.Control.Scale({ |
maxWidth : 32, |
maxWidth : 50, |
metric : true, |
imperial : false, |
updateWhenIdle : true |
159,9 → 73,14 |
zoom = map.getZoom(); |
} |
|
function dimensionnerCarte() { |
$('#map').height($(window).height()); |
$('#map').width($(window).width()); |
} |
|
function initialiserListeners() { |
map.on('moveend', surChangementVueSurCarte); |
map.on('zoomend', surChangementVueSurCarte); |
map.on('moveend', surChangementVueCarte); |
map.on('zoomend', surChangementVueCarte); |
map.on('popupclose', function(e) { |
masquerInfoBulle(); |
programmerRafraichissementCarte(); |
170,9 → 89,9 |
|
function initialiserPanneauControle() { |
var baseMaps = { |
"OpenStreetMap" : coucheOSM, |
"Plan" : couchePlanGoogle, |
"Satellite" : coucheSatelliteGoogle |
"Satellite" : coucheSatellite, |
"Relief" : coucheRelief, |
"Plan" : coucheOSM |
}; |
|
var overlayMaps = {}; |
182,8 → 101,8 |
} |
L.control.layers(baseMaps, overlayMaps).addTo(map); |
coucheOSM.bringToFront(); |
couchePlanGoogle.bringToBack(); |
coucheSatelliteGoogle.bringToBack(); |
map.removeLayer(coucheRelief); |
map.removeLayer(coucheOSM); |
|
// garder par defaut la couche plan google comme selectionnee dans le panel |
var selecteursFonds = $('.leaflet-control-layers-base .leaflet-control-layers-selector'); |
213,61 → 132,110 |
}); |
} |
|
function determinerSourcesSelectionnees() { |
var sourcesSelectionnees = new Array(); |
for (source in sources) { |
if (sources[source] == true) { |
sourcesSelectionnees.push(source); |
function changerSource(projetClique) { |
var indexProjetClique; |
for (var index = 0; index < overlays.length; index ++) { |
if (overlays[index].value == projetClique) { |
indexProjetClique = index; |
} |
} |
return sourcesSelectionnees; |
masquerInfoBulle(); |
sources[projetClique] = overlays[indexProjetClique].checked; |
if (sources[projetClique] == true) { |
programmerRafraichissementCarte(projetClique); |
} else { |
if (requeteEnCours()) { |
stopperRequeteAjax(); |
} |
supprimerFeaturesSource(projetClique); |
} |
} |
|
function surChangementVueSurCarte() { |
if (doitRafraichirCarte == false) { |
doitRafraichirCarte = true; |
function supprimerFeaturesSource(source) { |
if (coucheSites != null) { |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'maille') { |
retirerStationsEtObservations(layer, source); |
} else { |
supprimerTousLayers(); |
zoom = map.getZoom(); |
chargerMaillesVides(); |
layer.supprimerSource(source, coucheSites); |
if (layer._map == 'null') { |
couheSites.removeLayer(layer); |
} |
} |
}); |
if (typeSite == 'maille') { |
var nombreMailles = calculerNombreMaillesVisibles(); |
if (nombreMailles == 0) { |
coucheSites.clearLayers(); |
masquerLegende(); |
typeSite = 'point'; |
} |
} |
} |
} |
|
function chargerMaillesVides() { |
chargementMaillesEnCours = true; |
if (timer != null) { |
window.clearTimeout(timer); |
function retirerStationsEtObservations(maille, sourceRetrait) { |
var sources = maille.properties.source; |
var nombreStations = 0; |
for (var index = 0; index < sources.length; index ++) { |
var source = sources[index]; |
if (source == sourceRetrait) { |
delete maille.properties.stations[source]; |
delete maille.properties.observations[source]; |
} else if (typeof(maille.properties.stations[source]) != 'undefined') { |
nombreStations += parseInt(maille.properties.stations[source]); |
} |
if (requeteChargementPoints != null) { |
stopperRequeteAjax(); |
} |
timer = window.setTimeout(function() { |
var coordonneesBordure = calculerCoordonneesBordure(); |
var parametres = { |
"source" : "floradata", |
"bbox" : coordonneesBordure, |
"zoom" : map.getZoom() |
}; |
url = urlBase + "mailles?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterDonneesStations; |
executerAJAX(); |
}, 400); |
if (nombreStations == 0) { |
coucheSites.removeLayer(maille); |
} else { |
colorerMaille(maille) |
genererInfobulle(maille); |
} |
} |
|
function calculerNombreMaillesVisibles() { |
var nombreMailles = 0; |
coucheSites.eachLayer(function(layer) { |
if($(layer._path).attr('fill-opacity') != '0') { |
nombreMailles ++; |
} |
}); |
return nombreMailles; |
} |
|
function estValeurDansTableau(tableau, valeur) { |
var index; |
for (index = 0; index < tableau.length && tableau[index] != valeur; index ++); |
return (tableau.length > 0 && index != tableau.length); |
} |
|
//************************************ |
// requetes stations |
|
function surChangementVueCarte() { |
programmerRafraichissementCarte(); |
} |
|
function programmerRafraichissementCarte(source) { |
$('#tooltip').css('display', 'none'); |
source = (source == null || source == 'null') ? null : source; |
if (!chargementMaillesEnCours) { |
if (timer != null) { |
window.clearTimeout(timer); |
} |
if (requeteChargementPoints != null) { |
if (source == null) { |
stopperRequeteAjax(); |
} |
var nombreSourcesVisibles = 0; |
for (var index = 0; index < overlays.length; index ++) { |
if (overlays[index].checked) { |
nombreSourcesVisibles ++; |
} |
timer = window.setTimeout("rafraichirDonnnees('"+source+"')", 250); |
} |
if (source == null) { |
timer = window.setTimeout("chargerLocalisations()", 100); |
} else { |
window.setTimeout("programmerRafraichissementCarte('"+source+"')", 400); |
timer = window.setTimeout("chargerSource('"+source+"')", 100); |
} |
} |
|
276,85 → 244,141 |
requeteChargementPoints = null; |
} |
|
function rafraichirDonnnees(source) { |
source = (source == null || source == 'null') ? null : source; |
if (coucheDepartement == null || coucheDepartement.getStatus() == KML_READY) { |
if (source != null) { |
chargerLocalisations(source); |
} else { |
supprimerLocalisations(); |
for (source in sources) { |
if (sources[source] == true) { |
chargerLocalisations(source); |
function chargerLocalisations() { |
if (requeteEnCours()) { |
requeteChargementPoints.abort(); |
} |
afficherMessageChargement('stations'); |
if (!(ancienneRequete != null && ancienneRequete[1] == map.getZoom() |
&& map.getBounds().intersects(ancienneRequete[0]))) { |
supprimerFeatures(); |
deplacement = false; |
} |
var bboxRequete = calculerBboxRequete(); |
var parametres = { |
"bbox" : bboxRequete, |
"zoom" : map.getZoom(), |
"source" : recupererSourcesActivees(), |
"num_taxon" : numTaxon, |
"nn" : nn, |
"referentiel" : referentiel, |
"dept" : dept, |
"auteur" : auteur, |
"date_debut" : dateDebut, |
"date_fin" : dateFin, |
"nb_jours" : nbJours |
}; |
if (deplacement == true) { |
parametres.format = typeSite; |
} |
} else { |
window.setTimeout("rafraichirDonnnees('"+source+"')", 800); |
ancienneRequete = [map.getBounds(), map.getZoom()]; |
url = urlBase + "stations?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterDonneesStations; |
executerAJAX(); |
} |
} |
|
function supprimerTousLayers() { |
function supprimerFeatures() { |
if (coucheSites != null) { |
coucheSites.clearLayers(); |
points = []; |
formeDonnees = ''; |
coucheSites = null; |
} |
} |
|
function supprimerLocalisations(source) { |
source = (typeof(source) == 'undefined') ? null : source; |
if (source != null) { |
var sourceUrl = recupererParametreDansUrl('source', url); |
if (requeteChargementPoints != null && sourceUrl == source && source != null) { |
stopperRequeteAjax(); |
function recupererSourcesActivees(sourceAIgnorer) { |
sourceAIgnorer = typeof(sourceAIgnorer) == 'undefined' ? '' : sourceAIgnorer; |
var sourcesActivees = []; |
for (var index = 0; index < overlays.length; index ++) { |
if (overlays[index].checked == true && overlays[index].value != sourceAIgnorer) { |
sourcesActivees.push(overlays[index].value); |
} |
coucheSites.eachLayer(function(layer) { |
supprimerLayer(layer, source); |
}); |
if (source != null) { |
supprimerPointsListe(source); |
} |
var sourcesSelectionnees = determinerSourcesSelectionnees(); |
if (sourcesSelectionnees.length == 1 && determinerNombreMarqueurs(sourcesSelectionnees[0]) > 0) { |
transformerMaillesEnPoints(sourcesSelectionnees[0]); |
return sourcesActivees.join(','); |
} |
var sontPointsAffiches = (points.length>0 && determinerNombreMailles(false)==0); |
formeDonnees = sontPointsAffiches ? 'point' : 'maille'; |
|
function chargerSource(sourceAjout) { |
if (requeteEnCours()) { |
requeteChargementPoints.abort(); |
} |
afficherMessageChargement('stations'); |
var bboxRequete = determinerCoordonneesBordure(); |
var parametres = { |
"bbox" : bboxRequete, |
"zoom" : map.getZoom(), |
"format" : typeSite, |
"source" : sourceAjout, |
"num_taxon" : numTaxon, |
"nn" : nn, |
"referentiel" : referentiel, |
"dept" : dept, |
"auteur" : auteur, |
"date_debut" : dateDebut, |
"date_fin" : dateFin, |
"nb_jours" : nbJours |
}; |
ancienneRequete = [map.getBounds(), map.getZoom()]; |
url = urlBase + "stations?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterRetourChargementSource; |
executerAJAX(); |
} |
|
function estLayerUtilisePourSource(layer, source) { |
return ( |
(layer.typeSite == 'MAILLE' && typeof(layer.nombrePoints[source]) != 'undefined') || |
(layer.typeSite != 'MAILLE' && layer.source == source) |
); |
function calculerBboxRequete() { |
var bordure = map.getBounds(); |
var bboxRequete = ""; |
if (ancienneRequete != null && ancienneRequete[1] == map.getZoom() |
&& bordure.intersects(ancienneRequete[0])) { |
bboxRequete = calculerIntersectionRectangle(ancienneRequete[0], bordure); |
} else { |
bboxRequete = determinerCoordonneesBordure(); |
} |
return bboxRequete; |
} |
|
function supprimerLayer(layer, source) { |
if (estLayerUtilisePourSource(layer, source)) { |
if (layer.typeSite == 'MAILLE') { |
supprimerSourceDansMaille(layer, source); |
function calculerIntersectionRectangle(rectangle1, rectangle2) { |
var bbox1 = [rectangle2.getSouthWest().lng.toFixed(6), rectangle2.getSouthWest().lat.toFixed(6), |
rectangle2.getNorthEast().lng.toFixed(6), rectangle2.getNorthEast().lat.toFixed(6)]; |
var bbox2 = [rectangle2.getSouthWest().lng.toFixed(6), rectangle2.getSouthWest().lat.toFixed(6), |
rectangle2.getNorthEast().lng.toFixed(6), rectangle2.getNorthEast().lat.toFixed(6)]; |
|
if (rectangle2.getSouthWest().lng >= rectangle1.getSouthWest().lng |
&& rectangle2.getSouthWest().lng <= rectangle1.getNorthEast().lng) { |
bbox2[0] = bbox1[2] = rectangle1.getNorthEast().lng.toFixed(6); |
if (rectangle2.getSouthWest().lat >= rectangle1.getSouthWest().lat |
&& rectangle2.getSouthWest().lat <= rectangle1.getNorthEast().lat) { |
bbox1[1] = rectangle1.getNorthEast().lat.toFixed(6); |
} else { |
coucheSites.removeLayer(layer); |
bbox1[3] = rectangle1.getSouthWest().lat.toFixed(6); |
} |
} else { |
bbox2[0] = bbox1[2] = rectangle1.getSouthWest().lng.toFixed(6); |
if (rectangle2.getSouthWest().lat >= rectangle1.getSouthWest().lat |
&& rectangle2.getSouthWest().lat <= rectangle1.getNorthEast().lat) { |
bbox2[1] = rectangle1.getNorthEast().lat.toFixed(6); |
} else { |
bbox2[3] = rectangle1.getSouthWest().lat.toFixed(6); |
} |
} |
return bbox1.join(',')+'|'+bbox2.join(','); |
} |
|
|
function changerSource(projetClique) { |
var indexProjetClique; |
for (var index = 0; index < overlays.length; index ++) { |
if (overlays[index].value == projetClique) { |
indexProjetClique = index; |
function determinerCoordonneesBordure() { |
var ouest = map.getBounds().getSouthWest().lng.toFixed(6), |
sud = Math.max(map.getBounds().getSouthWest().lat, -85.051129).toFixed(6), |
est = map.getBounds().getNorthEast().lng.toFixed(6), |
nord = Math.min(map.getBounds().getNorthEast().lat, 85.051129).toFixed(6); |
// appliquer les limites possibles de la projection actuellement utilisee aux coordonnees |
// longitudes ouest et est de la bbox (permettra d'eviter de renvoyer des messages d'erreur) |
if (ouest < -180) { |
ouest += 360; |
} else if (ouest > 180) { |
ouest -= 360; |
} |
if (est < -180) { |
est += 360; |
} else if (est > 180) { |
est -= 360; |
} |
masquerInfoBulle(); |
sources[projetClique] = overlays[indexProjetClique].checked; |
if (sources[projetClique] == true) { |
programmerRafraichissementCarte(projetClique); |
} else { |
supprimerLocalisations(projetClique); |
return [ouest, sud, est, nord].join(','); |
} |
} |
|
function afficherMessageChargement(element) { |
if ($("#zone-chargement").css('display') == 'none') { |
369,11 → 393,8 |
$("#zone-chargement").children().remove(); |
} |
|
|
// execution d'une requete AJAX |
function executerAJAX() { |
if (requeteEnCours()) { |
masquerMessageChargement(); |
requeteChargementPoints.abort(); |
} |
requeteChargementPoints = $.getJSON(url).complete(function() { |
390,54 → 411,36 |
|| requeteChargementPoints.status == 0); |
} |
|
function chargerLocalisations(source) { |
if (requeteEnCours()) { |
window.setTimeout("chargerLocalisations('"+source+"')", 400); |
} else { |
afficherMessageChargement('stations'); |
// generer l'URL du script a interroger sur le serveur |
var coordonneesBordure = calculerCoordonneesBordure(); |
var parametres = { |
"source" : source, |
"num_taxon" : numTaxon, |
"referentiel" : referentiel, |
"dept" : dept, |
"nn" : nn, |
"auteur" : auteur, |
"date_debut" : dateDebut, |
"date_fin" : dateFin, |
"bbox" : coordonneesBordure, |
"nb_jours" : nbJours, |
"zoom" : map.getZoom() |
function convertirEnParametresUrl(objet) { |
var parametresUrl = ''; |
for (attribut in objet) { |
if (typeof(objet[attribut]) == 'function' || typeof(objet[attribut]) == 'undefined' || |
objet[attribut] == null || objet[attribut] == '*' || objet[attribut] == 0) |
continue; |
parametresUrl += (parametresUrl == '' ? '' : '&') + attribut + "=" + objet[attribut]; |
} |
return parametresUrl; |
}; |
url = urlBase + "stations?" + convertirEnParametresUrl(parametres); |
fonctionCallback = traiterDonneesStations; |
executerAJAX(); |
|
function traiterDonneesStations() { |
masquerMessageChargement(); |
masquerLegende(); |
if (deplacement == true) { |
supprimerFeaturesHorsBbox(); |
} |
deplacement = true; |
var texte = requeteChargementPoints.responseText; |
if (!estStatutRequeteOK()) { |
alert(texte); |
} else { |
var donneesJSON = eval("(function(){return " + texte + ";})()"); |
if (donneesJSON != null && donneesJSON.features.length > 0) { |
ajouterStationsSurCarte(donneesJSON); |
} |
|
function calculerCoordonneesBordure() { |
var bordure = map.getBounds(); |
var ouest = bordure.getSouthWest().lng.toFixed(6), |
sud = Math.max(bordure.getSouthWest().lat, -85.051129).toFixed(6), |
est = bordure.getNorthEast().lng.toFixed(6), |
nord = Math.min(bordure.getNorthEast().lat, 85.051129).toFixed(6); |
// appliquer les limites possibles de la projection actuellement utilisee aux coordonnees |
// longitudes ouest et est de la bbox (permettra d'eviter de renvoyer des messages d'erreur) |
if (ouest < -180) { |
ouest += 360; |
} else if (ouest > 180) { |
ouest -= 360; |
} |
if (est < -180) { |
est += 360; |
} else if (est > 180) { |
est -= 360; |
} |
return [ouest, sud, est, nord].join(','); |
} |
|
function traiterDonneesStations() { |
function traiterRetourChargementSource() { |
masquerMessageChargement(); |
var texte = requeteChargementPoints.responseText; |
if (!estStatutRequeteOK()) { |
444,82 → 447,78 |
alert(texte); |
} else { |
var donneesJSON = eval("(function(){return " + texte + ";})()"); |
if (donneesJSON != null && typeof(donneesJSON.features) != 'undefined') { |
if (donneesJSON != null && donneesJSON.features.length > 0) { |
var formatRetourDifferent = donneesJSON.stats.formeDonnees != typeSite; |
ajouterStationsSurCarte(donneesJSON); |
if (formatRetourDifferent) { |
var sourceAIgnorer = donneesJSON.stats.source[0]; |
var sourcesARecharger = recupererSourcesActivees(sourceAIgnorer); |
rechargerSources(sourcesARecharger); |
} |
} |
} |
} |
|
function ajouterStationsSurCarte(data) { |
if (doitTransformerEnMaille(data.stats)) { |
if (points.length > 0 && data.stats.source != '') { |
combinerMaillesEtPoints(); |
function supprimerFeaturesHorsBbox() { |
var bordure = map.getBounds(); |
var layersRestants = 0; |
if (coucheSites != null) { |
coucheSites.eachLayer(function(layer) { |
if (typeof(layer._latlng) != 'undefined') { |
if (bordure.contains(layer.getLatLng())) { |
layersRestants ++; |
} else { |
coucheSites.supprimerPoint(layer); |
} |
formeDonnees = 'maille'; |
} else { |
formeDonnees = data.stats.formeDonnees; |
if (bordure.intersects(layer.getBounds())) { |
layersRestants ++; |
} else { |
coucheSites.removeLayer(layer); |
} |
var sourceDonnees = data.stats.source; |
for (var index = 0; index < data.features.length; index ++) { |
ajouterStation(data.features[index]); |
} |
if (formeDonnees == 'maille' && data.stats.sites > 0) { |
afficherLegende(); |
regenererInfobulleMailles(); |
} else { |
masquerLegende(); |
}); |
} |
if (chargementMaillesEnCours) { |
chargementMaillesEnCours = false; |
programmerRafraichissementCarte(); |
if (layersRestants == 0) { |
coucheSites = null; |
} |
} |
|
function ajouterStation(feature) { |
if (feature.properties.typeSite == 'MAILLE') { |
function rechargerSources(sourcesARecharger) { |
var listeSourcesASupprimer = sourcesARecharger.split(','); |
for (var index = 0; index < listeSourcesASupprimer.length; index ++) { |
supprimerFeaturesSource(listeSourcesASupprimer[index]); |
} |
chargerSource(sourcesARecharger); |
} |
|
function ajouterStationsSurCarte(donnees) { |
typeSite = donnees.stats.formeDonnees; |
if (coucheSites == null) { |
coucheSites = (typeSite == 'maille') ? new L.FeatureGroup() : new L.ClusterGroup(); |
map.addLayer(coucheSites); |
} |
for (var index = 0; index < donnees.features.length; index ++) { |
var feature = donnees.features[index]; |
if (typeSite == 'maille') { |
traiterMaille(feature); |
} else { |
ajouterPoint(feature); |
} |
} |
|
function doitTransformerEnMaille(statsFeatures) { |
var condition1 = (formeDonnees == 'point' && statsFeatures.formeDonnees =='maille'); |
var condition2 = (formeDonnees == 'maille' && statsFeatures.formeDonnees =='point' |
&& determinerNombreMailles(false) > 0); |
var condition3 = (statsFeatures.formeDonnees == 'point' && map.getZoom() <= ZOOM_MAXIMUM_MAILLAGE |
&& (points.length+statsFeatures.sites) > SEUIL_MAILLAGE); |
return (condition1 || condition2 || condition3); |
if (donnees.features.length > 0) { |
afficherLegende(); |
} |
if (typeSite == 'maille') { |
genererInfobulleMailles(); |
} else { |
coucheSites.afficherClusters(); |
} |
} |
|
|
|
// ==================================================================== |
// ========================================= |
// Gestion des mailles |
|
var optionsMaille = { |
color: '#FFFFFF', |
opacity : 0.7, |
weight: 1, |
fillOpacity : 0.6 |
}; |
|
function determinerNombreMailles(prendToutesMailles) { |
var nombreMailles = 0; |
coucheSites.eachLayer(function(layer) { |
if ('typeSite' in layer && layer.typeSite == 'MAILLE') { |
var nombrePoints = 0; |
for (var source in layer.nombrePoints) { |
nombrePoints = layer.nombrePoints[source]; |
} |
if (prendToutesMailles || nombrePoints>0) { |
nombreMailles ++; |
} |
} |
}); |
return nombreMailles; |
} |
|
function traiterMaille(feature) { |
var coordonnees = []; |
for (var i = 0; i < feature.geometry.coordinates.length; i++) { |
529,15 → 528,16 |
var maille = rechercherMailleExistante(coordonnees); |
if (maille) { |
mettreAJourMaille(maille, feature); |
} else if (feature.properties.nombrePoints > 0) { |
ajouterMaille(feature); |
} else { |
maille = ajouterMaille(feature, coordonnees); |
} |
colorerMaille(maille); |
} |
|
function rechercherMailleExistante(coordonnees) { |
var mailleTrouvee = null; |
coucheSites.eachLayer(function(layer) { |
if ('typeSite' in layer && layer.typeSite == 'MAILLE') { |
if ('typeSite' in layer && layer.typeSite == 'maille') { |
if (sontMaillesIdentiques(coordonnees, layer._latlngs)) { |
mailleTrouvee = layer; |
return; |
556,60 → 556,49 |
); |
} |
|
function ajouterMaille(feature) { |
var coordonnees = []; |
for (var i = 0; i < feature.geometry.coordinates.length; i++) { |
var sommet = new L.LatLng(feature.geometry.coordinates[i][0], feature.geometry.coordinates[i][1]); |
coordonnees.push(sommet); |
} |
function ajouterMaille(feature, coordonnees) { |
var maille = new L.Polygon(coordonnees); |
var optionsMaille = { |
color: '#FFFFFF', |
opacity : 0.7, |
weight: 1, |
fillOpacity : 0.6 |
}; |
maille.setStyle(optionsMaille); |
maille.typeSite = feature.properties.typeSite; |
maille.nombrePoints = new Object(); |
var nombreAAjouter = feature.properties.nombrePoints == null ? 0 : parseInt(feature.properties.nombrePoints); |
maille.nombrePoints[feature.properties.source] = nombreAAjouter; |
maille.typeSite = 'maille'; |
maille.properties = feature.properties; |
coucheSites.addLayer(maille); |
colorerMaille(maille); |
return maille; |
} |
|
function mettreAJourMaille(maille, feature) { |
var nombreAAjouter = feature.properties.nombrePoints == null ? 0 : parseInt(feature.properties.nombrePoints); |
/*if (typeof(maille.nombrePoints[feature.properties.source]) == 'undefined') { |
maille.nombrePoints[feature.properties.source] = nombreAAjouter; |
} else { |
maille.nombrePoints[feature.properties.source] += nombreAAjouter; |
}*/ |
maille.nombrePoints[feature.properties.source] = nombreAAjouter; |
colorerMaille(maille); |
var sources = feature.properties.source; |
for (var index = 0; index < sources.length; index ++) { |
var source = sources[index]; |
maille.properties.stations[source] = parseInt(feature.properties.stations[source]); |
maille.properties.observations[source] = parseInt(feature.properties.observations[source]); |
maille.properties.source.push(source); |
} |
|
function regenererInfobulleMailles() { |
$('.leaflet-clickable').addClass('tooltip'); |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE') { |
genererInfobulle(layer); |
} |
}); |
} |
|
function colorerMaille(maille) { |
var nombrePoints = 0; |
for (sourceMaille in maille.nombrePoints) { |
nombrePoints += maille.nombrePoints[sourceMaille]; |
var nombreStations = 0; |
var sources = maille.properties.source; |
for (var index = 0; index < sources.length; index ++) { |
var source = sources[index]; |
if (typeof(maille.properties.stations[source]) != 'undefined') { |
nombreStations += parseInt(maille.properties.stations[source]); |
} |
if (nombrePoints > 0) { |
} |
if (nombreStations > 0) { |
maille.on('click', surClicMaille); |
maille.setStyle({fillColor : genererCouleur(nombrePoints), fillOpacity: 0.45, opacity: 0.7}); |
maille.setStyle({fillColor : genererCouleur(nombreStations), fillOpacity: 0.45, opacity: 0.7}); |
} else { |
maille.setStyle({fillOpacity: 0, opacity: 0}); |
maille.off('click', surClicMaille); |
maille.off('click'); |
} |
} |
|
function surClicMaille(event) { |
map.fitBounds(event.layer.getBounds()); |
} |
|
function genererCouleur(nombrePoints) { |
var couleur = {'bleu': 231, 'vert': 224, 'rouge': 64}, |
seuils = [1, 10, 50 ,100, 500, 1000, 2500], |
622,17 → 611,27 |
return 'rgb('+couleur.bleu+','+couleur.vert+','+couleur.rouge+')'; |
} |
|
function surClicMaille(event) { |
map.fitBounds(event.layer.getBounds()); |
} |
|
function afficherLegende() { |
if (legende == null) { |
legende = new L.Control({position : 'bottomright'}); |
legende.onAdd = function(map) { |
return construireContenuHtmlLegende(); |
var contenuHtml = ''; |
if (typeSite == 'maille') { |
contenuHtml = construireContenuHtmlLegendeMailles(); |
} else { |
contenuHtml = construireContenuHtmlLegendePoints(); |
} |
return contenuHtml; |
}; |
map.addControl(legende); |
} |
} |
|
function construireContenuHtmlLegende() { |
function construireContenuHtmlLegendeMailles() { |
var div = L.DomUtil.create('div', 'info'); |
div.innerHTML = '<h4>' + titreLegende + '</h4>'; |
var seuils = [1, 10, 50 ,100, 500, 1000, 2500]; |
640,8 → 639,8 |
for (var i = 0; i < seuils.length; i ++) { |
div.innerHTML += |
'<div class="legend">'+ |
'<span style="background:' + genererCouleur(seuils[i] + 1) + '"></span>'+ |
seuils[i]+ (i + 1 < seuils.length ? '–' + seuils[i + 1] : '+')+ |
'<span class="couleur-maille" style="background:' + genererCouleur(seuils[i] + 1) + '">'+ |
'</span>'+seuils[i]+ (i + 1 < seuils.length ? '–' + seuils[i + 1] : '+')+ |
'</div>'; |
} |
return div; |
654,166 → 653,115 |
} |
} |
|
function supprimerSourceDansMaille(maille, sourceSuppression) { |
if (typeof(maille.nombrePoints[sourceSuppression]) != 'undefined') { |
maille.nombrePoints[sourceSuppression] = 0; |
colorerMaille(maille); |
genererInfobulle(maille); |
function genererInfobulleMailles() { |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'maille') { |
genererInfobulle(layer); |
} |
}); |
} |
|
function genererInfobulle(maille) { |
var nombrePoints = 0, |
nombreSources = 0; |
contenuTexte = ''; |
for (sourceMaille in maille.nombrePoints) { |
nombrePoints = maille.nombrePoints[sourceMaille]; |
if (nombrePoints > 0) { |
contenuTexte += (contenuTexte.length==0 ?'' : '\n')+ |
sourceMaille+' : '+maille.nombrePoints[sourceMaille]; |
var sources = maille.properties.source; |
var textes = new Array(); |
for (var index = 0; index < sources.length; index ++) { |
var source = sources[index]; |
if (typeof(maille.properties.stations[source]) != 'undefined') { |
textes.push(source+" : "+maille.properties.stations[source]+" stations, " |
+maille.properties.observations[source]+" observations"); |
} |
nombreSources ++; |
} |
if (nombreSources > 0) { |
$(maille._path).addClass('tooltip'); |
$(maille._path).attr('title',contenuTexte); |
var contenu = textes.join('<br />'); |
maille.on('mouseover', function() { |
afficherTooltip(contenu, map.latLngToContainerPoint(maille.getBounds().getSouthWest())); |
}); |
maille.on('mouseout', function() { |
$("#tooltip").css('display', 'none'); |
}); |
} |
|
function afficherTooltip(texte, point) { |
$("#tooltip").html(texte); |
if ($("#tooltip").css('display') == 'none') { |
var x = point.x - 15; |
var y = point.y + (typeSite == 'maille' ? 1 : 10); |
$("#tooltip").css('display', 'block'); |
$("#tooltip").css('left', x + 'px'); |
$("#tooltip").css('top', y + 'px'); |
} |
} |
|
|
|
|
// ==================================================================== |
// Gestion des marqueurs |
// Gestion des points |
|
function ajouterPoint(feature) { |
var iconePoint = new L.Icon({ iconUrl : pointImageUrl, iconSize : [16, 16] }), |
iconeCommune = new L.Icon({ iconUrl : communeImageUrl, iconSize : [24, 32] }), |
icone = (feature.properties.typeSite == 'STATION') ? iconePoint : iconeCommune, |
point = new L.LatLng(feature.geometry.coordinates[0], feature.geometry.coordinates[1]), |
marker = new L.Marker(point, { |
point = new L.LatLng(feature.geometry.coordinates[0], feature.geometry.coordinates[1]); |
var marker = new L.Cluster(point, { |
icon : icone, |
title : feature.properties.nom |
}) |
marker.typeSite = feature.properties.typeSite; |
titre : feature.properties.nom |
}); |
marker.typeSite = feature.properties.typeSite.toLowerCase(); |
marker.source = feature.properties.source; |
marker.on('click', surClicMarqueur); |
points.push(marker); |
if (formeDonnees != 'maille') { |
coucheSites.addLayer(marker); |
} else { |
ajouterPointDansMaille(marker); |
} |
} |
|
function ajouterPointDansMaille(point) { |
var maille = null; |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE' && layer.getBounds().contains(point.getLatLng())) { |
maille = layer; |
return; |
} |
marker.on('mouseover', function() { |
afficherTooltip(marker.options.titre, map.latLngToContainerPoint(marker.getLatLng())); |
}); |
if (typeof(maille.nombrePoints[point.source]) == 'undefined') { |
maille.nombrePoints[point.source] = 1; |
} else { |
maille.nombrePoints[point.source] += 1; |
} |
colorerMaille(maille); |
} |
|
function combinerMaillesEtPoints() { |
enleverMarqueursCarte(); |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE') { |
var nombrePoints = compterNombrePointsDansMaille(layer); |
ajouterNombrePointsDansMaille(layer, nombrePoints); |
} |
marker.on('mouseout', function() { |
$("#tooltip").css('display', 'none'); |
}); |
coucheSites.ajouterPoint(marker); |
} |
|
function determinerNombreMarqueurs(source) { |
var nombrePoints = 0; |
for (var index = 0; index < points.length; index ++) { |
if (points[index].source == source) { |
nombrePoints += 1; |
function construireContenuHtmlLegendePoints() { |
var div = L.DomUtil.create('div', 'info'); |
div.innerHTML = |
'<h4>Stations</h4>'+ |
'<div class="legend"><table>'+ |
'<tr>'+ |
'<td class="image-station"><img src="'+communeImageUrl+'" width="24" height="32" /></td>'+ |
'<td class="label-station">Commune</td>'+ |
'</tr>'+ |
'<tr>'+ |
'<td class="image-station"><img src="'+pointImageUrl+'" /></td>'+ |
'<td class="label-station">Lieu précis</td>'+ |
'</tr>'+ |
'<tr>'+ |
'<td class="image-station"><img src="'+clusterImageUrl+'" width="20" height="20" /></td>'+ |
'<td class="label-station">Groupe de stations proches</td>'+ |
'</tr>'+ |
'</table></div>'; |
return div; |
} |
} |
return nombrePoints; |
} |
|
function enleverMarqueursCarte() { |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite != 'MAILLE') { |
coucheSites.removeLayer(layer); |
} |
}); |
} |
|
function compterNombrePointsDansMaille(maille) { |
var nombrePoints = {}; |
for (var index = 0; index < points.length; index ++) { |
if (maille.getBounds().contains(points[index].getLatLng())) { |
var source = points[index].source; |
if (typeof(nombrePoints[source]) == 'undefined') { |
nombrePoints[source] = 1; |
function surClicMarqueur(event) { |
var nombreMarkers = event.target.recupererMarkers().length; |
if (nombreMarkers == 1 || map.getZoom() == map.getMaxZoom()) { |
recupererObservations(event.target); |
} else { |
nombrePoints[source] += 1; |
map.setView(event.target.getLatLng(), Math.min(map.getZoom()+2, map.getMaxZoom())); |
} |
} |
} |
return nombrePoints; |
} |
|
function ajouterNombrePointsDansMaille(maille, nombrePoints) { |
for (sourceDonnees in nombrePoints) { |
if (typeof(maille.nombrePoints[sourceDonnees]) == 'undefined') { |
maille.nombrePoints[sourceDonnees] = nombrePoints[sourceDonnees]; |
} else { |
maille.nombrePoints[sourceDonnees] += nombrePoints[sourceDonnees]; |
} |
} |
colorerMaille(maille); |
} |
|
function supprimerPointsListe(sourceDonnees) { |
var index = 0; |
while (index < points.length) { |
if (points[index].source == sourceDonnees) { |
points.splice(index, 1); |
} else { |
index ++; |
} |
} |
} |
|
function transformerMaillesEnPoints(sourceDonnees) { |
coucheSites.eachLayer(function(layer) { |
if (layer.typeSite == 'MAILLE' && typeof(layer.nombrePoints[sourceDonnees]) != 'undefined') { |
supprimerSourceDansMaille(layer, sourceDonnees); |
} |
}); |
for (var index = 0; index < points.length; index ++) { |
coucheSites.addLayer(points[index]); |
} |
} |
|
function surClicMarqueur(event) { |
var latitude = event.target.getLatLng().lat; |
var longitude = event.target.getLatLng().lng; |
pointClique = event.target; |
function recupererObservations(cluster) { |
pointClique = cluster; |
var latlng = cluster.getLatLng(); |
afficherMessageChargement('observations'); |
var parametres = { |
"source" : pointClique.source, |
"source" : recupererSourcesCluster(cluster), |
"stations" : construireListeStationsCluster(cluster), |
"num_taxon" : numTaxon, |
"nn" : nn, |
"referentiel" : referentiel, |
"auteur" : auteur, |
"nn" : nn, |
"type_site" : pointClique.typeSite, |
"date_debut" : dateDebut, |
"date_fin" : dateFin, |
"longitude" : longitude, |
"latitude" : latitude, |
"nb_jours" : nbJours |
}; |
url = urlBase + "observations?" + convertirEnParametresUrl(parametres); |
821,6 → 769,27 |
executerAJAX(); |
} |
|
function recupererSourcesCluster(cluster) { |
var markers = cluster.recupererMarkers(); |
var sourcesCluster = []; |
for (var index = 0; index < markers.length; index ++) { |
if (sourcesCluster.indexOf(markers[index].source) == -1) { |
sourcesCluster.push(markers[index].source); |
} |
} |
return sourcesCluster.join(','); |
} |
|
function construireListeStationsCluster(cluster) { |
var markers = cluster.recupererMarkers(); |
var listePoints = []; |
for (var index = 0; index < markers.length; index ++) { |
var latlng = markers[index].getLatLng(); |
listePoints.push(markers[index].source+":"+markers[index].typeSite+":"+latlng.lng+","+latlng.lat); |
} |
return listePoints.join('|'); |
} |
|
function traiterDonneesObservations() { |
masquerMessageChargement(); |
var texte = requeteChargementPoints.responseText; |
841,13 → 810,9 |
} |
} |
|
function viderListeObservations() { |
obsStation = new Array(); |
} |
|
|
|
|
// ==================================================================== |
// Gestion de l'infobulle |
|
854,18 → 819,26 |
var obsJSON = null, |
pointClique = null, |
obsStation = [], |
typeAffichage = ""; |
pagineur = {'limite':100, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'}; |
|
function afficherInfoBulle() { |
var latitude = pointClique.getLatLng().lat; |
var longitude = pointClique.getLatLng().lng; |
infoBulle = new L.Popup({maxWidth : definirLargeurInfoBulle(), maxHeight : 350}); |
infoBulle = new L.Popup({maxWidth : definirLargeurInfoBulle(), maxHeight : 380}); |
infoBulle.setLatLng(new L.LatLng(latitude, longitude)); |
infoBulle.setContent($("#tpl-obs").html()); |
infoBulle.openOn(map); |
remplirContenuPopup(); |
$('#info-bulle').css('width', '99%'); |
$('#observations').css('height', '250px'); |
$('#observations').css('overflow', 'auto'); |
$('.leaflet-popup-scrolled').css('overflow', 'visible'); |
} |
|
function viderListeObservations() { |
obsStation = new Array(); |
} |
|
function definirLargeurInfoBulle() { |
var largeurViewPort = $(window).width(); |
var lageurInfoBulle = null; |
881,13 → 854,13 |
|
function redimensionnerPopup() { |
$('.leaflet-popup-content*').css('width', definirLargeurInfoBulle()); |
$('#info-bulle').css('width', definirLargeurInfoBulle()); |
$('#info-bulle').css('width', '99%'); |
} |
|
function remplirContenuPopup() { |
ajouterTableauTriable("#obs-tableau"); |
ajouterTitre(); |
afficherOnglets(); |
afficherTableau(); |
afficherTexteStationId(); |
} |
|
900,23 → 873,18 |
|
function ajouterTitre() { |
var texteStationTitre = obsJSON.total + ' observation' + (obsJSON.total > 1 ? 's' : '') |
+ ' pour ' + (pointClique.options.type=='STATION' ? 'la station : ' : 'la commune : ') |
+ ' sur ' + (pointClique.typeSite=='station' ? 'la station : ' : 'la commune : ') |
+ pointClique.options.title; |
$('#obs-station-titre').text(texteStationTitre); |
} |
|
function selectionnerOnglet() { |
$("#obs-vue-" + typeAffichage).css("display", "block"); |
$('#obs-tableau-lignes').empty(); |
$('#obs-liste-lignes').empty(); |
if (typeAffichage=='liste') { |
$("#obs-vue-tableau").css("display", "none"); |
} else { |
$("#obs-vue-liste").css("display", "none"); |
function afficherTableau() { |
construireListeObservations(); |
afficherPagination(); |
afficherObservationsDansHTML(); |
} |
} |
|
function ajouterObservationsDansHTML() { |
function construireListeObservations() { |
if (obsStation.length==0) { |
// premiere execution de la fonction : faire une copie des objets JSON decrivant les observations |
for (var index = 0; index < obsJSON.observations.length; index ++) { |
923,43 → 891,37 |
obsStation.push(obsJSON.observations[index]); |
} |
} |
var obsPage = []; |
for (var index = 0; index < obsStation.length; index ++) { |
obsPage.push(obsStation[index]); |
pagineur.total = obsStation.length; |
} |
$("#tpl-obs-"+typeAffichage).tmpl(obsPage).appendTo("#obs-"+typeAffichage+"-lignes"); |
} |
|
function afficherOnglets() { |
var $tabs = $('#obs').tabs(); |
$('#obs').bind('tabsselect', function(event, ui) { |
if (ui.panel.id == 'obs-vue-tableau') { |
surClicAffichageTableau(); |
} else if (ui.panel.id == 'obs-vue-liste') { |
surClicAffichageListe(); |
} |
function afficherPagination() { |
$(".navigation").pagination(pagineur.total, { |
items_per_page:pagineur.limite, |
callback:afficherObservationsDansHTML, |
next_text:'Suivant', |
prev_text:'Précédent', |
prev_show_always:false, |
num_edge_entries:1, |
num_display_entries:4, |
load_first_page:true |
}); |
if (obsJSON.total > 4) { |
surClicAffichageTableau(); |
} else { |
$tabs.tabs('select', "#obs-vue-liste"); |
} |
} |
|
function surClicAffichageTableau() { |
typeAffichage = 'tableau'; |
selectionnerOnglet(); |
ajouterObservationsDansHTML(); |
mettreAJourTableauTriable("#obs-tableau"); |
function afficherObservationsDansHTML(indexPage) { |
$("#obs-tableau-lignes").empty(); |
if (typeof(indexPage) == 'undefined') { |
indexPage = 0; |
} |
|
function surClicAffichageListe() { |
typeAffichage = 'liste'; |
selectionnerOnglet(); |
ajouterObservationsDansHTML(); |
var depart = indexPage * pagineur.limite; |
var obsPage = []; |
for (var index = depart; index < depart + pagineur.limite; index ++) { |
obsPage.push(obsStation[index]); |
} |
$("#tpl-obs-tableau").tmpl(obsPage).appendTo("#obs-tableau-lignes"); |
mettreAJourTableauTriable(); |
} |
|
function ajouterTableauTriable(element) { |
function ajouterTableauTriable() { |
$.tablesorter.addParser({ |
id: 'date_cel', |
is: function(s) { |
968,13 → 930,13 |
}, |
format: function(date) { |
// Transformation date jj/mm/aaaa en aaaa/mm/jj |
date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1"); |
date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3-$2-$1"); |
// Remplace la date par un nombre de millisecondes pour trier numériquement |
return $.tablesorter.formatFloat(new Date(date).getTime()); |
}, |
type: 'numeric' |
}); |
$(element).tablesorter({ |
$("#obs-tableau").tablesorter({ |
headers: { |
1: { |
sorter:'date_cel' |
983,13 → 945,14 |
}); |
} |
|
function mettreAJourTableauTriable(element) { |
$(element).trigger('update'); |
function mettreAJourTableauTriable() { |
$("#obs-tableau").trigger('update'); |
} |
|
function afficherTexteStationId() { |
var latitude = pointClique.getLatLng().lat; |
var longitude = pointClique.getLatLng().lng; |
var texteStationId = pointClique.typeSite+':'+latitude+'|'+longitude+', SOURCE:'+pointClique.source; |
var latitude = pointClique.getLatLng().lat.toFixed(5); |
var longitude = pointClique.getLatLng().lng.toFixed(5); |
var texteStationId = pointClique.typeSite.toUpperCase() + ':' |
+ latitude + '|' + longitude + ', SOURCE:' + pointClique.source; |
$('#obs-station-id').text(texteStationId); |
} |