'use client'; import React, { useEffect, useState } from 'react'; import { MapContainer, TileLayer, Marker, Popup, CircleMarker } from 'react-leaflet'; import L from 'leaflet'; import 'leaflet/dist/leaflet.css'; interface Burrow { id: string; gps_lat: number; gps_lng: number; status: string; location_description: string; } // Fix default marker icons in Next.js const activeIcon = new L.DivIcon({ className: '', html: '
', iconSize: [14, 14], iconAnchor: [7, 7], }); const inactiveIcon = new L.DivIcon({ className: '', html: '
', iconSize: [12, 12], iconAnchor: [6, 6], }); export default function BurrowMap() { const [burrows, setBurrows] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001'; fetch(`${apiUrl}/api/burrows`) .then((r) => r.json()) .then((data) => { setBurrows(data); setLoading(false); }) .catch(() => setLoading(false)); }, []); if (loading) { return (
); } // Cape Coral center const center: [number, number] = [26.6029, -81.9595]; return ( {burrows.map((b) => (
{b.status === 'active' ? '🟢 Active' : '⚫ Inactive'} Burrow
{b.location_description}
{b.gps_lat.toFixed(4)}, {b.gps_lng.toFixed(4)}
))}
); }