From 4181460ba11bd43f12aca658fe79ab05ca19debc Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Thu, 27 Jun 2024 16:09:09 +0200 Subject: [PATCH] profiles, reverse, geocoder, ... --- .../ItemPopupComponents/HeaderView.tsx | 21 +++++++++- src/Components/Profile/ContactInfo.tsx | 19 +++++---- src/Components/Profile/OverlayItemProfile.tsx | 39 ++++++++---------- src/Components/Profile/SocialShareBar.tsx | 1 - src/Components/README.md | 9 ++++ src/Components/Templates/MapOverlayPage.tsx | 7 ++-- src/Utils/ReverseGeocoder.ts | 41 +++++++++++++++++++ 7 files changed, 100 insertions(+), 37 deletions(-) create mode 100644 src/Components/README.md create mode 100644 src/Utils/ReverseGeocoder.ts diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx index db2312fa..ca12fc2c 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx @@ -6,11 +6,13 @@ import { useAssetApi } from '../../../AppShell/hooks/useAssets' import DialogModal from "../../../Templates/DialogModal"; import { useNavigate } from "react-router-dom"; import { useMap } from "react-leaflet"; +import { reverseGeocode } from "../../../../Utils/ReverseGeocoder"; +import { useEffect } from "react"; -export function HeaderView({ item, api, editCallback, deleteCallback, setPositionCallback, itemNameField, itemSubnameField, itemAvatarField, loading, hideMenu = false, big = false, truncateSubname = true, hideSubname = false }: { +export function HeaderView({ item, api, editCallback, deleteCallback, setPositionCallback, itemNameField, itemSubnameField, itemAvatarField, loading, hideMenu = false, big = false, truncateSubname = true, hideSubname = false, showAddress = false }: { item: Item, api?: ItemsApi, editCallback?: any, @@ -23,7 +25,8 @@ export function HeaderView({ item, api, editCallback, deleteCallback, setPositio hideMenu?: boolean, big?: boolean, hideSubname?: boolean, - truncateSubname?:boolean + truncateSubname?:boolean, + showAddress?: boolean }) { @@ -37,6 +40,17 @@ export function HeaderView({ item, api, editCallback, deleteCallback, setPositio const title = itemNameField ? getValue(item, itemNameField) : item.layer?.itemNameField && item && getValue(item, item.layer?.itemNameField); const subtitle = itemSubnameField ? getValue(item, itemSubnameField) : item.layer?.itemSubnameField && item && getValue(item, item.layer?.itemSubnameField); + const [address, setAdress] = React.useState(""); + + useEffect(() => { + + item.position && reverseGeocode(item.position?.coordinates[1],item.position?.coordinates[0]).then(address => { + setAdress(address); + }); + + }, [item]) + + const openDeleteModal = async (event: React.MouseEvent) => { @@ -62,6 +76,9 @@ export function HeaderView({ item, api, editCallback, deleteCallback, setPositio
{title}
+ {showAddress && address && !hideSubname &&
+ {address} +
} {subtitle && !hideSubname &&
{subtitle}
} diff --git a/src/Components/Profile/ContactInfo.tsx b/src/Components/Profile/ContactInfo.tsx index 43ec9e0d..7a8bc86d 100644 --- a/src/Components/Profile/ContactInfo.tsx +++ b/src/Components/Profile/ContactInfo.tsx @@ -1,11 +1,16 @@ +import { useAssetApi } from "../AppShell/hooks/useAssets"; -const ContactInfo = ({ contact }) => ( +const ContactInfo = ({ email, name, avatar } : {email: string, name: string, avatar: string}) => { + const assetsApi = useAssetApi(); + + + return(

Du hast Fragen?

- {contact.avatarSrc ? ( - {contact.name} + {avatar ? ( + {name} ) : ( @@ -16,8 +21,8 @@ const ContactInfo = ({ contact }) => ( )}
-); +)} export default ContactInfo; \ No newline at end of file diff --git a/src/Components/Profile/OverlayItemProfile.tsx b/src/Components/Profile/OverlayItemProfile.tsx index 1e3a46d2..b4b73d03 100644 --- a/src/Components/Profile/OverlayItemProfile.tsx +++ b/src/Components/Profile/OverlayItemProfile.tsx @@ -25,6 +25,7 @@ import { TagView } from '../Templates/TagView'; import RelationCard from "./RelationCard"; import ContactInfo from "./ContactInfo"; import ProfileSubHeader from "./ProfileSubHeader"; +import SocialShareBar from './SocialShareBar'; export function OverlayItemProfile() { @@ -297,41 +298,33 @@ export function OverlayItemProfile() { }; - return ( <> {item && - + <> -
- navigate("/edit-item/" + item.id)} setPositionCallback={() => { map.closePopup(); setSelectPosition(item); navigate("/") }} big truncateSubname={false} /> -
+
+ navigate("/edit-item/" + item.id)} setPositionCallback={() => { map.closePopup(); setSelectPosition(item); navigate("/") }} big truncateSubname={false} /> + -
+
+ +
{item.layer?.itemType.onepager && <> - - {d.contact && ( - - )} + {/* Description Section */} -
-

Beschreibung

-

- {d.description ?? 'Keine Beschreibung vorhanden'} -

-
+ + + + {d.contact && ( + + )} {/* Relations Section */} {d.relations && ( diff --git a/src/Components/Profile/SocialShareBar.tsx b/src/Components/Profile/SocialShareBar.tsx index e66ac421..61a07207 100644 --- a/src/Components/Profile/SocialShareBar.tsx +++ b/src/Components/Profile/SocialShareBar.tsx @@ -3,7 +3,6 @@ import SocialShareButton from './SocialShareButton'; const SocialShareBar = ({ url, title, platforms = ['facebook', 'twitter', 'linkedin', 'xing', 'email'] }) => { return (
- Teilen:
{platforms.map((platform) => ( { @@ -32,12 +32,11 @@ export function MapOverlayPage({ children, className, backdrop, card = true, pad return (
-
+
{children}
) -} - +} \ No newline at end of file diff --git a/src/Utils/ReverseGeocoder.ts b/src/Utils/ReverseGeocoder.ts new file mode 100644 index 00000000..5d23b5a8 --- /dev/null +++ b/src/Utils/ReverseGeocoder.ts @@ -0,0 +1,41 @@ +import axios from 'axios'; + +interface ReverseGeocodeResponse { + place_id: number; + licence: string; + osm_type: string; + osm_id: number; + lat: string; + lon: string; + display_name: string; + address: { + road?: string; + house_number?: string; + city?: string; + town?: string; + village?: string; + [key: string]: string | undefined; + }; + boundingbox: string[]; +} + +export async function reverseGeocode(lat: number, lon: number): Promise { + const url = `https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lon}&addressdetails=1`; + + try { + const response = await axios.get(url); + const address = response.data.address; + + // Extrahiere Straße, Hausnummer und Ort + const street = address.road || ''; + const houseNumber = address.house_number || ''; + const city = address.city || address.town || address.village || ''; + + // Formatiere die Adresse + const formattedAddress = `${street} ${houseNumber}, ${city}`.trim(); + return formattedAddress || ''; + } catch (error) { + console.error('Error:', error); + return ''; + } +}