feat(map in message): Added map in message of invite

This commit is contained in:
Laurian-Dufrechou
2023-05-21 00:41:50 +02:00
parent 5d0b0747b6
commit 366d6abf86
4 changed files with 97 additions and 14 deletions
+32
View File
@@ -0,0 +1,32 @@
import { Flex } from "@chakra-ui/react";
import { MapContainer, Marker, TileLayer } from "react-leaflet";
import SimpleMarkerBar from "./SimpleMarkerBar";
import MarkerClusterGroup from "@christopherpickering/react-leaflet-markercluster";
import "leaflet/dist/leaflet.css";
type MapBarProps = {
lat: string;
lon: string;
name: string;
align: "left" | "right";
};
export default function MapBar({ lat, lon, name, align }: MapBarProps) {
return (
<Flex justifyContent={align}>
<MapContainer
center={[Number(lat), Number(lon)]}
zoom={13}
minZoom={6}
zoomControl={false}
style={{ width: "50%", height: "20rem" }}
>
<TileLayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
/>
<SimpleMarkerBar lat={lat} lon={lon} name={name} />
</MapContainer>
</Flex>
);
}
+28 -10
View File
@@ -1,15 +1,33 @@
import {Text} from '@chakra-ui/react';
import { Box, Text } from "@chakra-ui/react";
import dynamic from "next/dynamic";
const MapBarWithNoSSR = dynamic(() => import("./MapBar"), {
ssr: false,
});
type Props = {
align: 'left' | 'right'
align: "left" | "right";
point: {
lon: string
lat: string
name: string
}
}
lon: string;
lat: string;
name: string;
};
};
export default function MessageMap({align, point}: Props) {
const {lon, lat, name} = point;
return <Text align={align}>{lon}, {lat}, {name}</Text>;
export default function MessageMap({ align, point }: Props) {
const { lon, lat, name } = point;
return (
<Box>
<MapBarWithNoSSR
lon={lon}
lat={lat}
name={name}
align={align}
></MapBarWithNoSSR>
<Text align={align}>
{lon}, {lat}, {name}
</Text>
</Box>
);
}
+34
View File
@@ -0,0 +1,34 @@
import { Marker, Popup } from "react-leaflet";
import { Box, Text } from "@chakra-ui/react";
import L from "leaflet";
type SimpleMarkerBarProps = {
lat: string;
lon: string;
name: string;
};
export default function SimpleMarkerBar({
lat,
lon,
name,
}: SimpleMarkerBarProps) {
const barIcon = new L.Icon({
iconUrl: "drink_cocktail.png",
iconSize: [35, 35],
popupAnchor: [0, -5],
backgroundColor: "purple",
});
return (
<Marker icon={barIcon} position={[Number(lat), Number(lon)]}>
<Popup>
<Box align={"center"}>
<Text fontSize={"1rem"} fontWeight={"bold"} align={"center"}>
Vous avez é invité au : {name}
</Text>
</Box>
</Popup>
</Marker>
);
}
+2 -3
View File
@@ -1,8 +1,7 @@
import { MapContainer, TileLayer, Marker, useMapEvents } from "react-leaflet";
import { Flex, Text, useToast } from "@chakra-ui/react";
import { MapContainer, TileLayer, Marker } from "react-leaflet";
import { Text, useToast } from "@chakra-ui/react";
import MarkerClusterGroup from "@christopherpickering/react-leaflet-markercluster";
import L from "leaflet";
import { memo, useState } from "react";
import "@christopherpickering/react-leaflet-markercluster/dist/styles.min.css";