# GeoJSON Map

> Spatial geographic boundary paths mapping data values to map regions.

A shadcn/ui block from the [@pacekit](https://ui.pacekit.dev/?utm_source=shadcn.exchange) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/pacekit/tanstack-charts-geojson-map).

- Page, with a live preview: https://shadcn.exchange/r/pacekit/tanstack-charts-geojson-map
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/pacekit/tanstack-charts-geojson-map-light-8949c37bb5d5ac6b.png
- Registry item: https://ui.pacekit.dev/r/tanstack-charts-geojson-map.json
- Listed: 2026-10-21, source last changed 2026-10-21

## Install

```bash
npx shadcn@latest add https://shadcn.exchange/r/pacekit/tanstack-charts-geojson-map.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `@tanstack/charts`, `@tanstack/react-charts`, `d3-geo`
- Registry items: `card`

## Files

### `components/tanstack-charts/area/geojson-map.tsx`

```tsx
import { type ChartPoint, defineChart } from "@tanstack/charts";
import { geoShape } from "@tanstack/charts/geo";
import { motion } from "@tanstack/charts/motion";
import { tooltip } from "@tanstack/charts/tooltip";
import { Chart } from "@tanstack/react-charts/core";
import { useMemo } from "react";

import { geoIdentity } from "d3-geo";
import { Map } from "lucide-react";

import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";

interface GeoFeature {
    type: "Feature";
    properties: {
        id: string;
        name: string;
        type: string;
    };
    geometry: {
        type: "Polygon";
        coordinates: number[][][];
    };
}

const motionRenderer = motion({
    initial: "always",
    transition: { type: "spring", stiffness: 170, damping: 18, mass: 1 },
});

function generateDemoData(): { type: "FeatureCollection"; features: GeoFeature[] } {
    const features: GeoFeature[] = [
        {
            type: "Feature",
            properties: { id: "room-1", name: "Main Hall", type: "reception" },
            geometry: {
                type: "Polygon",
                coordinates: [
                    [
                        [10, 10],
                        [50, 10],
                        [50, 40],
                        [10, 40],
                        [10, 10],
                    ],
                ],
            },
        },
        {
            type: "Feature",
            properties: { id: "room-2", name: "Conference Room A", type: "meeting" },
            geometry: {
                type: "Polygon",
                coordinates: [
                    [
                        [55, 10],
                        [90, 10],
                        [90, 40],
                        [55, 40],
                        [55, 10],
                    ],
                ],
            },
        },
        {
            type: "Feature",
            properties: { id: "room-3", name: "Executive Suite", type: "office" },
            geometry: {
                type: "Polygon",
                coordinates: [
                    [
                        [10, 45],
                        [45, 45],
                        [45, 80],
                        [10, 80],
                        [10, 45],
                    ],
                ],
            },
        },
        {
            type: "Feature",
            properties: { id: "room-4", name: "Engineering Hub", type: "workspace" },
            geometry: {
                type: "Polygon",
                coordinates: [
                    [
                        [50, 45],
                        [90, 45],
                        [90, 80],
                        [50, 80],
                        [50, 45],
                    ],
                ],
            },
        },
    ];

    return { type: "FeatureCollection", features };
}

function shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {
    if (points.length === 0) return { title: "", rows: [] };
    const feature = points[0].datum as GeoFeature;
    if (!feature || !feature.properties) return { title: "", rows: [] };
    return {
        title: feature.properties.name,
        rows: [
            { label: "Zone Type", value: feature.properties.type, color: "var(--chart-1)" },
            { label: "ID", value: feature.properties.id, color: "var(--foreground)" },
        ],
    };
}

export function GeojsonMap() {
    const geoData = useMemo(() => generateDemoData(), []);

    const definition = useMemo(
        () =>
            defineChart(
                {
                    renderer: motionRenderer,
                    marks: [
                        geoShape(geoData.features, {
                            key: (feature: GeoFeature) => feature.properties.id,
                            projection: {
                                type: geoIdentity,
                                fit: geoData,
                            },
                            fill: "var(--chart-1)",
                            fillOpacity: 0.25,
                            stroke: "var(--chart-1)",
                            strokeWidth: 2,
                        }),
                    ],
                    scales: {
                        x: null,
                        y: null,
                    },
                    margin: 16,
                    theme: {
                        foreground: "var(--muted-foreground)",
                        grid: "var(--border)",
                        background: "transparent",
                    },
                },
                {
                    keyboard: true,
                    tooltip: {
                        use: tooltip,
                        className:
                            "font-sans shadow-none rounded-md bg-popover text-popover-foreground border p-2 text-xs",
                        anchor: "pointer",
                        placement: "auto",
                        content: (points) => shadcnTooltipContent(points),
                    },
                },
            ),
        [geoData],
    );

    return (
        <Card className="w-full max-w-xl">
            <CardHeader>
                <CardTitle>GeoJSON Architectural Plan</CardTitle>
                <CardDescription>Spatial polygon projection mapping for venue floor layouts</CardDescription>
            </CardHeader>
            <CardContent>
                <div className="h-[250px] w-full">
                    <Chart
                        definition={definition}
                        renderer={motionRenderer}
                        height={250}
                        ariaLabel="GeoJSON Architectural Plan Chart"
                    />
                </div>
            </CardContent>
            <CardFooter className="flex-col items-start gap-2 text-sm">
                <div className="flex items-center gap-2 leading-none font-medium">
                    4 spatial zones rendered with d3 identity projection <Map className="h-4 w-4 text-emerald-500" />
                </div>
                <div className="text-muted-foreground leading-none">
                    Custom GeoJSON feature collection mapped to SVG paths
                </div>
            </CardFooter>
        </Card>
    );
}

export default GeojsonMap;
```
