From a6fc4b6aa450a3b3c91ffbbae646152ea3cd944b Mon Sep 17 00:00:00 2001 From: robinvandermolen Date: Wed, 18 Dec 2024 14:32:33 +0100 Subject: [PATCH] :sparkles: [open-formulieren/open-forms#2177] Add map component interaction to preview --- src/registry/map/preview.tsx | 38 ++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/registry/map/preview.tsx b/src/registry/map/preview.tsx index b52dbe9..58eea53 100644 --- a/src/registry/map/preview.tsx +++ b/src/registry/map/preview.tsx @@ -1,14 +1,17 @@ import {CRS_RD, TILE_LAYER_RD} from '@open-formulieren/leaflet-tools'; import {MapComponentSchema} from '@open-formulieren/types'; -import {useContext, useLayoutEffect} from 'react'; -import {MapContainer, TileLayer, useMap} from 'react-leaflet'; +import type {FeatureGroup as LeafletFeatureGroup} from 'leaflet'; +import 'leaflet-draw/dist/leaflet.draw.css'; +import 'leaflet/dist/leaflet.css'; +import {useContext, useLayoutEffect, useRef} from 'react'; +import {FeatureGroup, MapContainer, TileLayer, useMap} from 'react-leaflet'; +import {EditControl} from 'react-leaflet-draw'; import useAsync from 'react-use/esm/useAsync'; import Loader from '@/components/builder/loader'; import {Component, Description} from '@/components/formio'; import {BuilderContext} from '@/context'; - -import {ComponentPreviewProps} from '../types'; +import {ComponentPreviewProps} from '@/registry/types'; interface MapViewProps { lat: number; @@ -41,8 +44,10 @@ const Preview: React.FC> = ({component defaultZoom, initialCenter = {}, tileLayerIdentifier, + interactions, } = component; const {getMapTileLayers} = useContext(BuilderContext); + const featureGroupRef = useRef(null); const {value: tileLayers, loading, error} = useAsync(async () => await getMapTileLayers(), []); if (error) { throw error; @@ -63,6 +68,13 @@ const Preview: React.FC> = ({component TILE_LAYER_RD.url ); }; + + const onFeatureCreate = (event: any) => { + console.log(featureGroupRef); + featureGroupRef.current?.clearLayers(); + featureGroupRef.current?.addLayer(event.layer); + }; + return ( > = ({component }} > + + + {description && }