Skip to content

armgit / mapcn

Public Imported from GitHub
0

Beautiful map components. 100% Free, Zero config, one command setup.

TypeScript

update: refresh homepage examples with arc demo

anmolc6a0090cd40c
diff --git a/src/app/(main)/(home)/_components/examples-grid.tsx b/src/app/(main)/(home)/_components/examples-grid.tsx
index 2921c99..16e68c1 100644
--- a/src/app/(main)/(home)/_components/examples-grid.tsx
+++ b/src/app/(main)/(home)/_components/examples-grid.tsx
@@ -1,20 +1,20 @@
import {
AnalyticsExample,
DeliveryExample,
- TrendingExample,
EVChargingExample,
TrailExample,
+ FlyToExample,
+ ArcExample,
} from "./examples/index";
-import { FlyToExample } from "./examples/flyto-example";
export function ExamplesGrid() {
return (
<div className="grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-4">
<AnalyticsExample />
<TrailExample />
- <FlyToExample />
+ <ArcExample />
<EVChargingExample />
- <TrendingExample />
+ <FlyToExample />
<DeliveryExample />
</div>
);
diff --git a/src/app/(main)/(home)/_components/examples/analytics-example.tsx b/src/app/(main)/(home)/_components/examples/analytics-example.tsx
index 17b7a4d..e965b8a 100644
--- a/src/app/(main)/(home)/_components/examples/analytics-example.tsx
+++ b/src/app/(main)/(home)/_components/examples/analytics-example.tsx
@@ -8,12 +8,14 @@ const analyticsData = [
{ lng: -74.006, lat: 40.7128, city: "New York", users: 847, size: 14 },
{ lng: -0.1276, lat: 51.5074, city: "London", users: 623, size: 12 },
{ lng: 139.6917, lat: 35.6895, city: "Tokyo", users: 412, size: 10 },
+ { lng: 114.1694, lat: 22.3193, city: "Hong Kong", users: 364, size: 10 },
{ lng: -122.4194, lat: 37.7749, city: "San Francisco", users: 298, size: 9 },
- { lng: 2.3522, lat: 48.8566, city: "Paris", users: 187, size: 8 },
+ { lng: 72.8777, lat: 19.076, city: "Mumbai", users: 271, size: 9 },
+ { lng: 13.405, lat: 52.52, city: "Berlin", users: 187, size: 8 },
{ lng: 77.209, lat: 28.6139, city: "Delhi", users: 156, size: 7 },
{ lng: 151.2093, lat: -33.8688, city: "Sydney", users: 134, size: 7 },
+ { lng: 18.4241, lat: -33.9249, city: "Cape Town", users: 118, size: 6 },
{ lng: -43.1729, lat: -22.9068, city: "Rio", users: 89, size: 6 },
- { lng: 4.9041, lat: 52.3676, city: "Amsterdam", users: 76, size: 5 },
{ lng: 126.978, lat: 37.5665, city: "Seoul", users: 45, size: 5 },
];
@@ -27,7 +29,7 @@ export function AnalyticsExample() {
<div className="text-muted-foreground mb-1 text-[10px] tracking-wider uppercase">
Active Users
</div>
- <div className="text-2xl leading-tight font-semibold">2,847</div>
+ <div className="text-2xl leading-tight font-semibold">3,544</div>
<div className="mt-1 flex items-center gap-1">
<TrendingUp className="size-3 text-emerald-500" />
<span className="text-xs text-emerald-500">+12.5%</span>
@@ -39,32 +41,15 @@ export function AnalyticsExample() {
{analyticsData.map((loc) => (
<MapMarker key={loc.city} longitude={loc.lng} latitude={loc.lat}>
<MarkerContent>
- <div className="relative flex items-center justify-center">
- <div
- className="absolute rounded-full bg-emerald-500/20"
- style={{
- width: loc.size * 2.5,
- height: loc.size * 2.5,
- }}
- />
- <div
- className="absolute animate-ping rounded-full bg-emerald-500/40"
- style={{
- width: loc.size * 1.5,
- height: loc.size * 1.5,
- animationDuration: "2s",
- }}
- />
- <div
- className="relative rounded-full bg-emerald-500 shadow-lg shadow-emerald-500/50"
- style={{ width: loc.size, height: loc.size }}
- />
- </div>
+ <div
+ className="rounded-full bg-emerald-500/80 shadow-sm"
+ style={{ width: loc.size * 1.8, height: loc.size * 1.8 }}
+ />
</MarkerContent>
<MarkerTooltip>
<div className="text-center">
<div className="font-medium">{loc.city}</div>
- <div className="font-semibold text-emerald-500">
+ <div className="font-semibold text-emerald-400">
{loc.users}
</div>
<div className="text-background/70 text-[10px]">
diff --git a/src/app/(main)/(home)/_components/examples/arc-example.tsx b/src/app/(main)/(home)/_components/examples/arc-example.tsx
new file mode 100644
index 0000000..36b9d74
--- /dev/null
+++ b/src/app/(main)/(home)/_components/examples/arc-example.tsx
@@ -0,0 +1,64 @@
+"use client";
+
+import {
+ Map,
+ MapArc,
+ MapMarker,
+ MarkerContent,
+ MarkerLabel,
+} from "@/registry/map";
+import { ExampleCard } from "./example-card";
+
+const hub = { name: "London", lng: -0.1276, lat: 51.5074 };
+
+const destinations = [
+ { name: "New York", lng: -74.006, lat: 40.7128 },
+ { name: "São Paulo", lng: -46.6333, lat: -23.5505 },
+ { name: "Cape Town", lng: 18.4241, lat: -33.9249 },
+ { name: "Mumbai", lng: 72.8777, lat: 19.076 },
+ { name: "Tokyo", lng: 139.6917, lat: 35.6895 },
+];
+
+const arcs = destinations.map((dest) => ({
+ id: dest.name,
+ from: [hub.lng, hub.lat] as [number, number],
+ to: [dest.lng, dest.lat] as [number, number],
+}));
+
+export function ArcExample() {
+ return (
+ <ExampleCard className="aspect-square" stagger={8}>
+ <Map
+ center={[-0.1276, 41.5074]}
+ zoom={1.2}
+ projection={{ type: "globe" }}
+ >
+ <MapArc
+ data={arcs}
+ paint={{
+ "line-color": "#3b82f6",
+ "line-opacity": 0.9,
+ "line-dasharray": [2, 2],
+ }}
+ interactive={false}
+ />
+
+ <MapMarker longitude={hub.lng} latitude={hub.lat}>
+ <MarkerContent>
+ <div className="size-3 rounded-full border-2 border-white bg-blue-500" />
+ <MarkerLabel position="top">{hub.name}</MarkerLabel>
+ </MarkerContent>
+ </MapMarker>
+
+ {destinations.map((dest) => (
+ <MapMarker key={dest.name} longitude={dest.lng} latitude={dest.lat}>
+ <MarkerContent>
+ <div className="size-2 rounded-full border-2 border-white bg-blue-500" />
+ <MarkerLabel position="top">{dest.name}</MarkerLabel>
+ </MarkerContent>
+ </MapMarker>
+ ))}
+ </Map>
+ </ExampleCard>
+ );
+}
diff --git a/src/app/(main)/(home)/_components/examples/delivery-example.tsx b/src/app/(main)/(home)/_components/examples/delivery-example.tsx
index 336c595..b172eeb 100644
--- a/src/app/(main)/(home)/_components/examples/delivery-example.tsx
+++ b/src/app/(main)/(home)/_components/examples/delivery-example.tsx
@@ -1,6 +1,5 @@
"use client";
-import { useEffect, useState } from "react";
import {
Map,
MapMarker,
@@ -15,60 +14,98 @@ import { ExampleCard } from "./example-card";
const store = { lng: -0.14, lat: 51.5154 };
const home = { lng: -0.07, lat: 51.51 };
-export function DeliveryExample() {
- const [route, setRoute] = useState<[number, number][]>([]);
- const [truckPosition, setTruckPosition] = useState<[number, number] | null>(
- null,
- );
-
- useEffect(() => {
- async function fetchRoute() {
- try {
- const response = await fetch(
- `https://router.project-osrm.org/route/v1/driving/${store.lng},${store.lat};${home.lng},${home.lat}?overview=full&geometries=geojson`,
- );
- const data = await response.json();
-
- if (data.routes?.[0]?.geometry?.coordinates) {
- const coords: [number, number][] =
- data.routes[0].geometry.coordinates;
- setRoute(coords);
- const truckIdx = Math.floor(coords.length * 0.6);
- setTruckPosition(coords[truckIdx]);
- }
- } catch (error) {
- console.error("Failed to fetch route:", error);
- }
- }
+// Precomputed driving route (OSRM result)
+const route: [number, number][] = [
+ [-0.14, 51.5155],
+ [-0.1418, 51.5153],
+ [-0.1417, 51.5145],
+ [-0.1414, 51.514],
+ [-0.1407, 51.5133],
+ [-0.1398, 51.5122],
+ [-0.1393, 51.5117],
+ [-0.1388, 51.5111],
+ [-0.1381, 51.5103],
+ [-0.1376, 51.5101],
+ [-0.1364, 51.5099],
+ [-0.136, 51.5099],
+ [-0.1354, 51.5101],
+ [-0.1348, 51.5101],
+ [-0.134, 51.51],
+ [-0.1333, 51.5101],
+ [-0.1326, 51.5094],
+ [-0.1319, 51.5086],
+ [-0.1311, 51.5078],
+ [-0.1301, 51.508],
+ [-0.1292, 51.5083],
+ [-0.129, 51.5082],
+ [-0.1286, 51.5075],
+ [-0.128, 51.5075],
+ [-0.1275, 51.5076],
+ [-0.1272, 51.5074],
+ [-0.1255, 51.507],
+ [-0.1233, 51.5067],
+ [-0.1226, 51.5066],
+ [-0.1219, 51.5072],
+ [-0.1208, 51.5084],
+ [-0.1193, 51.5094],
+ [-0.1187, 51.5097],
+ [-0.1165, 51.5104],
+ [-0.1154, 51.5107],
+ [-0.1135, 51.5109],
+ [-0.112, 51.511],
+ [-0.1082, 51.511],
+ [-0.1072, 51.511],
+ [-0.1035, 51.511],
+ [-0.1015, 51.5112],
+ [-0.0958, 51.5112],
+ [-0.0932, 51.5109],
+ [-0.0912, 51.5105],
+ [-0.0903, 51.5103],
+ [-0.0896, 51.5102],
+ [-0.0883, 51.5099],
+ [-0.0871, 51.5097],
+ [-0.0838, 51.5093],
+ [-0.0818, 51.5091],
+ [-0.0805, 51.5094],
+ [-0.0797, 51.5096],
+ [-0.0782, 51.5095],
+ [-0.0768, 51.5095],
+ [-0.0755, 51.5097],
+ [-0.0748, 51.5099],
+ [-0.0741, 51.5098],
+ [-0.0736, 51.5093],
+ [-0.0732, 51.5089],
+ [-0.0715, 51.5084],
+ [-0.0709, 51.5083],
+ [-0.0705, 51.5091],
+ [-0.0696, 51.5094],
+ [-0.0699, 51.51],
+];
- fetchRoute();
- }, []);
+const truckPosition = route[Math.floor(route.length * 0.6)];
+export function DeliveryExample() {
return (
<ExampleCard
className="aspect-square sm:col-span-2 sm:aspect-video lg:aspect-auto"
stagger={9}
>
<Map center={[-0.105, 51.511]} zoom={12.4}>
- {route.length > 0 && (
- <MapRoute coordinates={route} width={4} color="#4285F4" />
- )}
+ <MapRoute coordinates={route} width={4} color="#4285F4" />
<MapMarker longitude={store.lng} latitude={store.lat}>
<MarkerContent>
<div className="size-3.5 rounded-full border-2 border-white bg-emerald-500 shadow-lg" />
<MarkerLabel>Store</MarkerLabel>
</MarkerContent>
</MapMarker>
- {truckPosition && (
- <MapMarker longitude={truckPosition[0]} latitude={truckPosition[1]}>
- <MarkerContent>
- <div className="rounded-full bg-blue-500 p-1.5 shadow-lg">
- <Truck className="size-3 text-white" />
- </div>
- </MarkerContent>
- <MarkerTooltip>On the way</MarkerTooltip>
- </MapMarker>
- )}
+ <MapMarker longitude={truckPosition[0]} latitude={truckPosition[1]}>
+ <MarkerContent>
+ <div className="rounded-full bg-blue-500 p-1.5 shadow-lg">
+ <Truck className="size-3 text-white" />
+ </div>
+ </MarkerContent>
+ <MarkerTooltip>On the way</MarkerTooltip>
+ </MapMarker>
<MapMarker longitude={home.lng} latitude={home.lat}>
<MarkerContent>
<div className="size-3.5 rounded-full border-2 border-white bg-blue-500 shadow-lg" />
diff --git a/src/app/(main)/(home)/_components/examples/flyto-example.tsx b/src/app/(main)/(home)/_components/examples/flyto-example.tsx
index a767ff8..f0193b1 100644
--- a/src/app/(main)/(home)/_components/examples/flyto-example.tsx
+++ b/src/app/(main)/(home)/_components/examples/flyto-example.tsx
@@ -1,69 +1,60 @@
"use client";
-import {
- Map,
- MapMarker,
- MapRef,
- MarkerContent,
- MarkerTooltip,
-} from "@/registry/map";
-import { useRef } from "react";
-import { ExampleCard } from "./example-card";
+import { useRef, useState } from "react";
+
+import { Map, MapMarker, MapRef, MarkerContent } from "@/registry/map";
import { Button } from "@/components/ui/button";
-import { Navigation } from "lucide-react";
+import { ExampleCard } from "./example-card";
-const destination = {
- name: "New York",
- description: "United States",
- center: [-74.006, 40.7128] as [number, number],
- startCenter: [10, 50] as [number, number],
-};
+const destinations = [
+ { name: "New York", center: [-74.006, 40.7128] as [number, number] },
+ { name: "London", center: [-0.1276, 51.5074] as [number, number] },
+ { name: "Tokyo", center: [139.6917, 35.6895] as [number, number] },
+ { name: "Sydney", center: [151.2093, -33.8688] as [number, number] },
+];
export function FlyToExample() {
const mapRef = useRef<MapRef>(null);
+ const [activeIndex, setActiveIndex] = useState(0);
+
+ const flyTo = (index: number) => {
+ setActiveIndex(index);
+ mapRef.current?.flyTo({
+ center: destinations[index].center,
+ zoom: 4.5,
+ duration: 2000,
+ essential: true,
+ });
+ };
+
+ const active = destinations[activeIndex];
return (
<ExampleCard className="aspect-square" stagger={6}>
- <Map
- center={destination.startCenter}
- zoom={0.6}
- ref={mapRef}
- projection={{ type: "globe" }}
- >
- <MapMarker
- longitude={destination.center[0]}
- latitude={destination.center[1]}
- >
+ <Map ref={mapRef} center={active.center} zoom={4.5}>
+ <MapMarker longitude={active.center[0]} latitude={active.center[1]}>
<MarkerContent>
<div className="relative flex items-center justify-center">
- <div className="absolute size-6 animate-ping rounded-full bg-cyan-500/20" />
- <div className="size-4 rounded-full border-2 border-white bg-cyan-500 shadow-lg" />
+ <div className="absolute size-6 animate-ping rounded-full bg-blue-500/30" />
+ <div className="size-3 rounded-full border-2 border-white bg-blue-500 shadow-lg" />
</div>
</MarkerContent>
- <MarkerTooltip>
- <div className="text-center">
- <div className="font-medium">{destination.name}</div>
- <div className="text-background/70 text-[10px]">
- {destination.description}
- </div>
- </div>
- </MarkerTooltip>
</MapMarker>
</Map>
- <Button
- size="icon-sm"
- variant="secondary"
- className="absolute top-2 right-2"
- onClick={() => {
- mapRef.current?.flyTo({
- center: destination.center,
- zoom: 14,
- duration: 2500,
- });
- }}
- >
- <Navigation className="size-4" />
- </Button>
+
+ <div className="absolute inset-x-3 top-3 flex flex-wrap gap-1.5">
+ {destinations.map((dest, index) => (
+ <Button
+ key={dest.name}
+ size="xs"
+ variant={index === activeIndex ? "default" : "secondary"}
+ onClick={() => flyTo(index)}
+ className="rounded-full border"
+ >
+ {dest.name}
+ </Button>
+ ))}
+ </div>
</ExampleCard>
);
}
diff --git a/src/app/(main)/(home)/_components/examples/index.tsx b/src/app/(main)/(home)/_components/examples/index.tsx
index a37c06a..8f49777 100644
--- a/src/app/(main)/(home)/_components/examples/index.tsx
+++ b/src/app/(main)/(home)/_components/examples/index.tsx
@@ -1,6 +1,7 @@
export { ExampleCard } from "./example-card";
export { AnalyticsExample } from "./analytics-example";
export { DeliveryExample } from "./delivery-example";
-export { TrendingExample } from "./trending-example";
export { EVChargingExample } from "./ev-charging-example";
export { TrailExample } from "./trail-example";
+export { FlyToExample } from "./flyto-example";
+export { ArcExample } from "./arc-example";
diff --git a/src/app/(main)/(home)/_components/examples/trending-example.tsx b/src/app/(main)/(home)/_components/examples/trending-example.tsx
deleted file mode 100644
index 6716d39..0000000
--- a/src/app/(main)/(home)/_components/examples/trending-example.tsx
+++ /dev/null
@@ -1,66 +0,0 @@
-"use client";
-
-import { Map, MapMarker, MarkerContent, MarkerTooltip } from "@/registry/map";
-import { Flame, TrendingUp } from "lucide-react";
-import { ExampleCard } from "./example-card";
-
-export function TrendingExample() {
- return (
- <ExampleCard className="aspect-square" stagger={8}>
- <Map center={[-73.99, 40.735]} zoom={10}>
- <MapMarker longitude={-73.9857} latitude={40.7484}>
- <MarkerContent>
- <div className="relative flex items-center justify-center">
- <div className="pointer-events-none absolute size-18 rounded-full bg-orange-500/30" />
- <div className="absolute size-7 rounded-full bg-orange-500/40" />
- <div className="rounded-full bg-linear-to-br from-orange-500 to-red-500 p-1.5 shadow-lg shadow-orange-500/50">
- <Flame className="size-3.5 text-white" />
- </div>
- </div>
- </MarkerContent>
- <MarkerTooltip>
- <p className="font-medium">Times Square</p>
- <div className="flex items-center gap-1">
- <TrendingUp className="size-3 text-green-500" />
- <span className="text-xs text-green-500">2.4k visitors</span>
- </div>
- </MarkerTooltip>
- </MapMarker>
- <MapMarker longitude={-73.9654} latitude={40.7829}>
- <MarkerContent>
- <div className="relative flex items-center justify-center">
- <div className="pointer-events-none absolute size-14 rounded-full bg-rose-500/30" />
- <div className="rounded-full bg-linear-to-br from-rose-500 to-pink-500 p-1.5 shadow-lg shadow-rose-500/50">
- <Flame className="size-3 text-white" />
- </div>
- </div>
- </MarkerContent>
- <MarkerTooltip>
- <p className="font-medium">Central Park</p>
- <div className="flex items-center gap-1">
- <TrendingUp className="size-3 text-green-500" />
- <span className="text-xs text-green-500">1.8k visitors</span>
- </div>
- </MarkerTooltip>
- </MapMarker>
- <MapMarker longitude={-74.0445} latitude={40.6892}>
- <MarkerContent>
- <div className="relative flex items-center justify-center">
- <div className="pointer-events-none absolute size-12 rounded-full bg-amber-500/30" />
- <div className="rounded-full bg-linear-to-br from-amber-500 to-yellow-500 p-1 shadow-lg shadow-amber-500/50">
- <Flame className="size-2.5 text-white" />
- </div>
- </div>
- </MarkerContent>
- <MarkerTooltip>
- <p className="font-medium">Statue of Liberty</p>
- <div className="flex items-center gap-1">
- <TrendingUp className="size-3 text-green-500" />
- <span className="text-xs text-green-500">890 visitors</span>
- </div>
- </MarkerTooltip>
- </MapMarker>
- </Map>
- </ExampleCard>
- );
-}
diff --git a/src/app/(main)/docs/_components/examples/arc-example.tsx b/src/app/(main)/docs/_components/examples/arc-example.tsx
index 447d02c..27e4102 100644
--- a/src/app/(main)/docs/_components/examples/arc-example.tsx
+++ b/src/app/(main)/docs/_components/examples/arc-example.tsx
@@ -1,4 +1,3 @@
-import { cn } from "@/lib/utils";
import {
Map,
MapArc,
@@ -20,23 +19,11 @@ const destinations = [
{ name: "Sydney", lng: 151.2093, lat: -33.8688 },
];
-const sanFrancisco = { name: "San Francisco", lng: -122.4194, lat: 37.7749 };
-const tokyo = destinations.find((d) => d.name === "Tokyo")!;
-
-const arcs = [
- ...destinations.map((dest) => ({
- id: dest.name,
- from: [hub.lng, hub.lat] as [number, number],
- to: [dest.lng, dest.lat] as [number, number],
- })),
- // Transpacific arc straddling the antimeridian — should bow across the
- // Pacific, not the long way around the globe.
- {
- id: "tokyo-sf",
- from: [tokyo.lng, tokyo.lat] as [number, number],
- to: [sanFrancisco.lng, sanFrancisco.lat] as [number, number],
- },
-];
+const arcs = destinations.map((dest) => ({
+ id: dest.name,
+ from: [hub.lng, hub.lat] as [number, number],
+ to: [dest.lng, dest.lat] as [number, number],
+}));
export function ArcExample() {
return (
@@ -53,7 +40,7 @@ export function ArcExample() {
<MapMarker longitude={hub.lng} latitude={hub.lat}>
<MarkerContent>
- <div className="size-3 rounded-full border-2 border-white bg-blue-500 shadow-md" />
+ <div className="size-3 rounded-full border-2 border-white bg-blue-500" />
<MarkerLabel
position="top"
className="bg-background/80 rounded-sm px-1.5 py-0.5 text-[11px] font-semibold backdrop-blur"
@@ -63,15 +50,10 @@ export function ArcExample() {
</MarkerContent>
</MapMarker>
- {[...destinations, sanFrancisco].map((dest) => (
+ {destinations.map((dest) => (
<MapMarker key={dest.name} longitude={dest.lng} latitude={dest.lat}>
<MarkerContent>
- <div
- className={cn(
- "size-2 rounded-full border-2 border-white",
- "bg-emerald-500 shadow",
- )}
- />
+ <div className="size-2 rounded-full border-2 border-white bg-blue-500" />
<MarkerLabel position="top">{dest.name}</MarkerLabel>
</MarkerContent>
</MapMarker>