From a96ebaa77c64df84902dd80eae6c6aa00e236c32 Mon Sep 17 00:00:00 2001 From: Nishit Suwal <81785002+NSUWAL123@users.noreply.github.com> Date: Fri, 20 Oct 2023 12:19:04 +0545 Subject: [PATCH] Feat project details map component (#926) * feat (projectDetails): map - for small screen, full screen map visible(only map visible) * feat (projectDetails): map - footer added to the map * fix (MobileFooter) - border top added * feat (bottomSheet): bottomSheet component made for mobile device * feat (projectDetails): activities - bottomSheet made for activities * feat (projectDetails): project info - added bottom sheet for project information for small screen * feat (projectDetails) - fmtm logo and back button added for small screen * fix (Accordion): interface added to props * feat/fix (projectDetails): projectDetails component projectOption section splitted to projectOption component. projectOptions added for others bottomSheet * fix (projectDetails): bottomSheet - converted css to tailwind css, converted dom manipulation to react states * fix (projectDetails): map - mapcontrols button gap reduced for small screens * fix (bottomSheet): fmtm logo move bottom sheet expand/contract * fix (projectDetails): margins/paddings updated for mobile view * feat(icons): added new icon * fix (console): console logs removed * fix (project details): displaying map using map component * fix (project details): MapControl - component to display map controls * fix (projectDetails): UI updated for new project details map * fix (newProjectDetails): map - vectorLayer added for buildings * fix (vectorLayer): map onClick returns feature as a second argument * fix (newProjectDetials): changes in creating geojson * fix (newProjectDetail): map - chloropeth and styles added * fix *(newProjectDetails): map - defaultStyles imported, naming changes * feat (newProjectDetails): map - setting layer style according to the task status * feat (vectorLayer/newProjectDetials): layerProperties props added to vectorLayer * fix (newProjectDetails): map - buildingStyles added * fix (mobileFooter/bottomSheet): zIndex adjusted * (newProjectDetails): mapLegends added for small screen * fix (accordion): border width 0 on accordion collapse * fix (mapLegend): header not shown medium & large devices * fix (newProjectDetails): mapLegend - mapLegend added to devices bigger than small * fix (newProjectDetails): mapControlComponent - hover effects added to buttons * fix (newProjectDetials): imports and states cleanup * fix (newProjectDetials): added taskBoundries length as a dependency to prevent rerendering * fix (newProjectDetails): mapLegend - default legend collapsed * fix (projectDetails): route - projectDetails route updated * fix (projectDetails): taskSectionPopup - zIndex adjusted --- .../src/components/GenerateMbTiles.jsx | 1 - .../LayerSwitcher/index.js | 29 +- .../OpenLayersComponent/Layers/VectorLayer.js | 15 +- src/frontend/src/components/MapLegends.jsx | 4 +- .../ProjectDetails/MapControlComponent.tsx | 116 +++++ .../ProjectDetails/MobileFooter.tsx | 2 +- .../ProjectDetails/TaskSectionPopup.tsx | 2 +- .../components/ProjectInfo/ProjectInfomap.jsx | 2 +- src/frontend/src/components/TasksLayer.jsx | 2 - .../src/components/common/Accordion.tsx | 2 +- .../src/components/common/BottomSheet.tsx | 2 +- src/frontend/src/routes.jsx | 15 +- src/frontend/src/shared/AssetModules.js | 2 + .../src/utilfunctions/getTaskStatusStyle.js | 108 +++++ src/frontend/src/views/NewProjectDetails.jsx | 426 ++++++++++++++++++ 15 files changed, 714 insertions(+), 14 deletions(-) create mode 100644 src/frontend/src/components/ProjectDetails/MapControlComponent.tsx create mode 100644 src/frontend/src/utilfunctions/getTaskStatusStyle.js create mode 100644 src/frontend/src/views/NewProjectDetails.jsx diff --git a/src/frontend/src/components/GenerateMbTiles.jsx b/src/frontend/src/components/GenerateMbTiles.jsx index fa3e4023a3..09060212a3 100644 --- a/src/frontend/src/components/GenerateMbTiles.jsx +++ b/src/frontend/src/components/GenerateMbTiles.jsx @@ -21,7 +21,6 @@ const GenerateMbTiles = ({ setToggleGenerateModal, toggleGenerateModal, projectI border: '1px solid ', padding: '16px 32px 24px 32px', }); - console.log(projectInfo, 'projectInfo'); const downloadMbTiles = (tileId) => { dispatch(DownloadTile(`${import.meta.env.VITE_API_URL}/projects/download_tiles/?tile_id=${tileId}`, projectInfo)); }; diff --git a/src/frontend/src/components/MapComponent/OpenLayersComponent/LayerSwitcher/index.js b/src/frontend/src/components/MapComponent/OpenLayersComponent/LayerSwitcher/index.js index dec28db24b..410a620dfb 100644 --- a/src/frontend/src/components/MapComponent/OpenLayersComponent/LayerSwitcher/index.js +++ b/src/frontend/src/components/MapComponent/OpenLayersComponent/LayerSwitcher/index.js @@ -7,8 +7,8 @@ import LayerTile from 'ol/layer/Tile'; import SourceOSM from 'ol/source/OSM'; import LayerSwitcher from 'ol-layerswitcher'; import React, { useEffect } from 'react'; - import { XYZ } from 'ol/source'; +import { useLocation } from 'react-router-dom'; // const mapboxOutdoors = new MapboxVector({ // styleUrl: 'mapbox://styles/geovation/ckpicg3of094w17nyqyd2ziie', @@ -147,6 +147,33 @@ const LayerSwitcherControl = ({ map, visible = 'osm' }) => { }; }, [map, visible]); + const location = useLocation(); + if (location.pathname.includes('project_details')) { + const olZoom = document.querySelector('.ol-zoom'); + const layerSwitcher = document.querySelector('.layer-switcher'); + + if (olZoom) { + olZoom.style.display = 'none'; + } + + if (layerSwitcher) { + layerSwitcher.style.right = '19px'; + layerSwitcher.style.top = '250px'; + layerSwitcher.style.zIndex = '1000'; + + const layerSwitcherButton = layerSwitcher.querySelector('button'); + if (layerSwitcherButton) { + layerSwitcherButton.style.width = '40px'; + layerSwitcherButton.style.height = '40px'; + } + + layerSwitcher.style.backgroundColor = 'white'; + layerSwitcher.style.display = 'flex'; + layerSwitcher.style.justifyContent = 'center'; + layerSwitcher.style.alignItems = 'center'; + } + } + return null; }; diff --git a/src/frontend/src/components/MapComponent/OpenLayersComponent/Layers/VectorLayer.js b/src/frontend/src/components/MapComponent/OpenLayersComponent/Layers/VectorLayer.js index aa6c761fd4..2bcc1bc2bd 100644 --- a/src/frontend/src/components/MapComponent/OpenLayersComponent/Layers/VectorLayer.js +++ b/src/frontend/src/components/MapComponent/OpenLayersComponent/Layers/VectorLayer.js @@ -47,6 +47,8 @@ const VectorLayer = ({ setStyle, onModify, onDraw, + getTaskStatusStyle, + layerProperties, }) => { const [vectorLayer, setVectorLayer] = useState(null); @@ -157,9 +159,8 @@ const VectorLayer = ({ // Perform an action if a feature is found if (feature) { // Do something with the feature - console.log('Clicked feature:', feature.getProperties()); // dispatch() - mapOnClick(feature.getProperties()); + mapOnClick(feature.getProperties(), feature); } }); setVectorLayer(vectorLyr); @@ -183,6 +184,11 @@ const VectorLayer = ({ vectorLayer.setStyle(setStyle); }, [map, setStyle, vectorLayer, visibleOnMap]); + useEffect(() => { + if (!map || !vectorLayer || !getTaskStatusStyle) return; + vectorLayer.setStyle((feature) => getTaskStatusStyle(feature)); + }, [map, vectorLayer, getTaskStatusStyle]); + useEffect(() => { if (!vectorLayer || !style.visibleOnMap) return; vectorLayer.setStyle((feature, resolution) => getStyles({ style, feature, resolution })); @@ -209,6 +215,11 @@ const VectorLayer = ({ }); }, [vectorLayer, properties]); + useEffect(() => { + if (!map || !vectorLayer || !layerProperties) return; + vectorLayer.setProperties(layerProperties); + }, [map, vectorLayer, layerProperties]); + // style on hover useEffect(() => { if (!map) return null; diff --git a/src/frontend/src/components/MapLegends.jsx b/src/frontend/src/components/MapLegends.jsx index 8da0e8c7f1..9361c9afa4 100755 --- a/src/frontend/src/components/MapLegends.jsx +++ b/src/frontend/src/components/MapLegends.jsx @@ -89,8 +89,8 @@ const MapLegends = ({ direction, spacing, iconBtnProps, defaultTheme, valueStatu // ); // })} // -
Map Legend
Legend
+