2024-05-06 18:10:30 +02:00
|
|
|
import { useState } from 'react';
|
2022-02-08 12:49:51 +01:00
|
|
|
import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css';
|
|
|
|
import type { FeatureCollection } from 'geojson';
|
|
|
|
|
|
|
|
import { MapLibre } from '../shared/maplibre/MapLibre';
|
|
|
|
import { useFeatureCollection } from './hooks';
|
|
|
|
import { DrawLayer } from './components/DrawLayer';
|
|
|
|
import { CadastreLayer } from './components/CadastreLayer';
|
|
|
|
import { AddressInput } from './components/AddressInput';
|
|
|
|
import { PointInput } from './components/PointInput';
|
|
|
|
import { ImportFileInput } from './components/ImportFileInput';
|
|
|
|
import { FlashMessage } from '../shared/FlashMessage';
|
|
|
|
|
|
|
|
export default function MapEditor({
|
|
|
|
featureCollection: initialFeatureCollection,
|
|
|
|
url,
|
2024-05-06 18:10:30 +02:00
|
|
|
adresseSource,
|
2023-02-27 11:59:38 +01:00
|
|
|
options,
|
2024-04-11 11:34:06 +02:00
|
|
|
champId
|
2022-02-08 12:49:51 +01:00
|
|
|
}: {
|
|
|
|
featureCollection: FeatureCollection;
|
|
|
|
url: string;
|
2024-05-06 18:10:30 +02:00
|
|
|
adresseSource: string;
|
2022-02-08 12:49:51 +01:00
|
|
|
options: { layers: string[] };
|
2024-04-11 11:34:06 +02:00
|
|
|
champId: string;
|
2022-02-08 12:49:51 +01:00
|
|
|
}) {
|
|
|
|
const [cadastreEnabled, setCadastreEnabled] = useState(false);
|
|
|
|
|
|
|
|
const { featureCollection, error, ...actions } = useFeatureCollection(
|
|
|
|
initialFeatureCollection,
|
2022-04-07 11:41:35 +02:00
|
|
|
{ url }
|
2022-02-08 12:49:51 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{error && <FlashMessage message={error} level="alert" fixed={true} />}
|
2022-02-24 17:20:17 +01:00
|
|
|
|
|
|
|
<ImportFileInput featureCollection={featureCollection} {...actions} />
|
2023-02-27 11:59:38 +01:00
|
|
|
<AddressInput
|
2024-05-06 18:10:30 +02:00
|
|
|
source={adresseSource}
|
2024-04-11 11:34:06 +02:00
|
|
|
champId={champId}
|
2024-02-02 15:08:30 +01:00
|
|
|
featureCollection={featureCollection}
|
2023-02-27 11:59:38 +01:00
|
|
|
/>
|
2022-02-24 17:20:17 +01:00
|
|
|
|
|
|
|
<MapLibre layers={options.layers}>
|
2022-02-08 12:49:51 +01:00
|
|
|
<DrawLayer
|
|
|
|
featureCollection={featureCollection}
|
|
|
|
{...actions}
|
2022-04-07 11:41:35 +02:00
|
|
|
enabled={!cadastreEnabled}
|
2022-02-08 12:49:51 +01:00
|
|
|
/>
|
|
|
|
{options.layers.includes('cadastres') ? (
|
2024-09-20 18:22:49 +02:00
|
|
|
<CadastreLayer
|
|
|
|
featureCollection={featureCollection}
|
|
|
|
{...actions}
|
|
|
|
toggle={() => setCadastreEnabled((enabled) => !enabled)}
|
|
|
|
enabled={cadastreEnabled}
|
|
|
|
/>
|
2022-02-08 12:49:51 +01:00
|
|
|
) : null}
|
|
|
|
</MapLibre>
|
2024-02-02 15:08:30 +01:00
|
|
|
<PointInput featureCollection={featureCollection} />
|
2022-02-08 12:49:51 +01:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|