From acff469ba069b6f090adfd5ed91379c9f146aa77 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Wed, 30 Mar 2022 15:18:16 -0600 Subject: Ability to add, remove, update radius and location of chatrooms with a leaflet --- client/components/map/_map.jsx | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 client/components/map/_map.jsx (limited to 'client/components/map/_map.jsx') diff --git a/client/components/map/_map.jsx b/client/components/map/_map.jsx new file mode 100644 index 0000000..9f6684c --- /dev/null +++ b/client/components/map/_map.jsx @@ -0,0 +1,47 @@ +import { MapContainer, TileLayer } from 'react-leaflet'; +import '@geoman-io/leaflet-geoman-free'; +import '@geoman-io/leaflet-geoman-free/dist/leaflet-geoman.css'; +import Geoman from './chat_room_geoman'; +import { useEffect, useState } from 'react'; +import toast from 'react-hot-toast'; +import { Legend } from './legend'; + +export const Map = ({ user, zoom }) => { + const [loading, setLoading] = useState(true); + const [position, setPosition] = useState({}); + const [positionWatcher, setPositionWatcher] = useState(); + + zoom = zoom || 18; + + useEffect(() => { + if (user) { + setPositionWatcher( + navigator.geolocation.getCurrentPosition( + (pos) => { + const { latitude: lat, longitude: lng } = pos.coords; + setPosition({ lat, lng }); + setLoading(false); + }, + (err) => { + toast.error(err.message); + }, + ), + ); + } + }, [user]); + + if (!loading) { + return ( + + + + + + ); + } + return
Getting current location...
; +}; -- cgit v1.2.3-70-g09d2