Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat project info legend #1017

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -207,7 +207,7 @@ const VectorLayer = ({
}),
getStyles({ style, feature, resolution }),
]);
}, [vectorLayer, style]);
}, [vectorLayer, style, setStyle]);

useEffect(() => {
if (!vectorLayer) return;
Expand Down
38 changes: 38 additions & 0 deletions src/frontend/src/components/ProjectInfo/ProjectInfoMapLegend.jsx
Original file line number Diff line number Diff line change
@@ -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 }) => (
<div className="fmtm-flex fmtm-items-center fmtm-gap-2">
<div style={{ backgroundColor: code.color }} className="fmtm-w-10 fmtm-h-6 fmtm-mx-2"></div>
<div>
{code.min !== code.max ? (
<p>
{code.min} - {code.max}
</p>
) : (
<p>{code.min}</p>
)}
</div>
</div>
);

const ProjectInfoMapLegend = () => {
return (
<div className="fmtm-py-3">
<div className="fmtm-flex fmtm-flex-col fmtm-gap-2 sm:fmtm-gap-4">
{colorCodes.map((code) => (
<LegendListItem key={code.color} code={code} />
))}
</div>
</div>
);
};

export default ProjectInfoMapLegend;
17 changes: 16 additions & 1 deletion src/frontend/src/components/ProjectInfo/ProjectInfomap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -272,6 +274,19 @@ const ProjectInfomap = () => {
zIndex={5}
/>
)}
<div className="fmtm-absolute fmtm-bottom-2 fmtm-left-2 sm:fmtm-bottom-5 sm:fmtm-left-5 fmtm-z-50 fmtm-rounded-lg">
<Accordion
body={<ProjectInfoMapLegend defaultTheme={defaultTheme} />}
header={
<p className="fmtm-text-lg fmtm-font-normal fmtm-my-auto fmtm-mb-[0.35rem] fmtm-ml-2">
No. of Submissions
</p>
}
onToggle={() => {}}
className="fmtm-py-0 !fmtm-pb-0 fmtm-rounded-lg hover:fmtm-bg-gray-50"
collapsed={true}
/>
</div>
{buildingGeojson && <VectorLayer key={buildingGeojson} geojson={buildingGeojson} zIndex={15} />}
</MapComponent>
</CoreModules.Box>
Expand Down