Map
nordaun-ui/mapFreeBlock
A modular context-based map with built in controls such as projection, zoom, rotation and fullscreen.
Live preview
live · rendered by the registry
Rendered by @nordaun/ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.nordaun.com/r/map.jsonSource
1"use client";23import {4 MapLibreMap,5 MapOptions,6 Marker,7 MarkerOptions,8 Popup,9 PopupOptions,10 StyleSpecification,11} from "maplibre-gl";12import "maplibre-gl/dist/maplibre-gl.css";13import * as React from "react";14import { createPortal } from "react-dom";1516import { Button } from "@/components/ui/button";17import { ButtonGroup } from "@/components/ui/button-group";18import { Loading } from "@/components/ui/loading";19import { cn } from "@/lib/utils";20import {21 ChevronDown,22 ChevronUp,23 Globe,24 Loader2,25 Locate,26 Map as MapIcon,27 MapPin,28 Maximize,29 Minimize,30 Minus,31 Plus,32} from "lucide-react";3334type Theme = "light" | "dark";35type Coordinate = { latitude: number; longitude: number };36type Projection = "mercator" | "globe";37type Style = string | StyleSpecification;3839const defaultStyles: Record<Theme, Style> = {40 light: "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",41 dark: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json",42};4344function getDocumentTheme(): Theme | null {45 if (typeof document === "undefined") return null;46 if (document.documentElement.classList.contains("dark")) return "dark";47 if (document.documentElement.classList.contains("light")) return "light";48 return null;49}5051function getSystemTheme(): Theme {52 if (typeof window === "undefined") return "light";53 return window.matchMedia("(prefers-color-scheme: dark)").matches54 ? "dark"55 : "light";56}5758function useTheme(defaultTheme?: Theme): Theme {59 const [theme, setTheme] = React.useState<Theme>(60 () => getDocumentTheme() ?? getSystemTheme(),61 );6263 React.useEffect(() => {64 if (defaultTheme) return;6566 const observer = new MutationObserver(() => {67 const docTheme = getDocumentTheme();68 if (docTheme) setTheme(docTheme);69 });7071 observer.observe(document.documentElement, {72 attributes: true,73 attributeFilter: ["class"],74 });7576 const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");77 const handleSystemChange = (e: MediaQueryListEvent) => {78 if (!getDocumentTheme()) setTheme(e.matches ? "dark" : "light");79 };80 mediaQuery.addEventListener("change", handleSystemChange);8182 return () => {83 observer.disconnect();84 mediaQuery.removeEventListener("change", handleSystemChange);85 };86 }, [defaultTheme]);8788 return defaultTheme ?? theme;89}9091type MapContext = {92// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from @nordaun/ui
All 8 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Audioaudio | @nordaun/ui | Blocks | Free | 1 dep | |
| Filefile | @nordaun/ui | Blocks | Free | 1 dep · 3 files | |
| Flagflag | @nordaun/ui | Blocks | Free | no deps · 2 files | |
| Loadingloading | @nordaun/ui | Blocks | Free | no deps | |
| Passwordpassword | @nordaun/ui | Blocks | Free | 1 dep | |
| Phonephone | @nordaun/ui | Blocks | Free | 2 deps · 3 files | |
| Videovideo | @nordaun/ui | Blocks | Free | 1 dep · 2 files |
