Standalone Popups
Display popups anywhere on the map without markers.
Use MapPopup to display a popup at any location on the map. Unlike MarkerPopup, standalone popups are not attached to markers and can be controlled programmatically.
"use client";
import { useState } from "react";
import { Map, MapPopup } from "@/components/ui/map";
import { Button } from "@/components/ui/button";
export function StandalonePopupExample() {
const [showPopup, setShowPopup] = useState(true);
return (
<div className="h-[400px] w-full relative">
<Map center={[116.397428, 39.90923]} zoom={13}>
{showPopup && (
<MapPopup
longitude={116.397428}
latitude={39.90923}
onClose={() => setShowPopup(false)}
closeButton
className="w-62"
>
<div className="space-y-2">
<h3 className="font-semibold text-foreground">Beijing</h3>
<p className="text-sm text-muted-foreground">
The capital of China. Population: 21.5 million
</p>
<Button
size="sm"
variant="outline"
className="w-full"
onClick={() => setShowPopup(false)}
>
Close
</Button>
</div>
</MapPopup>
)}
</Map>
{!showPopup && (
<Button
size="sm"
className="absolute bottom-4 left-4 z-10"
onClick={() => setShowPopup(true)}
>
Show Popup
</Button>
)}
</div>
);
}