Skip to content

Commit

Permalink
Factorisation popup
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Oct 21, 2024
1 parent 72b730e commit 5736cb9
Showing 1 changed file with 45 additions and 70 deletions.
115 changes: 45 additions & 70 deletions atlas/static/mapGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<b>Date: </b> ${formatDate(date)}
</br><b>Altitude: </b> ${feature.properties.altitude_retenue}
${observersTxt(feature)}`

// verifie si le champs effectif est rempli
if (feature.properties.effectif_total != undefined) {
popupContent = `${popupContent} </br><b>Effectif: </b>${feature.properties.effectif_total}`
}

// S'il faut lier à une fiche espèce
if (linkSpecies == true) {
popupContent = `<b>Espèce: </b> ${feature.properties.taxon} </br>
${popupContent}
</br>
<a href='${configuration.URL_APPLICATION}${language}/espece/${feature.properties.cd_ref}'> Fiche espèce </a>
`
}
return popupContent
}


function generateMap(zoomHomeButton) {
// Map initialization
firstMapTile = L.tileLayer(configuration.MAP.FIRST_MAP.url, {
Expand Down Expand Up @@ -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 =
"<b>Date: </b>" +
date.toLocaleDateString(undefined, options) +
"</br><b>Altitude: </b>" +
feature.properties.altitude_retenue +
observersTxt(feature)

// verifie si le champs effectif est rempli
if (feature.properties.effectif_total != undefined) {
layer.bindPopup(
popupContent +
"</br><b>Effectif: </b>" +
feature.properties.effectif_total
);
} else {
layer.bindPopup(popupContent);
}
function onEachFeaturePoint(feature, layer) {
popupContent = generateObservationPopup(feature, false);
layer.bindPopup(popupContent);
}

// popup Maille
Expand Down Expand Up @@ -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 =
"<b>Espèce: </b>" +
feature.properties.taxon +
"</br><b>Date: </b>" +
date.toLocaleDateString(undefined, options) +
"</br><b>Altitude: </b>" +
feature.properties.altitude_retenue;

layer.bindPopup(
popupContent +
"</br> <a href='" +
configuration.URL_APPLICATION +
language +
"/espece/" +
feature.properties.cd_ref +
"'> Fiche espèce </a>"
);
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 =
"<b>Espèce: </b>" +
feature.properties.taxon +
"</br><b>Date: </b>" +
date.toLocaleDateString(undefined, options) +
"</br><b>Altitude: </b>" +
feature.properties.altitude_retenue +
observersTxt(feature)

layer.bindPopup(
popupContent +
"</br> <a href='" +
configuration.URL_APPLICATION +
"/espece/" +
feature.properties.cd_ref +
"'> Fiche espèce </a>"
);
popupContent = generateObservationPopup(feature, true);
layer.bindPopup(popupContent);
}

function generateGeojsonPointLastObs(observationsPoint) {
Expand Down

0 comments on commit 5736cb9

Please sign in to comment.