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 details map component #926

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a54b024
feat (projectDetails): map - for small screen, full screen map visibl…
NSUWAL123 Oct 11, 2023
7f8af19
feat (projectDetails): map - footer added to the map
NSUWAL123 Oct 11, 2023
786cc4e
fix (MobileFooter) - border top added
NSUWAL123 Oct 12, 2023
651644e
feat (bottomSheet): bottomSheet component made for mobile device
NSUWAL123 Oct 12, 2023
70f1dc3
feat (projectDetails): activities - bottomSheet made for activities
NSUWAL123 Oct 12, 2023
f545429
feat (projectDetails): project info - added bottom sheet for project …
NSUWAL123 Oct 12, 2023
e8008f7
feat (projectDetails) - fmtm logo and back button added for small screen
NSUWAL123 Oct 12, 2023
3606915
fix (Accordion): interface added to props
NSUWAL123 Oct 12, 2023
bc65a24
feat/fix (projectDetails): projectDetails component projectOption sec…
NSUWAL123 Oct 12, 2023
c17cb6d
fix (projectDetails): bottomSheet - converted css to tailwind css, co…
NSUWAL123 Oct 13, 2023
807627c
fix (projectDetails): map - mapcontrols button gap reduced for small …
NSUWAL123 Oct 13, 2023
d7b59b8
fix (bottomSheet): fmtm logo move bottom sheet expand/contract
NSUWAL123 Oct 13, 2023
8c252c9
Merge branch 'development' of https://github.com/hotosm/fmtm into fix…
NSUWAL123 Oct 13, 2023
9577d4c
fix (projectDetails): margins/paddings updated for mobile view
NSUWAL123 Oct 13, 2023
6610dd9
feat(icons): added new icon
NSUWAL123 Oct 13, 2023
a070823
fix (console): console logs removed
NSUWAL123 Oct 16, 2023
6855f5e
fix (project details): displaying map using map component
NSUWAL123 Oct 16, 2023
3a20b59
fix (project details): MapControl - component to display map controls
NSUWAL123 Oct 16, 2023
d299983
fix (projectDetails): UI updated for new project details map
NSUWAL123 Oct 16, 2023
416e224
fix (newProjectDetails): map - vectorLayer added for buildings
NSUWAL123 Oct 17, 2023
0745baa
fix (vectorLayer): map onClick returns feature as a second argument
NSUWAL123 Oct 18, 2023
5e87ef7
fix (newProjectDetials): changes in creating geojson
NSUWAL123 Oct 18, 2023
4ac8b20
fix (newProjectDetail): map - chloropeth and styles added
NSUWAL123 Oct 18, 2023
a77e1cc
merge conflict resolved
NSUWAL123 Oct 18, 2023
fa307ce
fix *(newProjectDetails): map - defaultStyles imported, naming changes
NSUWAL123 Oct 18, 2023
2185666
feat (newProjectDetails): map - setting layer style according to the …
NSUWAL123 Oct 19, 2023
6ad5364
feat (vectorLayer/newProjectDetials): layerProperties props added to …
NSUWAL123 Oct 19, 2023
0c9d22f
fix (newProjectDetails): map - buildingStyles added
NSUWAL123 Oct 19, 2023
96e5f24
fix (mobileFooter/bottomSheet): zIndex adjusted
NSUWAL123 Oct 19, 2023
3cce23c
(newProjectDetails): mapLegends added for small screen
NSUWAL123 Oct 19, 2023
35f2b84
fix (accordion): border width 0 on accordion collapse
NSUWAL123 Oct 19, 2023
34f6287
fix (mapLegend): header not shown medium & large devices
NSUWAL123 Oct 19, 2023
55a3fcc
fix (newProjectDetails): mapLegend - mapLegend added to devices bigge…
NSUWAL123 Oct 19, 2023
686d868
fix (newProjectDetails): mapControlComponent - hover effects added to…
NSUWAL123 Oct 19, 2023
7c8f20a
fix (newProjectDetials): imports and states cleanup
NSUWAL123 Oct 19, 2023
bbeb137
fix (newProjectDetials): added taskBoundries length as a dependency t…
NSUWAL123 Oct 20, 2023
6d5e6af
fix (newProjectDetails): mapLegend - default legend collapsed
NSUWAL123 Oct 20, 2023
300e26a
Merge branch 'development' of https://github.com/hotosm/fmtm into fea…
NSUWAL123 Oct 20, 2023
5d9c6ed
fix (projectDetails): route - projectDetails route updated
NSUWAL123 Oct 20, 2023
9ee31e7
fix (projectDetails): taskSectionPopup - zIndex adjusted
NSUWAL123 Oct 20, 2023
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
1 change: 0 additions & 1 deletion src/frontend/src/components/GenerateMbTiles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Contributor

@varun2948 varun2948 Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a seperate dependent added onto the isolated mapcomponent @NSUWAL123 please replace this logic on other PR not this and make it pass through props instead of using it in this component. and dont use new dependncy library like react-router-dom inside any mapcomponent folder map.


// const mapboxOutdoors = new MapboxVector({
// styleUrl: 'mapbox://styles/geovation/ckpicg3of094w17nyqyd2ziie',
Expand Down Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const VectorLayer = ({
setStyle,
onModify,
onDraw,
getTaskStatusStyle,
layerProperties,
}) => {
const [vectorLayer, setVectorLayer] = useState(null);

Expand Down Expand Up @@ -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);
Expand All @@ -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 }));
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/components/MapLegends.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ const MapLegends = ({ direction, spacing, iconBtnProps, defaultTheme, valueStatu
// );
// })}
// </CoreModules.Stack>
<div>
<div className="fmtm-flex fmtm-gap-3 fmtm-border-b-[1px] fmtm-pb-2 fmtm-mb-4">
<div className="fmtm-py-0 sm:fmtm-py-3">
<div className="sm:fmtm-hidden fmtm-flex fmtm-gap-3 fmtm-border-b-[1px] fmtm-pb-2 fmtm-mb-4">
<AssetModules.LegendToggleIcon className=" fmtm-text-primaryRed" sx={{ fontSize: '35px' }} />
<p className="fmtm-text-2xl">Map Legend</p>
</div>
Expand Down
116 changes: 116 additions & 0 deletions src/frontend/src/components/ProjectDetails/MapControlComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React, { useEffect, useState } from 'react';
import AssetModules from '../../shared/AssetModules';
import { transform } from 'ol/proj';
import * as ol from 'ol';
import { Point } from 'ol/geom';
import Vector from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import { Style } from 'ol/style';
import { Icon } from 'ol/style';
import LocationImage from '../../assets/images/location.png';
import VectorLayer from 'ol/layer/Vector';

const MapControlComponent = ({ map }) => {
const btnList = [
{
id: 'add',
icon: <AssetModules.AddIcon />,
},
{
id: 'minus',
icon: <AssetModules.RemoveIcon />,
},
{
id: 'currentLocation',
icon: <AssetModules.MyLocationIcon />,
},
{
id: 'taskBoundries',
icon: <AssetModules.CropFreeIcon />,
},
];
const [toggleCurrentLoc, setToggleCurrentLoc] = useState(false);
const [currentLocLayer, setCurrentLocLayer] = useState(null);
useEffect(() => {
if (!map) return;
if (!currentLocLayer) return;
map.addLayer(currentLocLayer);
map.getView().fit(currentLocLayer.getSource().getExtent(), {
maxZoom: 18,
duration: 500,
});
return () => {
map.removeLayer(currentLocLayer);
};
}, [map, currentLocLayer]);
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 === 'currentLocation') {
setToggleCurrentLoc(!toggleCurrentLoc);
const sourceProjection = 'EPSG:4326'; // The current projection of the coordinates
const targetProjection = 'EPSG:3857'; // The desired projection
var markerStyle = new Style({
image: new Icon({
src: LocationImage, // Path to your marker icon image
anchor: [0.5, 1], // Anchor point of the marker icon (center bottom)
scale: 2, // Scale factor for the marker icon
}),
});
if ('geolocation' in navigator) {
if (!toggleCurrentLoc) {
navigator.geolocation.getCurrentPosition((position) => {
const lat = position.coords.latitude;
const lng = position.coords.longitude;
const convertedCoordinates = transform([lng, lat], sourceProjection, targetProjection);
const positionFeature = new ol.Feature(new Point(convertedCoordinates));
const positionLayer = new Vector({
source: new VectorSource({
features: [positionFeature],
}),
});
positionFeature.setStyle(markerStyle);
setCurrentLocLayer(positionLayer);
});
} else {
setCurrentLocLayer(null);
}
}
} else if (btnId === 'taskBoundries') {
const layers = map.getAllLayers();
let extent;
layers.map((layer) => {
if (layer instanceof VectorLayer) {
const layerName = layer.getProperties().name;
if (layerName === 'project-area') {
extent = layer.getSource().getExtent();
}
}
});
map.getView().fit(extent, {
padding: [10, 10, 10, 10],
});
}
};

return (
<div className="fmtm-absolute fmtm-top-[20px] fmtm-right-5 fmtm-z-[99] fmtm-flex fmtm-flex-col fmtm-gap-4">
{btnList.map((btn) => (
<div key={btn.id}>
<div
className="fmtm-bg-white fmtm-rounded-full fmtm-p-2 hover:fmtm-bg-gray-100 fmtm-cursor-pointer fmtm-duration-300"
onClick={() => handleOnClick(btn.id)}
>
{btn.icon}
</div>
</div>
))}
</div>
);
};

export default MapControlComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const MobileFooter = () => {
);
};
return (
<div className="fmtm-absolute fmtm-bottom-0 sm:fmtm-hidden fmtm-w-full fmtm-border-t-[1px]">
<div className="fmtm-absolute fmtm-bottom-0 sm:fmtm-hidden fmtm-w-full fmtm-border-t-[1px] fmtm-z-[10001]">
<div
className={`fmtm-w-full fmtm-grid fmtm-grid-cols-5 fmtm-bg-white fmtm-pb-16 fmtm-pt-2 fmtm-gap-5 fmtm-px-2`}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const TaskSectionPopup = ({ body }) => {

return (
<div
className={`fmtm-z-[3000] fmtm-duration-1000 ${
className={`fmtm-duration-1000 fmtm-z-[10002] ${
taskModalStatus
? 'fmtm-bottom-0 fmtm-right-0 md:fmtm-bottom-[calc(20vh)] fmtm-w-[100vw] md:fmtm-w-[50vw] md:fmtm-max-w-[25rem]'
: 'fmtm-top-[calc(100vh)] md:fmtm-top-[calc(50vh)] md:fmtm-left-[calc(100vw)] fmtm-w-[100vw]'
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/ProjectInfo/ProjectInfomap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const ProjectInfomap = () => {
);
}, [selectedTask]);

const taskOnSelect = (properties) => {
const taskOnSelect = (properties, feature) => {
dispatch(CoreModules.TaskActions.SetSelectedTask(properties.uid));
};

Expand Down
2 changes: 0 additions & 2 deletions src/frontend/src/components/TasksLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const TasksLayer = (map, view, feature) => {
properties: { centroid: task.bbox },
});
});
console.log(geojsonObject, 'geojsonObject');
console.log(state.projectTaskBoundries, 'projectTaskBoundries');
const vectorSource = new VectorSource({
features: new GeoJSON().readFeatures(geojsonObject, {
featureProjection: get('EPSG:3857'),
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/common/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function Accordion({
<div
className={`fmtm-flex fmtm-items-center fmtm-justify-between
fmtm-w-full fmtm-font-bold fmtm-gap-3 fmtm-cursor-pointer fmtm-text-2xl fmtm-py-2 fmtm-border-[#929DB3] ${
collapsed ? 'fmtm-border-b-[1px]' : 'fmtm-border-b-[2px]'
collapsed ? 'fmtm-border-b-[0px]' : 'fmtm-border-b-[2px]'
}`}
onClick={() => {
if (disableHeaderClickToggle) return;
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/common/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const BottomSheet = ({ body, onClose }) => {
}, [currSheetHeight]);

return (
<div className="fmtm-absolute fmtm-bottom-[200px] fmtm-bg-white sm:fmtm-hidden">
<div className="fmtm-absolute fmtm-bottom-[200px] fmtm-bg-white sm:fmtm-hidden fmtm-z-[10000]">
<div
className={`bottom-sheet fmtm-fixed fmtm-w-full fmtm-left-0 fmtm-bottom-0 fmtm-flex fmtm-items-center fmtm-flex-col fmtm-justify-end fmtm-duration-100 fmtm-ease-linear ${
!show ? 'fmtm-opacity-0 fmtm-pointer-events-none' : 'fmtm-opacity-100 fmtm-pointer-events-auto'
Expand Down
15 changes: 14 additions & 1 deletion src/frontend/src/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import CreateNewProject from './views/CreateNewProject';
import ProjectDetails from './views/ProjectDetails';
import UnderConstruction from './views/UnderConstruction';
import ErrorBoundary from './views/ErrorBoundary';
import NewProjectDetails from './views/NewProjectDetails';

// const ProjectDetails = React.lazy(() => import('./views/ProjectDetails'));
const Submissions = React.lazy(() => import('./views/Submissions'));
Expand Down Expand Up @@ -120,13 +121,25 @@ const routes = createBrowserRouter([
),
},

// {
// path: '/project_details/:id',
// element: (
// <ProtectedRoute>
// <Suspense fallback={<div>Loading...</div>}>
// <ErrorBoundary>
// <ProjectDetails />
// </ErrorBoundary>
// </Suspense>
// </ProtectedRoute>
// ),
// },
{
path: '/project_details/:id',
element: (
<ProtectedRoute>
<Suspense fallback={<div>Loading...</div>}>
<ErrorBoundary>
<ProjectDetails />
<NewProjectDetails />
</ErrorBoundary>
</Suspense>
</ProtectedRoute>
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/shared/AssetModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
Info as InfoIcon,
MoreVert as MoreVertIcon,
LocationOn as LocationOnIcon,
CropFree as CropFreeIcon,
LegendToggle as LegendToggleIcon,
} from '@mui/icons-material';
import LockPng from '../assets/images/lock.png';
Expand Down Expand Up @@ -103,5 +104,6 @@ export default {
InfoIcon,
MoreVertIcon,
LocationOnIcon,
CropFreeIcon,
LegendToggleIcon,
};
Loading
Loading