Skip to content

Commit

Permalink
Merge pull request #1513 from Vizzuality/MRXN23-458-fe-implementation-of
Browse files Browse the repository at this point in the history
[MRXN23-435]: abundance feature layer
  • Loading branch information
andresgnlez authored Oct 27, 2023
2 parents 88f9c4a + e9a0cf8 commit 0ba7e0a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
6 changes: 3 additions & 3 deletions app/hooks/map/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export const LEGEND_LAYERS = {
}));
},

'features-preview-new': (options: {
'binary-features': (options: {
items: { id: string; name: string; color: string }[];
onChangeVisibility: (featureId: Feature['id']) => void;
}) => {
Expand Down Expand Up @@ -314,7 +314,7 @@ export const LEGEND_LAYERS = {
},
}),
// ANALYSIS
['features-abundance']: (options: {
['continuous-features']: (options: {
items: {
id: Feature['id'];
amountRange: { min: number; max: number };
Expand All @@ -326,7 +326,7 @@ export const LEGEND_LAYERS = {
const { items, onChangeVisibility } = options;

return items?.map(({ id, name, amountRange, color }) => ({
id: `feature-abundance-${id}`,
id,
name,
type: 'gradient' as LegendItemType,
settingsManager: {
Expand Down
8 changes: 4 additions & 4 deletions app/hooks/map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,8 @@ export function usePUGridLayer({
const {
visibility = true,
opacity = 1,
amountRange = { min: 50000, max: 1000000 },
amountRange,
color,
} = restLayerSettings[featureId] || {};

return {
Expand Down Expand Up @@ -804,10 +805,9 @@ export function usePUGridLayer({
['linear'],
['var', 'amount'],
amountRange.min,
'white', // ! use COLORS.abundance.default instead when is available
COLORS.abundance.default,
amountRange.max,
'green',
// color, // ! enable the color variable when we receive it
color,
],
],
'fill-opacity': opacity,
Expand Down
1 change: 1 addition & 0 deletions app/hooks/map/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export interface UsePUGridLayer {
min: number;
max: number;
};
color?: string;
};
};
};
Expand Down
1 change: 1 addition & 0 deletions app/layout/projects/show/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const ProjectMap = (): JSX.Element => {
sublayers: [
...(sid1 && !sid2 ? ['frequency'] : []),
...(!!selectedCostSurface ? ['cost'] : []),
...(!!selectedFeaturesIds.length ? ['features'] : []),
],
options: {
cost: { min: 1, max: 100 },
Expand Down
11 changes: 7 additions & 4 deletions app/layout/projects/show/map/legend/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,14 @@ export const useFeaturesLegend = () => {
select: ({ data }) => ({
binaryFeatures:
data?.filter(
(feature) => !Object.hasOwn(feature, 'min') && !Object.hasOwn(feature, 'max')
(feature) =>
!Object.hasOwn(feature.amountRange, 'min') &&
!Object.hasOwn(feature.amountRange, 'max')
) || [],
continuousFeatures:
data?.filter(
(feature) => Object.hasOwn(feature, 'min') && Object.hasOwn(feature, 'max')
(feature) =>
Object.hasOwn(feature.amountRange, 'min') && Object.hasOwn(feature.amountRange, 'max')
) || [],
}),
}
Expand Down Expand Up @@ -175,7 +178,7 @@ export const useFeaturesLegend = () => {
) || [];

return [
...LEGEND_LAYERS['features-preview-new']({
...LEGEND_LAYERS['binary-features']({
items: binaryFeaturesItems,
onChangeVisibility: (featureId: Feature['id']) => {
const newSelectedFeatures = [...selectedFeatures];
Expand All @@ -201,7 +204,7 @@ export const useFeaturesLegend = () => {
);
},
}),
...LEGEND_LAYERS['features-abundance']({
...LEGEND_LAYERS['continuous-features']({
items: continuousFeaturesItems,
onChangeVisibility: (featureId: Feature['id']) => {
const { color, amountRange } =
Expand Down
10 changes: 8 additions & 2 deletions app/layout/scenarios/edit/map/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const ScenariosEditMap = (): JSX.Element => {
const sublayers = useMemo(() => {
return [
...(layerSettings['wdpa-percentage']?.visibility ? ['wdpa-percentage'] : []),
...(layerSettings['features']?.visibility ? ['features'] : []),
...(layerSettings['features']?.visibility || selectedFeatures?.length ? ['features'] : []),
...(preHighlightFeatures?.length || postHighlightFeatures?.length ? ['features'] : []),
...(selectedCostSurface ? ['cost'] : []),
...(layerSettings['lock-in']?.visibility ? ['lock-in'] : []),
Expand All @@ -170,7 +170,13 @@ export const ScenariosEditMap = (): JSX.Element => {
...(layerSettings['frequency']?.visibility ? ['frequency'] : []),
...(layerSettings['solution']?.visibility ? ['solution'] : []),
];
}, [layerSettings, selectedCostSurface, preHighlightFeatures, postHighlightFeatures]);
}, [
layerSettings,
selectedCostSurface,
preHighlightFeatures,
postHighlightFeatures,
selectedFeatures,
]);

const featuresIds = useMemo(() => {
if (allGapAnalysisData) {
Expand Down
4 changes: 2 additions & 2 deletions app/layout/scenarios/edit/map/legend/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const useFeaturesLegend = () => {
) || [];

return [
...LEGEND_LAYERS['features-preview-new']({
...LEGEND_LAYERS['binary-features']({
items: binaryFeaturesItems,
onChangeVisibility: (featureId: Feature['id']) => {
const newSelectedFeatures = [...selectedFeatures];
Expand All @@ -211,7 +211,7 @@ export const useFeaturesLegend = () => {
);
},
}),
...LEGEND_LAYERS['features-abundance']({
...LEGEND_LAYERS['continuous-features']({
items: continuousFeaturesItems,
onChangeVisibility: (featureId: Feature['id']) => {
const { color, amountRange } =
Expand Down

1 comment on commit 0ba7e0a

@vercel
Copy link

@vercel vercel bot commented on 0ba7e0a Oct 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

marxan – ./

marxan-git-develop-vizzuality1.vercel.app
marxan-vizzuality1.vercel.app
marxan23.vercel.app

Please sign in to comment.