8000 fix: coordinates by Marvine89 · Pull Request #18 · Marvine89/work-surface-state-management · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: coordinates #18

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

Merged
merged 2 commits into from
Nov 9, 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
Binary file modified public/images/screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/screenshot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/screenshot-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/shared/hooks/use-fetch-work-surfece-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { workSurfacesSelector } from '../states/selectors';
import { useFetchWorkSurfaceQuery } from '../api';
import { useEffect } from 'react';
import { setSurfaces } from '../states/work-surface.slice';
import { transformCoordinates } from '../utils';

export const useFetchWorkSurfaceStore = () => {
const dispatch = useDispatch();
const workSurfaces = useSelector(workSurfacesSelector);
const { isLoading, isError, data } = useFetchWorkSurfaceQuery();

useEffect(() => {
if (data) dispatch(setSurfaces(data));
if (data) dispatch(setSurfaces(transformCoordinates(data)));
}, [data, dispatch]);

return { isLoading, isError, data: workSurfaces };
Expand Down
1 change: 1 addition & 0 deletions src/shared/hooks/use-selected-coordinates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function useSelectedCoordinates() {
if (!polygoneMode) return setGeometryList(filteredCoords.map((coords) => coords[0]));

const geometryList = polygoneMode === 'union' ? unionHelper(filteredCoords) : intersectHelper(filteredCoords);

setGeometryList(geometryList);
dispatch(setDisplayedPolygon(geometryList));
}, [workSurfaces, removedFeature, setGeometryList, polygoneMode, dispatch]);
Expand Down
2 changes: 0 additions & 2 deletions src/shared/interfaces/work-surfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ export interface WorkSurface {

export interface SurfaceFeatureResponse {
type: string;
properties: Record<string, string>;
geometry: SurfaceGeometry;
}

export interface SurfaceFeature {
type: string;
id: number;
parentId: number;
properties: Record<string, string>;
geometry: SurfaceGeometry;
}

Expand Down
1 change: 1 addition & 0 deletions src/shared/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './filtered-coordinates';
export * from './union';
export * from './interception';
export * from './area-calculation';
export * from './transform-coordinates';
3 changes: 1 addition & 2 deletions src/shared/utils/tests/mocks/features.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const FEATURE_1_MOCK: SurfaceFeature = {
type: 'Feature 1',
id: 1,
parentId: 1,
properties: { name: 'Feature 1', description: 'Feature 1 description' },

geometry: {
type: 'Polygon',
color: 'red',
Expand All @@ -24,7 +24,6 @@ export const FEATURE_2_MOCK: SurfaceFeature = {
type: 'Feature 2',
id: 1,
parentId: 2,
properties: { name: 'Feature 2', description: 'Feature 2 description' },
geometry: {
type: 'Polygon',
color: 'red',
Expand Down
20 changes: 20 additions & 0 deletions src/shared/utils/transform-coordinates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { WorkSurface } from '../interfaces';

export function transformCoordinates(workSurfaces: WorkSurface[]): WorkSurface[] {
return workSurfaces.map((workSurface) => {
return {
...workSurface,
features: workSurface.features.map((feature) => {
return {
...feature,
geometry: {
...feature.geometry,
coordinates: feature.geometry.coordinates.map((coords) => {
return coords.map(([lng, lat]) => [lat, lng]);
}),
},
};
}),
};
});
}
0