Skip to content

Commit

Permalink
feat (HomePage): cluster layer added in project list map
Browse files Browse the repository at this point in the history
  • Loading branch information
NSUWAL123 committed Oct 10, 2023
1 parent a04dc8c commit 66261ea
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 16 deletions.
67 changes: 51 additions & 16 deletions src/frontend/src/components/home/ProjectListMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { useOLMap } from '../MapComponent/OpenLayersComponent';
import { MapContainer as MapComponent } from '../MapComponent/OpenLayersComponent';
import LayerSwitcherControl from '../MapComponent/OpenLayersComponent/LayerSwitcher/index.js';
import { VectorLayer } from '../MapComponent/OpenLayersComponent/Layers';
import { ClusterLayer } from '../MapComponent/OpenLayersComponent/Layers';
import CoreModules from '../../shared/CoreModules';
import { geojsonObjectModel } from '../../constants/geojsonObjectModal';
import { defaultStyles, getStyles } from '../MapComponent/OpenLayersComponent/helpers/styleUtils';
import MarkerIcon from '../../assets/images/red_marker.png';
import { useNavigate } from 'react-router-dom';
import environment from '../../environment';
import { Style, Text, Icon, Fill } from 'ol/style';

type HomeProjectSummaryType = {
features: { geometry: any; properties: any; type: any }[];
Expand All @@ -21,20 +23,39 @@ type HomeProjectSummaryType = {
};
};

const projectGeojsonLayerStyle = {
...defaultStyles,
fillOpacity: 0,
lineColor: '#ffffff',
labelFontSize: 20,
lineThickness: 7,
lineOpacity: 40,
showLabel: true,
labelField: 'project_id',
labelOffsetY: 35,
labelFontWeight: 'bold',
labelMaxResolution: 10000,
icon: { scale: [0.09, 0.09], url: MarkerIcon },
// const projectGeojsonLayerStyle = {
// ...defaultStyles,
// fillOpacity: 0,
// lineColor: '#ffffff',
// labelFontSize: 20,
// lineThickness: 7,
// lineOpacity: 40,
// showLabel: true,
// labelField: 'project_id',
// labelOffsetY: 35,
// labelFontWeight: 'bold',
// labelMaxResolution: 10000,
// icon: { scale: [0.09, 0.09], url: MarkerIcon },
// };

const getIndividualStyle = (featureProperty) => {
const style = new Style({
image: new Icon({
src: MarkerIcon,
scale: 0.08,
}),
text: new Text({
text: featureProperty?.project_id,
fill: new Fill({
color: 'black',
}),
offsetY: 35,
font: '20px Times New Roman',
}),
});
return style;
};

const ProjectListMap = () => {
const navigate = useNavigate();

Expand Down Expand Up @@ -67,7 +88,6 @@ const ProjectListMap = () => {
}, [homeProjectSummary]);

const projectClickOnMap = (properties: any) => {
console.log(properties);
const encodedProjectId = environment.encode(properties.id);
navigate(`/project_details/${encodedProjectId}`);
};
Expand All @@ -85,7 +105,7 @@ const ProjectListMap = () => {
}}
>
<LayerSwitcherControl visible={'outdoors'} />
{projectGeojson && projectGeojson?.features?.length > 0 && (
{/* {projectGeojson && projectGeojson?.features?.length > 0 && (
<VectorLayer
geojson={projectGeojson}
style={projectGeojsonLayerStyle}
Expand Down Expand Up @@ -123,8 +143,23 @@ const ProjectListMap = () => {
// // selectedFeature.setStyle();
// }}
/>
)} */}
{projectGeojson && projectGeojson?.features?.length > 0 && (
<ClusterLayer
map={map}
source={projectGeojson}
zIndex={100}
visibleOnMap={true}
style={{
...defaultStyles,
background_color: '#D73F37',
color: '#eb9f9f',
opacity: 90,
}}
mapOnClick={projectClickOnMap}
getIndividualStyle={getIndividualStyle}
/>
)}
{/* )} */}
</MapComponent>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/types/modulesDecleration.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
declare module '@testing-library/react';
declare module '*.png';
declare module 'ol/style';

0 comments on commit 66261ea

Please sign in to comment.