import React, {useEffect, useState} from "react"; import {Link, useNavigate} from "react-router"; import {getMapSearchStatus, searchMap} from "../api"; import {Card, CardGroup, Header, Loading, Panel} from "./ui"; import {Paginator} from "./Common"; import {useLatestRequest, usePages} from "../hooks/customHooks"; import {QueryContext} from "../contexts/contexts"; import {MAP_VIEWER_URI} from "./Vars"; function formatPopulation(pop) { if (!pop) return null; if (pop >= 1_000_000) return `${(pop / 1_000_000).toFixed(1)}M`; if (pop >= 1_000) return `${Math.round(pop / 1_000)}K`; return `${pop}`; } function MapPlaceCard({place, index}) { const navigate = useNavigate(); const [iframeSrc, setIframeSrc] = useState(null); const zoom = place.min_zoom ? Math.max(8, Math.round(13 - place.min_zoom / 3)) : 11; const embedSrc = `${MAP_VIEWER_URI}/embed.html#${place.lat},${place.lon},${zoom}`; // Stagger iframe loading to avoid overwhelming the map viewer with simultaneous requests. useEffect(() => { const timer = setTimeout(() => setIframeSrc(embedSrc), 100 + index * 200); return () => clearTimeout(timer); }, [embedSrc, index]); const handleClick = () => { navigate(`/map?lat=${place.lat}&lon=${place.lon}&z=${zoom}`); }; const subtitle = []; if (place.region) subtitle.push(place.region); const detail = place.kind_detail || place.kind || ""; if (detail && !place.region) subtitle.push(detail.replace(/_/g, " ")); const pop = formatPopulation(place.population); if (pop) subtitle.push(`pop. ${pop}`); const media =
{iframeSrc &&