import React, { useState } from 'react'; import PropTypes from 'prop-types'; import ReactMapboxGl, { ZoomControl } from 'react-mapbox-gl'; import DrawControl from 'react-mapbox-gl-draw'; import { CursorClickIcon, PlusIcon, LocationMarkerIcon } from '@heroicons/react/outline'; import CoordinateInput from 'react-coordinate-input'; import { fire } from '@utils'; import VisuallyHidden from '@reach/visually-hidden'; import { useId } from '@reach/auto-id'; import 'mapbox-gl/dist/mapbox-gl.css'; import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css'; import MapStyleControl, { useMapStyle } from '../shared/mapbox/MapStyleControl'; import { FlashMessage } from '../shared/FlashMessage'; import ComboAdresseSearch from '../ComboAdresseSearch'; import { useMapboxEditor } from './useMapboxEditor'; const Mapbox = ReactMapboxGl({}); function MapEditor({ featureCollection, url, options, preview }) { const [cadastreEnabled, setCadastreEnabled] = useState(false); const [coords, setCoords] = useState([1.7, 46.9]); const [zoom, setZoom] = useState([5]); const { isSupported, error, inputs, onLoad, onStyleChange, onFileChange, drawRef, createFeatures, updateFeatures, deleteFeatures, addInputFile, removeInputFile } = useMapboxEditor(featureCollection, { url, enabled: !preview, cadastreEnabled }); const { style, layers, setStyle, setLayerEnabled, setLayerOpacity } = useMapStyle(options.layers, { onStyleChange, cadastreEnabled }); if (!isSupported) { return (

Nous ne pouvons pas afficher notre éditeur de carte car il est imcompatible avec votre navigateur. Nous vous conseillons de le mettre à jour ou utiliser les dernières versions de Chrome, Firefox ou Safari

); } return ( <> {error && }

Besoin d'aide ?  consulter les tutoriels video

{inputs.map((input) => (
onFileChange(e, input.id)} /> {input.hasValue && ( removeInputFile(e, input.id)} > )}
))}
{ setCoords(coordinates); setZoom([17]); }} />
onLoad(map)} center={coords} zoom={zoom} style={style} containerStyle={{ height: '500px' }} > {!cadastreEnabled && ( )} {options.layers.includes('cadastres') && (
)}
); } function PointInput() { const inputId = useId(); const [value, setValue] = useState(''); const [feature, setFeature] = useState(null); const getCurrentPosition = () => { navigator.geolocation && navigator.geolocation.getCurrentPosition(({ coords }) => { setValue( `${coords.latitude.toPrecision(6)}, ${coords.longitude.toPrecision( 6 )}` ); }); }; const addPoint = () => { if (feature) { fire(document, 'map:feature:create', feature); setValue(''); setFeature(null); } }; return ( <>
{navigator.geolocation ? ( ) : null} { setValue(value); setFeature( dd.length ? { type: 'Feature', geometry: { type: 'Point', coordinates: dd.reverse() }, properties: {} } : null ); }} />
); } MapEditor.propTypes = { featureCollection: PropTypes.shape({ bbox: PropTypes.array, features: PropTypes.array }), url: PropTypes.string, preview: PropTypes.bool, options: PropTypes.shape({ layers: PropTypes.array }) }; export default MapEditor;