MCPcopy Create free account
hub / github.com/Seanium/ChatMap / MapContainer

Function MapContainer

components/map-container.tsx:9–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7import MapError from "@/components/map-error"
8
9export default function MapContainer() {
10 const { markers, setMapInstance, task_type } = useMapStore()
11 const [mapError, setMapError] = useState<string | null>(null)
12 const [MapComponent, setMapComponent] = useState<React.ComponentType<any> | null>(null)
13
14 // Load the map component only on the client side
15 useEffect(() => {
16 // Add Leaflet CSS from CDN
17 const linkElement = document.createElement("link")
18 linkElement.rel = "stylesheet"
19 linkElement.href = "https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
20 linkElement.integrity = "sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
21 linkElement.crossOrigin = ""
22 document.head.appendChild(linkElement)
23
24 // Dynamically import the map component
25 import("@/components/client-map")
26 .then((module) => {
27 setMapComponent(() => module.default)
28 })
29 .catch((error) => {
30 console.error("Error loading map component:", error)
31 setMapError("加载地图组件时出错。请检查控制台获取更多信息。")
32 })
33
34 return () => {
35 // Clean up the CSS link when component unmounts
36 document.head.removeChild(linkElement)
37 }
38 }, [])
39
40 if (mapError) {
41 return <MapError message={mapError} />
42 }
43
44 if (!MapComponent) {
45 return (
46 <div className="flex-1 flex items-center justify-center">
47 <div className="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-primary"></div>
48 </div>
49 )
50 }
51
52 return <MapComponent markers={markers} setMapInstance={setMapInstance} task_type={task_type} />
53}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected