Components
DOM-based map markers with custom content, tooltips, popups, and draggable marker support.

"use client";
import { useMemo } from "react";
import {
Map,
MapMarker,
MarkerContent,
MapClusterLayer,
} from "@/components/ui/mapcn-map-marker";
const settings = {
zoom: 3,
color: "#3b82f6",
opacity: 1,
pointColor: "#f97316",
clusterRadius: 50,
};
const CENTER: [number, number] = [-98, 39];
function makePoints(): GeoJSON.FeatureCollection<GeoJSON.Point> {
const features: GeoJSON.Feature<GeoJSON.Point>[] = [];
for (let i = 0; i < 400; i += 1) {
features.push({
type: "Feature",
properties: {},
geometry: {
type: "Point",
coordinates: [-125 + Math.random() * 58, 25 + Math.random() * 24],
},
});
}
return { type: "FeatureCollection", features };
}
export default function Demo(props: Partial<typeof settings>) {
const s = { ...settings, ...props };
const data = useMemo(() => makePoints(), []);
return (
<div className="h-screen w-screen">
<Map viewport={{ center: CENTER, zoom: s.zoom }}>
<MapClusterLayer
data={data}
pointColor={s.pointColor}
clusterRadius={s.clusterRadius}
/>
<MapMarker longitude={CENTER[0]} latitude={CENTER[1]}>
<MarkerContent>
<div
className="h-4 w-4 rounded-full border-2 border-white shadow-lg"
style={{ backgroundColor: s.color, opacity: s.opacity }}
/>
</MarkerContent>
</MapMarker>
</Map>
</div>
);
}
