diff --git a/atlas/static/mapGenerator.js b/atlas/static/mapGenerator.js index 3867897da..c1df79768 100644 --- a/atlas/static/mapGenerator.js +++ b/atlas/static/mapGenerator.js @@ -19,6 +19,44 @@ const areaBorderColor = String( ) ); +function formatDate(date) { + const date_options = { + year: 'numeric', + month: 'numeric', + day: 'numeric', + }; + return date.toLocaleDateString(undefined, date_options); +} + +function generateObservationPopup(feature, linkSpecies = false) { + /* + Génération popup des observations + linkSpecies : indique s'il faut ou non rajouter un lien vers la fiche espèce + (cas des fiches communes ; home page) + */ + date = new Date(feature.properties.dateobs); + popupContent = ` + Date: ${formatDate(date)} +
Altitude: ${feature.properties.altitude_retenue} + ${observersTxt(feature)}` + + // verifie si le champs effectif est rempli + if (feature.properties.effectif_total != undefined) { + popupContent = `${popupContent}
Effectif: ${feature.properties.effectif_total}` + } + + // S'il faut lier à une fiche espèce + if (linkSpecies == true) { + popupContent = `Espèce: ${feature.properties.taxon}
+ ${popupContent} +
+ Fiche espèce + ` + } + return popupContent +} + + function generateMap(zoomHomeButton) { // Map initialization firstMapTile = L.tileLayer(configuration.MAP.FIRST_MAP.url, { @@ -153,30 +191,9 @@ function observersTxt(feature) { //****** Fonction fiche espècce *********** // Popup Point -function onEachFeaturePoint(feature, layer) { - date = new Date(feature.properties.dateobs); - const options = { - year: 'numeric', - month: 'long', - day: 'numeric', - }; - popupContent = - "Date: " + - date.toLocaleDateString(undefined, options) + - "
Altitude: " + - feature.properties.altitude_retenue + - observersTxt(feature) - - // verifie si le champs effectif est rempli - if (feature.properties.effectif_total != undefined) { - layer.bindPopup( - popupContent + - "
Effectif: " + - feature.properties.effectif_total - ); - } else { - layer.bindPopup(popupContent); - } +function onEachFeaturePoint(feature, layer) { + popupContent = generateObservationPopup(feature, false); + layer.bindPopup(popupContent); } // popup Maille @@ -431,55 +448,13 @@ function displayMarkerLayerFicheEspece( /* *** Point ****/ function onEachFeaturePointLastObs(feature, layer) { - date = new Date(feature.properties.dateobs); - const options = { - year: 'numeric', - month: 'long', - day: 'numeric', - }; - popupContent = - "Espèce: " + - feature.properties.taxon + - "
Date: " + - date.toLocaleDateString(undefined, options) + - "
Altitude: " + - feature.properties.altitude_retenue; - - layer.bindPopup( - popupContent + - "
Fiche espèce " - ); + popupContent = generateObservationPopup(feature, true); + layer.bindPopup(popupContent); } function onEachFeaturePointCommune(feature, layer) { - date = new Date(feature.properties.dateobs); - const options = { - year: 'numeric', - month: 'long', - day: 'numeric', - }; - popupContent = - "Espèce: " + - feature.properties.taxon + - "
Date: " + - date.toLocaleDateString(undefined, options) + - "
Altitude: " + - feature.properties.altitude_retenue + - observersTxt(feature) - - layer.bindPopup( - popupContent + - "
Fiche espèce " - ); + popupContent = generateObservationPopup(feature, true); + layer.bindPopup(popupContent); } function generateGeojsonPointLastObs(observationsPoint) {