-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #664 from GeotrekCE/develop
Develop > Main / Prepa 3.8.4
- Loading branch information
Showing
17 changed files
with
172 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 30 additions & 15 deletions
45
frontend/src/components/Map/DetailsMap/SensitiveAreas.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,43 @@ | ||
import React from 'react'; | ||
import React, { useMemo } from 'react'; | ||
import { Polygon } from 'react-leaflet'; | ||
import 'leaflet/dist/leaflet.css'; | ||
import { SensitiveAreaGeometry } from 'modules/sensitiveArea/interface'; | ||
import { RawCoordinate2D } from 'modules/interface'; | ||
|
||
export type PropsType = { | ||
contents?: SensitiveAreaGeometry[]; | ||
}; | ||
|
||
export const SensitiveAreas: React.FC<PropsType> = ({ contents }) => { | ||
if (contents === undefined) { | ||
return null; | ||
} | ||
|
||
const polygons = useMemo(() => { | ||
return contents | ||
.map(({ color, geometry }) => { | ||
if (geometry.type === 'MultiPolygon') { | ||
return geometry.coordinates.flatMap(polygon => | ||
polygon.map(line => ({ | ||
positions: line.map<RawCoordinate2D>(point => [point.y, point.x]), | ||
color, | ||
})), | ||
); | ||
} | ||
return { | ||
positions: geometry.coordinates.map(line => | ||
line.map<RawCoordinate2D>(point => [point.y, point.x]), | ||
), | ||
color, | ||
}; | ||
}) | ||
.flat(); | ||
}, contents); | ||
|
||
return ( | ||
<> | ||
{contents !== undefined && | ||
contents.map(({ color, geometry }, i) => { | ||
return ( | ||
<Polygon | ||
key={`sensitiveArea${i}`} | ||
color={color} | ||
weight={3} | ||
positions={geometry.coordinates.map(line => | ||
line.map<[number, number]>(point => [point.y, point.x]), | ||
)} | ||
/> | ||
); | ||
})} | ||
{polygons.map(({ positions, color }, i) => { | ||
return <Polygon color={color} key={`sensitiveArea${i}`} positions={positions} weight={3} />; | ||
})} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.