map.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React, { useEffect, useMemo, useRef } from "react";
  2. import mapboxgl from "mapbox-gl";
  3. import { useTheme } from "next-themes";
  4. import Image from "next/image";
  5. const MapComponent: React.FC = () => {
  6. const { theme } = useTheme();
  7. const mapContainerRef = useRef<HTMLDivElement>(null);
  8. const style = useMemo(() => {
  9. return theme === "dark"
  10. ? "mapbox://styles/mapbox/dark-v10"
  11. : "mapbox://styles/mapbox/standard";
  12. }, [theme]);
  13. useEffect(() => {
  14. const map = new mapboxgl.Map({
  15. accessToken: process.env.NEXT_PUBLIC_MAPBOX_TOKEN,
  16. container: mapContainerRef.current as HTMLElement,
  17. style: style,
  18. center: [-118.4438, 34.0699],
  19. zoom: 10,
  20. });
  21. return () => map.remove(); // Cleanup on unmount
  22. }, [style]);
  23. return (
  24. <div className="w-full h-full rounded-3xl overflow-hidden">
  25. <div ref={mapContainerRef} className="w-full h-full" />
  26. <div
  27. className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2
  28. flex items-center justify-center
  29. w-14 h-14 md:w-20 md:h-20 rounded-full
  30. shadow-lg cursor-pointer bg-blue-400 bg-opacity-40 border-2 md:border-4 border-white border-opacity-80 hover:animate-pulse"
  31. >
  32. <Image
  33. alt="Icon"
  34. className="w-8 h-8 md:w-10 md:h-10"
  35. height={300}
  36. src="https://raw.githubusercontent.com/Tarikul-Islam-Anik/Animated-Fluent-Emojis/master/Emojis/Smilies/Hugging%20Face.png"
  37. width={300}
  38. />
  39. </div>
  40. </div>
  41. );
  42. };
  43. export default MapComponent;