First attempt at selected cell state display

This commit is contained in:
Tyler Hallada 2022-01-16 02:52:34 -05:00
parent 79015201b0
commit 576eb5b583
2 changed files with 21 additions and 2 deletions

View File

@ -192,6 +192,7 @@ const Map: React.FC = () => {
];
grid.features.push({
type: "Feature",
id: x * 100 + y,
geometry: {
type: "Polygon",
coordinates: [
@ -228,8 +229,18 @@ const Map: React.FC = () => {
source: "grid-source",
paint: {
"fill-color": ["get", "color"],
"fill-opacity": 0.25,
"fill-outline-color": "transparent",
"fill-opacity": [
"case",
["boolean", ["feature-state", "selected"], false],
0.5,
0.25,
],
"fill-outline-color": [
"case",
["boolean", ["feature-state", "selected"], false],
"white",
"transparent",
]
},
},
"grid-labels-layer"
@ -242,6 +253,13 @@ const Map: React.FC = () => {
map.current.on("click", "grid-layer", (e) => {
if (e.features && e.features[0]) {
const cell: [number, number] = [e.features[0].properties!.cellX, e.features[0].properties!.cellY];
map.current.removeFeatureState({ source: "grid-source" });
map.current.setFeatureState({
source: "grid-source",
id: e.features[0].id,
}, {
selected: true
});
setSelectedCell(cell);
map.current.resize();
}

View File

@ -11,6 +11,7 @@ type Props = {
const Sidebar: React.FC<Props> = ({ selectedCell, setSelectedCell, map }) => {
const onClose = () => {
setSelectedCell(null);
if (map.current) map.current.removeFeatureState({ source: "grid-source" });
requestAnimationFrame(() => { if (map.current) map.current.resize() });
}