From 6ab6748be7a7ac85108c79cf594964c6d0d422a3 Mon Sep 17 00:00:00 2001 From: Fritz Hoeing Date: Tue, 5 Sep 2023 14:11:10 +0200 Subject: [PATCH] feat: attribution drawer --- .../ToolMenu/Draw/Attributions/index.less | 5 ++ .../ToolMenu/Draw/Attributions/index.tsx | 50 +++++++++++-------- src/i18n/translations.ts | 12 +++++ 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/components/ToolMenu/Draw/Attributions/index.less b/src/components/ToolMenu/Draw/Attributions/index.less index 68f9b76d6..58d4b3186 100644 --- a/src/components/ToolMenu/Draw/Attributions/index.less +++ b/src/components/ToolMenu/Draw/Attributions/index.less @@ -3,5 +3,10 @@ top: var(--headerHeight); bottom: var(--footerHeight); z-index: 499; + + .anticon.anticon-minus-circle { + padding-bottom: 25px; + padding-left: 5px; + } } diff --git a/src/components/ToolMenu/Draw/Attributions/index.tsx b/src/components/ToolMenu/Draw/Attributions/index.tsx index 12958e046..363c71ec0 100644 --- a/src/components/ToolMenu/Draw/Attributions/index.tsx +++ b/src/components/ToolMenu/Draw/Attributions/index.tsx @@ -11,12 +11,15 @@ import { import _cloneDeep from 'lodash/cloneDeep'; import OlFeature from 'ol/Feature'; +import { useTranslation } from 'react-i18next'; + import { useMap } from '@terrestris/react-geo/dist/Hook/useMap'; import './index.less'; import AttributionRow from './AttributionRow'; +import Geometry from 'ol/geom/Geometry'; export type AttributionDrawerProps = { openAttributeDrawer: boolean; @@ -30,7 +33,6 @@ const AttributionDrawer: React.FC = ({ const [selectedFeature, setSelectedFeature] = useState(); const [render, setRender] = useState(true); const [isFormValid, setIsFormIsValid] = useState(true); - const [fields, setFields] = useState({}); const [currentProperties, setCurrentProperties] = useState({}); const [form] = Form.useForm(); @@ -40,16 +42,15 @@ const AttributionDrawer: React.FC = ({ const map = useMap(); - useEffect(() => { - setFields(selectedFeature?.getProperties()); - }, [selectedFeature]); + const { + t + } = useTranslation(); useEffect(() => { const properties = selectedFeature?.getProperties(); - setCurrentProperties({...properties}); + setCurrentProperties({ ...properties }); - // TODO filter out geometry const fs: any = {}; if (properties) { Object.entries(properties).forEach(([key, value]) => { @@ -91,12 +92,13 @@ const AttributionDrawer: React.FC = ({ } Object.entries(input.fields).forEach(([key, value]) => { + // @ts-ignore selectedFeature.set(value.name, value.value); }); }; const onPropertyAdd = () => { - const newProps = {...currentProperties}; + const newProps = { ...currentProperties }; newProps[''] = ''; setCurrentProperties(newProps); }; @@ -124,7 +126,13 @@ const AttributionDrawer: React.FC = ({ const getFormItems = () => { - return Object.entries(currentProperties).map(([key, value]) => { + const filteredProperties = currentProperties; + + if (filteredProperties.geometry) { + delete filteredProperties.geometry; + } + + return Object.entries(filteredProperties).map(([key, value]) => { return (
= ({ return ( <> = ({ <> {!selectedFeature && <> - Please select a feature + {t('Attribution.select')} } -
= ({ getFormItems() } - + {selectedFeature ? + : + <>}
diff --git a/src/i18n/translations.ts b/src/i18n/translations.ts index a54af203a..c8b7e9cc1 100644 --- a/src/i18n/translations.ts +++ b/src/i18n/translations.ts @@ -199,6 +199,12 @@ export default { undo: 'Rückgängig', redo: 'Wiederherstellen' }, + Attribution: { + title: 'Attribute', + add: 'Attribut hinzufügen', + select: 'Wählen Sie zunächst eine Geometrie aus.', + submit: 'Speichern' + }, ResetButton: { title: 'Zurücksetzen' }, @@ -425,6 +431,12 @@ export default { undo: 'Undo', redo: 'Redo' }, + Attribution: { + title: 'Attributes', + add: 'Add Attribution', + select: 'Please select a geometry first.', + submit: 'Submit' + }, ResetButton: { title: 'Reset' },