Skip to content
New issue

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

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

Already on GitHub? # to your account

Feature/19 reviewers can switch between the cdi map and cdi raster #20

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
6 changes: 6 additions & 0 deletions frontend/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
.ant-typography {
display: block;
}
.leaflet-control,
.leaflet-pane,
.leaflet-top,
.leaflet-bottom {
z-index: 0;
}
}

body {
Expand Down
64 changes: 53 additions & 11 deletions frontend/src/components/Map/CDIMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import L from "leaflet";
import "leaflet.pattern";
import { DEFAULT_CENTER, DROUGHT_CATEGORY } from "@/static/config";
import {
DEFAULT_CENTER,
DROUGHT_CATEGORY,
FILTER_VALUE_TYPES,
} from "@/static/config";
import Map from "./Map";
import { useMap, GeoJSON } from "react-leaflet";
import {
Expand All @@ -11,7 +15,9 @@ import {
styleOptions,
} from "@/static/poly-styles";
import { useAppContext, useAppDispatch } from "@/context/AppContextProvider";
import { Flex, Spin } from "antd";
import { Card, Flex, Select, Spin } from "antd";
import { useState } from "react";
import classNames from "classnames";

const CDIGeoJSON = ({ geoData, onEachFeature, style }) => {
const map = useMap();
Expand All @@ -37,6 +43,7 @@ const CDIGeoJSON = ({ geoData, onEachFeature, style }) => {
};

const CDIMap = ({ data = [] }) => {
const [valueType, setValueType] = useState(FILTER_VALUE_TYPES[0]?.value);
const appContext = useAppContext();
const geoData = appContext?.geoData || null;
const { selectedAdms = [], isBulkAction = false, activeAdm } = appContext;
Expand Down Expand Up @@ -65,10 +72,7 @@ const CDIMap = ({ data = [] }) => {
const findAdm = data?.find(
(d) => d?.administration_id === feature?.properties?.administration_id
);
const category =
findAdm?.category === null
? findAdm?.initial_category
: findAdm?.category;
const category = findAdm?.[valueType];
const fillColor =
DROUGHT_CATEGORY?.[category]?.color || DROUGHT_CATEGORY[0].color;
const shape = new L.PatternCircle({
Expand All @@ -95,12 +99,50 @@ const CDIMap = ({ data = [] }) => {
}
};

const onSelectValueType = (value) => {
appDispatch({
type: "REFRESH_MAP_TRUE",
});
setValueType(value);
setTimeout(() => {
appDispatch({
type: "REFRESH_MAP_FALSE",
});
}, 500);
};

return (
<Map center={DEFAULT_CENTER} height={160} zoom={9} minZoom={9}>
{() => (
<CDIGeoJSON {...{ geoData, onEachFeature }} style={geoJSONStyle} />
)}
</Map>
<div className="relative bg-neutral-100">
<div className="w-1/2 xl:w-1/3 absolute top-0 right-0 z-10 p-2 space-y-4">
<Select
className="w-full"
placeholder="Select value type"
options={FILTER_VALUE_TYPES}
value={valueType}
onChange={onSelectValueType}
/>
<Card title="LEGEND">
<ul>
{DROUGHT_CATEGORY.map((category, index) => (
<li key={category.value}>
<span
className={classNames("inline-block w-4 h-4 mr-2", {
"border border-gray-400": index == 0,
})}
style={{ backgroundColor: category.color }}
></span>
{category.label}
</li>
))}
</ul>
</Card>
</div>
<Map center={DEFAULT_CENTER} height={160} zoom={9} minZoom={9}>
{() => (
<CDIGeoJSON {...{ geoData, onEachFeature }} style={geoJSONStyle} />
)}
</Map>
</div>
);
};

Expand Down
11 changes: 11 additions & 0 deletions frontend/src/static/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,14 @@ export const PUBLICATION_STATUS = [
color: "green",
},
];

export const FILTER_VALUE_TYPES = [
{
value: "category",
label: "Reviewed Values",
},
{
value: "initial_category",
label: "Raw Values",
},
];
Loading