Skip to content

Commit 94931eb

Browse files
committed
Merge branch 'main' into analyst/lounes_tous-polluants_udi_dernier
2 parents dedaf94 + 9cc986e commit 94931eb

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

webapp/lib/colorMapping.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import type {
77
} from "maplibre-gl";
88

99
/**
10-
* Generate the map color expression for MapLibre GL
11-
* This creates a "case" expression for use in map style
12-
* @returns A MapLibre GL expression for the fill-color property
10+
* Generates a color expression for MapLibre GL based on data from pmtiles.
11+
*
12+
* Creates a case-based expression that maps different pollution values to specific colors
13+
* for rendering on the map. Handles both "dernier_prelevement" and "bilan_annuel" data periods.
14+
*
15+
* Returns a MapLibre GL expression for the fill-color property
16+
*
17+
* MapLibre expressions documentation : https://maplibre.org/maplibre-style-spec/expressions/
1318
*/
1419
export function generateColorExpression(
1520
category: string,
@@ -24,11 +29,29 @@ export function generateColorExpression(
2429
return defaultColor;
2530
}
2631

32+
// Check if we have no data for this zone (when either cdreseau or commune_code_insee exists but is empty)
33+
// If yes, set the color to transparent to hide these zones on the map
34+
cases.push([
35+
"any",
36+
["all", ["has", "cdreseau"], ["==", ["get", "cdreseau"], ""]],
37+
[
38+
"all",
39+
["has", "commune_code_insee"],
40+
["==", ["get", "commune_code_insee"], ""],
41+
],
42+
]);
43+
cases.push("transparent"); // Transparent for no data
44+
2745
// dernier prélèvement specific logic
2846
if (period.startsWith("dernier_prel")) {
29-
const propertyId = getPropertyName(period, category, "resultat");
47+
const resultatProp = getPropertyName(period, category, "resultat");
3048
Object.entries(categoryDetails.resultats).forEach(([value, detail]) => {
31-
cases.push(["==", ["get", propertyId], value]);
49+
// the value "non_recherche" is actually an empty string so we set a special case for it
50+
if (value === "non_recherche") {
51+
cases.push(["==", ["get", resultatProp], ""]);
52+
} else {
53+
cases.push(["==", ["get", resultatProp], value]);
54+
}
3255

3356
// Check if the color is valid
3457
const color = detail.couleur || detail.couleurFond;
@@ -83,7 +106,7 @@ export function generateColorExpression(
83106
}
84107

85108
if (cases.length > 0) {
86-
const expression = ["case", ...cases, defaultColor];
109+
const expression = ["case", ...cases, "#333333"]; // black for unmatched cases
87110
console.log("Expression:", expression);
88111
return expression as DataDrivenPropertyValueSpecification<ColorSpecification>;
89112
} else {

webapp/lib/polluants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export const availableCategories: ICategory[] = [
287287
couleurFond: "#FFF33B",
288288
picto: null,
289289
},
290-
entre_0_1_et_0_9: {
290+
inf_limite_qualite_sup_0_1: {
291291
label:
292292
"Concentration comprise entre 0,1 et 0,9 µg/L (si l'ESA métolachlore était considéré comme un métabolite pertinent, l'eau serait déclarée \"non conforme\")",
293293
couleur: "#FDC70C",
@@ -340,7 +340,7 @@ export const availableCategories: ICategory[] = [
340340
couleurFond: "#FFF33B",
341341
picto: null,
342342
},
343-
entre_0_1_et_0_9: {
343+
inf_limite_qualite_sup_0_1: {
344344
label:
345345
'Concentration comprise entre 0,1 et 0,9 µg/L*\n\n (si le Chlorothalonil R471811 était considéré comme un métabolite pertinent, l\'eau serait déclarée "non conforme")',
346346
couleur: "#FDC70C",

0 commit comments

Comments
 (0)