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

Add AOI editing to map during project creation #1135

Merged
merged 5 commits into from
Jan 25, 2024
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 @@ -161,12 +161,18 @@ const LayerSwitcherControl = ({ map, visible = 'osm' }) => {
layerSwitcher.style.justifyContent = 'center';
layerSwitcher.style.alignItems = 'center';
}
if (location.pathname.includes('project_details')) {
if (
location.pathname.includes('project_details') ||
location.pathname.includes('upload-area') ||
location.pathname.includes('select-form') ||
location.pathname.includes('data-extract') ||
location.pathname.includes('split-tasks')
) {
const olZoom = document.querySelector('.ol-zoom');
if (olZoom) {
olZoom.style.display = 'none';
}
if (layerSwitcher) {
if (layerSwitcher && location.pathname.includes('project_details')) {
layerSwitcher.style.right = '19px';
layerSwitcher.style.top = '250px';
layerSwitcher.style.zIndex = '1000';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ const VectorLayer = ({
map.addInteraction(select);

return () => {
// map.removeInteraction(defaultInteractions().extend([select, modify]))
// map.removeInteraction(defaultInteractions().extend([select, modify]));
map.removeInteraction(modify);
map.removeInteraction(select);
};
}, [map, vectorLayer, onModify]);

Expand Down Expand Up @@ -213,7 +215,7 @@ const VectorLayer = ({
]
: [getStyles({ style, feature, resolution })];
});
}, [vectorLayer, style, setStyle]);
}, [vectorLayer, style, setStyle, onModify]);

useEffect(() => {
if (!vectorLayer) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React, { useState } from 'react';
import AssetModules from '../../shared/AssetModules';
import VectorLayer from 'ol/layer/Vector';
import CoreModules from '../../shared/CoreModules.js';
import { CreateProjectActions } from '../../store/slices/CreateProjectSlice';

const MapControlComponent = ({ map, hasEditUndo }) => {
const dispatch = CoreModules.useAppDispatch();
const toggleSplittedGeojsonEdit = CoreModules.useAppSelector(
(state) => state.createproject.toggleSplittedGeojsonEdit,
);
const btnList = [
{
id: 'Add',
icon: <AssetModules.AddIcon style={{ fontSize: '20px' }} className="fmtm-text-[#666666]" />,
},
{
id: 'Minus',
icon: <AssetModules.RemoveIcon style={{ fontSize: '20px' }} className="fmtm-text-[#666666]" />,
},
{
id: 'Edit',
icon: (
<AssetModules.TimelineIcon
style={{ fontSize: '20px' }}
className={`${toggleSplittedGeojsonEdit ? 'fmtm-text-primaryRed' : 'fmtm-text-[#666666]'}`}
/>
),
},
];

const handleOnClick = (btnId) => {
if (btnId === 'Add') {
const actualZoom = map.getView().getZoom();
map.getView().setZoom(actualZoom + 1);
} else if (btnId === 'Minus') {
const actualZoom = map.getView().getZoom();
map.getView().setZoom(actualZoom - 1);
} else if (btnId === 'Edit') {
dispatch(CreateProjectActions.SetToggleSplittedGeojsonEdit(!toggleSplittedGeojsonEdit));
}
};

return (
<div className="fmtm-absolute fmtm-top-[20px] fmtm-left-3 fmtm-z-50 fmtm-bg-white fmtm-rounded-md fmtm-p-[2px] fmtm-shadow-xl fmtm-flex fmtm-flex-col fmtm-gap-[2px]">
{btnList.map((btn) => {
return (
<div key={btn.id} title={btn.id}>
{((btn.id !== 'Edit' && btn.id !== 'Undo') || (btn.id === 'Edit' && hasEditUndo)) && (
<div
className={` fmtm-p-1 fmtm-rounded-md fmtm-duration-200 fmtm-cursor-pointer ${
toggleSplittedGeojsonEdit && btn.id === 'Edit'
? 'fmtm-bg-red-50'
: 'fmtm-bg-white hover:fmtm-bg-gray-100'
}`}
onClick={() => handleOnClick(btn.id)}
>
{btn.icon}
</div>
)}
</div>
);
})}
</div>
);
};

export default MapControlComponent;
19 changes: 14 additions & 5 deletions src/frontend/src/components/createnewproject/SplitTasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customLineUpload, custo
);
const isTasksGenerated = CoreModules.useAppSelector((state) => state.createproject.isTasksGenerated);
const isFgbFetching = CoreModules.useAppSelector((state) => state.createproject.isFgbFetching);
const toggleSplittedGeojsonEdit = CoreModules.useAppSelector(
(state) => state.createproject.toggleSplittedGeojsonEdit,
);

const toggleStep = (step, url) => {
dispatch(CommonActions.SetCurrentStepFormStep({ flag: flag, step: step }));
Expand Down Expand Up @@ -427,11 +430,17 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customLineUpload, custo
splittedGeojson={dividedTaskGeojson}
uploadedOrDrawnGeojsonFile={drawnGeojson}
buildingExtractedGeojson={dataExtractGeojson}
onModify={(geojson) => {
handleCustomChange('drawnGeojson', geojson);
dispatch(CreateProjectActions.SetDividedTaskGeojson(JSON.parse(geojson)));
setGeojsonFile(null);
}}
onModify={
toggleSplittedGeojsonEdit
? (geojson) => {
handleCustomChange('drawnGeojson', geojson);
dispatch(CreateProjectActions.SetDividedTaskGeojson(JSON.parse(geojson)));
setGeojsonFile(null);
}
: null
}
// toggleSplittedGeojsonEdit
hasEditUndo
/>
</div>
{generateProjectLog ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function DataExtractValidation(values: ProjectValues) {
errors.customPolygonUpload = 'A GeoJSON file is required.';
}

console.log(errors);
return errors;
}

Expand Down
1 change: 0 additions & 1 deletion src/frontend/src/hooks/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { unstable_useBlocker as useBlocker } from 'react-router-dom';
function Prompt(props) {
const block = props.when;
useBlocker(({ nextLocation }) => {
console.log(nextLocation, 'next');
if (block && !pathNotToBlock.includes(nextLocation.pathname)) {
return !window.confirm(props.message);
}
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/shared/AssetModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import {
AccessTime as AccessTimeIcon,
ImportExport as ImportExportIcon,
Check as CheckIcon,
Undo as UndoIcon,
Timeline as TimelineIcon,
} from '@mui/icons-material';
import LockPng from '../assets/images/lock.png';
import RedLockPng from '../assets/images/red-lock.png';
Expand Down Expand Up @@ -122,4 +124,6 @@ export default {
AccessTimeIcon,
ImportExportIcon,
CheckIcon,
UndoIcon,
TimelineIcon,
};
4 changes: 4 additions & 0 deletions src/frontend/src/store/slices/CreateProjectSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const initialState: CreateProjectStateTypes = {
canSwitchCreateProjectSteps: false,
isTasksGenerated: { divide_on_square: false, task_splitting_algorithm: false },
isFgbFetching: false,
toggleSplittedGeojsonEdit: false,
};

const CreateProject = createSlice({
Expand Down Expand Up @@ -225,6 +226,9 @@ const CreateProject = createSlice({
state.dataExtractGeojson = null;
state.projectDetails = { ...action.payload, customLineUpload: null, customPolygonUpload: null };
},
SetToggleSplittedGeojsonEdit(state, action) {
state.toggleSplittedGeojsonEdit = action.payload;
},
},
});

Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/store/types/ICreateProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type CreateProjectStateTypes = {
canSwitchCreateProjectSteps: boolean;
isTasksGenerated: {};
isFgbFetching: boolean;
toggleSplittedGeojsonEdit: boolean;
};
export type ValidateCustomFormResponse = {
detail: { message: string; possible_reason: string };
Expand Down
6 changes: 5 additions & 1 deletion src/frontend/src/views/NewDefineAreaMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MapContainer as MapComponent } from '../components/MapComponent/OpenLay
import LayerSwitcherControl from '../components/MapComponent/OpenLayersComponent/LayerSwitcher/index.js';
import { VectorLayer } from '../components/MapComponent/OpenLayersComponent/Layers';
import { GeoJSONFeatureTypes } from '../store/types/ICreateProject';
import MapControlComponent from '../components/createnewproject/MapControlComponent';

type NewDefineAreaMapProps = {
drawToggle?: boolean;
Expand All @@ -12,7 +13,8 @@ type NewDefineAreaMapProps = {
buildingExtractedGeojson?: GeoJSONFeatureTypes;
lineExtractedGeojson?: GeoJSONFeatureTypes;
onDraw?: (geojson: any, area: number) => void;
onModify?: (geojson: any, area?: number) => void;
onModify?: ((geojson: any, area?: number) => void) | null;
hasEditUndo?: boolean;
};
const NewDefineAreaMap = ({
drawToggle,
Expand All @@ -22,6 +24,7 @@ const NewDefineAreaMap = ({
lineExtractedGeojson,
onDraw,
onModify,
hasEditUndo,
}: NewDefineAreaMapProps) => {
const { mapRef, map } = useOLMap({
// center: fromLonLat([85.3, 27.7]),
Expand All @@ -43,6 +46,7 @@ const NewDefineAreaMap = ({
}}
>
<LayerSwitcherControl />
<MapControlComponent map={map} hasEditUndo={hasEditUndo} />
{splittedGeojson && (
<VectorLayer
geojson={splittedGeojson}
Expand Down