Skip to content

Commit e9a0cf8

Browse files
committed
map legend: merges binary and continuous features
1 parent 88f9c4a commit e9a0cf8

File tree

7 files changed

+26
-15
lines changed

7 files changed

+26
-15
lines changed

app/hooks/map/constants.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export const LEGEND_LAYERS = {
252252
}));
253253
},
254254

255-
'features-preview-new': (options: {
255+
'binary-features': (options: {
256256
items: { id: string; name: string; color: string }[];
257257
onChangeVisibility: (featureId: Feature['id']) => void;
258258
}) => {
@@ -314,7 +314,7 @@ export const LEGEND_LAYERS = {
314314
},
315315
}),
316316
// ANALYSIS
317-
['features-abundance']: (options: {
317+
['continuous-features']: (options: {
318318
items: {
319319
id: Feature['id'];
320320
amountRange: { min: number; max: number };
@@ -326,7 +326,7 @@ export const LEGEND_LAYERS = {
326326
const { items, onChangeVisibility } = options;
327327

328328
return items?.map(({ id, name, amountRange, color }) => ({
329-
id: `feature-abundance-${id}`,
329+
id,
330330
name,
331331
type: 'gradient' as LegendItemType,
332332
settingsManager: {

app/hooks/map/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,8 @@ export function usePUGridLayer({
770770
const {
771771
visibility = true,
772772
opacity = 1,
773-
amountRange = { min: 50000, max: 1000000 },
773+
amountRange,
774+
color,
774775
} = restLayerSettings[featureId] || {};
775776

776777
return {
@@ -804,10 +805,9 @@ export function usePUGridLayer({
804805
['linear'],
805806
['var', 'amount'],
806807
amountRange.min,
807-
'white', // ! use COLORS.abundance.default instead when is available
808+
COLORS.abundance.default,
808809
amountRange.max,
809-
'green',
810-
// color, // ! enable the color variable when we receive it
810+
color,
811811
],
812812
],
813813
'fill-opacity': opacity,

app/hooks/map/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export interface UsePUGridLayer {
177177
min: number;
178178
max: number;
179179
};
180+
color?: string;
180181
};
181182
};
182183
};

app/layout/projects/show/map/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export const ProjectMap = (): JSX.Element => {
142142
sublayers: [
143143
...(sid1 && !sid2 ? ['frequency'] : []),
144144
...(!!selectedCostSurface ? ['cost'] : []),
145+
...(!!selectedFeaturesIds.length ? ['features'] : []),
145146
],
146147
options: {
147148
cost: { min: 1, max: 100 },

app/layout/projects/show/map/legend/hooks/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,14 @@ export const useFeaturesLegend = () => {
129129
select: ({ data }) => ({
130130
binaryFeatures:
131131
data?.filter(
132-
(feature) => !Object.hasOwn(feature, 'min') && !Object.hasOwn(feature, 'max')
132+
(feature) =>
133+
!Object.hasOwn(feature.amountRange, 'min') &&
134+
!Object.hasOwn(feature.amountRange, 'max')
133135
) || [],
134136
continuousFeatures:
135137
data?.filter(
136-
(feature) => Object.hasOwn(feature, 'min') && Object.hasOwn(feature, 'max')
138+
(feature) =>
139+
Object.hasOwn(feature.amountRange, 'min') && Object.hasOwn(feature.amountRange, 'max')
137140
) || [],
138141
}),
139142
}
@@ -175,7 +178,7 @@ export const useFeaturesLegend = () => {
175178
) || [];
176179

177180
return [
178-
...LEGEND_LAYERS['features-preview-new']({
181+
...LEGEND_LAYERS['binary-features']({
179182
items: binaryFeaturesItems,
180183
onChangeVisibility: (featureId: Feature['id']) => {
181184
const newSelectedFeatures = [...selectedFeatures];
@@ -201,7 +204,7 @@ export const useFeaturesLegend = () => {
201204
);
202205
},
203206
}),
204-
...LEGEND_LAYERS['features-abundance']({
207+
...LEGEND_LAYERS['continuous-features']({
205208
items: continuousFeaturesItems,
206209
onChangeVisibility: (featureId: Feature['id']) => {
207210
const { color, amountRange } =

app/layout/scenarios/edit/map/component.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export const ScenariosEditMap = (): JSX.Element => {
161161
const sublayers = useMemo(() => {
162162
return [
163163
...(layerSettings['wdpa-percentage']?.visibility ? ['wdpa-percentage'] : []),
164-
...(layerSettings['features']?.visibility ? ['features'] : []),
164+
...(layerSettings['features']?.visibility || selectedFeatures?.length ? ['features'] : []),
165165
...(preHighlightFeatures?.length || postHighlightFeatures?.length ? ['features'] : []),
166166
...(selectedCostSurface ? ['cost'] : []),
167167
...(layerSettings['lock-in']?.visibility ? ['lock-in'] : []),
@@ -170,7 +170,13 @@ export const ScenariosEditMap = (): JSX.Element => {
170170
...(layerSettings['frequency']?.visibility ? ['frequency'] : []),
171171
...(layerSettings['solution']?.visibility ? ['solution'] : []),
172172
];
173-
}, [layerSettings, selectedCostSurface, preHighlightFeatures, postHighlightFeatures]);
173+
}, [
174+
layerSettings,
175+
selectedCostSurface,
176+
preHighlightFeatures,
177+
postHighlightFeatures,
178+
selectedFeatures,
179+
]);
174180

175181
const featuresIds = useMemo(() => {
176182
if (allGapAnalysisData) {

app/layout/scenarios/edit/map/legend/hooks/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export const useFeaturesLegend = () => {
185185
) || [];
186186

187187
return [
188-
...LEGEND_LAYERS['features-preview-new']({
188+
...LEGEND_LAYERS['binary-features']({
189189
items: binaryFeaturesItems,
190190
onChangeVisibility: (featureId: Feature['id']) => {
191191
const newSelectedFeatures = [...selectedFeatures];
@@ -211,7 +211,7 @@ export const useFeaturesLegend = () => {
211211
);
212212
},
213213
}),
214-
...LEGEND_LAYERS['features-abundance']({
214+
...LEGEND_LAYERS['continuous-features']({
215215
items: continuousFeaturesItems,
216216
onChangeVisibility: (featureId: Feature['id']) => {
217217
const { color, amountRange } =

0 commit comments

Comments
 (0)