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

Distinguish create project layer #1936

Merged
merged 10 commits into from
Dec 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ const LayerSwitcherControl = ({ map, visible = 'osm', pmTileLayerUrl = null }) =
location.pathname.includes('upload-area') ||
location.pathname.includes('upload-survey') ||
location.pathname.includes('map-features') ||
location.pathname.includes('split-tasks')
location.pathname.includes('split-tasks') ||
location.pathname.includes('project-submissions')
) {
const olZoom = document.querySelector('.ol-zoom');
if (olZoom) {
Expand Down
63 changes: 63 additions & 0 deletions src/frontend/src/components/SubmissionMap/MapControlComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react';
import AssetModules from '@/shared/AssetModules';
import VectorLayer from 'ol/layer/Vector';
import * as olExtent from 'ol/extent';

const MapControlComponent = ({ map }) => {
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: 'Zoom To Layer',
icon: <AssetModules.CropFreeIcon style={{ fontSize: '20px' }} className="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 === 'Zoom To Layer') {
const extent = olExtent.createEmpty();
const layers = map?.getLayers();

layers?.forEach((layer) => {
if (layer instanceof VectorLayer) {
olExtent.extend(extent, layer.getSource().getExtent());
}
});
map?.getView()?.fit(extent, {
padding: [50, 50, 50, 50],
duration: 900,
});
}
};

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}>
<div
className={`fmtm-p-1 fmtm-rounded-md fmtm-duration-200 fmtm-cursor-pointer hover:fmtm-bg-red-50`}
onClick={() => handleOnClick(btn.id)}
>
{btn.icon}
</div>
</div>
);
})}
</div>
);
};

export default MapControlComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Stroke } from 'ol/style';
import { hexToRgba } from '@/components/MapComponent/OpenLayersComponent/helpers/styleUtils';
import { Fill } from 'ol/style';
import { geojsonType } from '@/store/types/ISubmissions';
import MapControlComponent from '@/components/SubmissionMap/MapControlComponent';

type submissionInstanceMapPropType = {
featureGeojson: { vectorLayerGeojson: geojsonType; clusterLayerGeojson: geojsonType };
Expand Down Expand Up @@ -61,6 +62,7 @@ const SubmissionInstanceMap = ({ featureGeojson }: submissionInstanceMapPropType
<div className="fmtm-absolute fmtm-right-2 fmtm-top-2 fmtm-z-20">
<LayerSwitchMenu map={map} />
</div>
<MapControlComponent map={map} />
<LayerSwitcherControl visible={'osm'} />
{featureGeojson?.vectorLayerGeojson?.type && (
<VectorLayer
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/src/views/NewDefineAreaMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { VectorLayer } from '@/components/MapComponent/OpenLayersComponent/Layer
import { DrawnGeojsonTypes, GeoJSONFeatureTypes } from '@/store/types/ICreateProject';
import MapControlComponent from '@/components/createnewproject/MapControlComponent';
import LayerSwitchMenu from '@/components/MapComponent/OpenLayersComponent/LayerSwitcher/LayerSwitchMenu';
import { defaultStyles } from '@/components/MapComponent/OpenLayersComponent/helpers/styleUtils';

type NewDefineAreaMapProps = {
drawToggle?: boolean;
Expand Down Expand Up @@ -65,6 +66,7 @@ const NewDefineAreaMap = ({
duration: 500,
}}
onModify={onModify}
style={{ ...defaultStyles, lineColor: '#0fffff', lineThickness: 2, fillOpacity: 10, fillColor: '#000000' }}
/>
)}
{isDrawOrGeojsonFile && !splittedGeojson && (
Expand All @@ -80,6 +82,7 @@ const NewDefineAreaMap = ({
onModify={onModify}
zoomToLayer
getAOIArea={getAOIArea}
style={{ ...defaultStyles, lineColor: '#0fffff', lineThickness: 2, fillOpacity: 10, fillColor: '#000000' }}
/>
)}

Expand All @@ -93,6 +96,7 @@ const NewDefineAreaMap = ({
duration: 500,
}}
zoomToLayer
style={{ ...defaultStyles, lineColor: '#D73F37', lineThickness: 1.5, fillColor: '#D73F37' }}
/>
)}
{buildingExtractedGeojson && (
Expand All @@ -105,6 +109,7 @@ const NewDefineAreaMap = ({
duration: 500,
}}
zoomToLayer
style={{ ...defaultStyles, lineColor: '#1a2fa2', fillOpacity: 30, lineOpacity: 50 }}
/>
)}
{lineExtractedGeojson && (
Expand Down
Loading