From ecc1f2a45df4a55038dc6f1a56cbea1459055922 Mon Sep 17 00:00:00 2001 From: Nishit Suwal <81785002+NSUWAL123@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:18:15 +0545 Subject: [PATCH] feat: project info legend (#1017) * feat (projectInfo): map - legend added to map * fix (vectorLayer) - default style overriding setStyle if setStyle supplied stopped * fix (projectInfo): legend - legend header changed --- .../OpenLayersComponent/Layers/VectorLayer.js | 4 +- .../ProjectInfo/ProjectInfoMapLegend.jsx | 38 +++++++++++++++++++ .../components/ProjectInfo/ProjectInfomap.jsx | 17 ++++++++- 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/frontend/src/components/ProjectInfo/ProjectInfoMapLegend.jsx diff --git a/src/frontend/src/components/MapComponent/OpenLayersComponent/Layers/VectorLayer.js b/src/frontend/src/components/MapComponent/OpenLayersComponent/Layers/VectorLayer.js index 134debfa47..546bd7fddf 100644 --- a/src/frontend/src/components/MapComponent/OpenLayersComponent/Layers/VectorLayer.js +++ b/src/frontend/src/components/MapComponent/OpenLayersComponent/Layers/VectorLayer.js @@ -190,7 +190,7 @@ const VectorLayer = ({ }, [map, vectorLayer, getTaskStatusStyle]); useEffect(() => { - if (!vectorLayer || !style.visibleOnMap) return; + if (!vectorLayer || !style.visibleOnMap || setStyle) return; vectorLayer.setStyle((feature, resolution) => [ new Style({ image: new CircleStyle({ @@ -207,7 +207,7 @@ const VectorLayer = ({ }), getStyles({ style, feature, resolution }), ]); - }, [vectorLayer, style]); + }, [vectorLayer, style, setStyle]); useEffect(() => { if (!vectorLayer) return; diff --git a/src/frontend/src/components/ProjectInfo/ProjectInfoMapLegend.jsx b/src/frontend/src/components/ProjectInfo/ProjectInfoMapLegend.jsx new file mode 100644 index 0000000000..088f83da32 --- /dev/null +++ b/src/frontend/src/components/ProjectInfo/ProjectInfoMapLegend.jsx @@ -0,0 +1,38 @@ +import React from 'react'; + +const colorCodes = [ + { color: '#0062AC', min: 130, max: 160 }, + { color: '#4A90D9', min: 100, max: 130 }, + { color: '#7CB2E8', min: 50, max: 100 }, + { color: '#A9D2F3', min: 10, max: 50 }, + { color: '#FF4538', min: 0, max: 0 }, +]; + +const LegendListItem = ({ code }) => ( +
+
+
+ {code.min !== code.max ? ( +

+ {code.min} - {code.max} +

+ ) : ( +

{code.min}

+ )} +
+
+); + +const ProjectInfoMapLegend = () => { + return ( +
+
+ {colorCodes.map((code) => ( + + ))} +
+
+ ); +}; + +export default ProjectInfoMapLegend; diff --git a/src/frontend/src/components/ProjectInfo/ProjectInfomap.jsx b/src/frontend/src/components/ProjectInfo/ProjectInfomap.jsx index 73b08b6974..4b306a51be 100644 --- a/src/frontend/src/components/ProjectInfo/ProjectInfomap.jsx +++ b/src/frontend/src/components/ProjectInfo/ProjectInfomap.jsx @@ -13,6 +13,8 @@ import environment from '../../environment'; import { getStyles } from '../MapComponent/OpenLayersComponent/helpers/styleUtils'; import { ProjectActions } from '../../store/slices/ProjectSlice'; import { basicGeojsonTemplate } from '../../utilities/mapUtils'; +import ProjectInfoMapLegend from './ProjectInfoMapLegend'; +import Accordion from '../common/Accordion'; export const defaultStyles = { lineColor: '#000000', @@ -68,7 +70,6 @@ const colorCodes = { function colorRange(data, noOfRange) { if (data?.length === 0) return []; const actualCodes = [{ min: 0, max: 0, color: '#605f5e' }]; - console.log(data, 'data'); const maxVal = Math.max(...data?.map((d) => d.count)); const maxValue = maxVal <= noOfRange ? 10 : maxVal; // const minValue = Math.min(...data?.map((d) => d.count)) 0; @@ -114,6 +115,7 @@ const ProjectInfomap = () => { const projectBuildingGeojson = CoreModules.useAppSelector((state) => state.project.projectBuildingGeojson); const selectedTask = CoreModules.useAppSelector((state) => state.task.selectedTask); + const defaultTheme = CoreModules.useAppSelector((state) => state.theme.hotTheme); const params = CoreModules.useParams(); const encodedId = params.projectId; const decodedId = environment.decode(encodedId); @@ -272,6 +274,19 @@ const ProjectInfomap = () => { zIndex={5} /> )} +
+ } + header={ +

+ No. of Submissions +

+ } + onToggle={() => {}} + className="fmtm-py-0 !fmtm-pb-0 fmtm-rounded-lg hover:fmtm-bg-gray-50" + collapsed={true} + /> +
{buildingGeojson && }