Geo Map
tool-ui/geo-mapFreeBlock
Display geolocated entities and fleet positions.
See it running
Open the demo on tool-ui
www.tool-ui.com/components/geo-mapInstall it
npx shadcn@latest add https://www.tool-ui.com/r/geo-map.jsonSource
1"use client";23import { memo, useEffect, useState } from "react";4import { cn } from "./_adapter";5import { GeoMapEngine } from "./geo-map-engine";6import styles from "./geo-map-theme.module.css";7import type { GeoMapProps, GeoMapStyle } from "./schema";89const LIGHT_TILE_URL =10 "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png";11const DARK_TILE_URL =12 "https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png";1314function getSystemTheme(): "light" | "dark" {15 if (typeof window === "undefined") return "light";16 return window.matchMedia?.("(prefers-color-scheme: dark)").matches17 ? "dark"18 : "light";19}2021function getDocumentTheme(): "light" | "dark" | null {22 if (typeof document === "undefined") return null;2324 const root = document.documentElement;25 const dataTheme = root.getAttribute("data-theme")?.toLowerCase();26 if (dataTheme === "dark") return "dark";27 if (dataTheme === "light") return "light";28 if (root.classList.contains("dark")) return "dark";29 if (root.classList.contains("light")) return "light";3031 return null;32}3334function useInheritedTheme(): "light" | "dark" {35 const [theme, setTheme] = useState<"light" | "dark">(() => {36 return getDocumentTheme() ?? getSystemTheme();37 });3839 useEffect(() => {40 if (typeof window === "undefined" || typeof document === "undefined") {41 return;42 }4344 const update = () => setTheme(getDocumentTheme() ?? getSystemTheme());4546 const mql = window.matchMedia?.("(prefers-color-scheme: dark)");47 mql?.addEventListener("change", update);4849 const observer = new MutationObserver(update);50 observer.observe(document.documentElement, {51 attributes: true,52 attributeFilter: ["class", "data-theme"],53 });5455 return () => {56 mql?.removeEventListener("change", update);57 observer.disconnect();58 };59 }, []);6061 return theme;62}6364function resolveMapAriaLabel(title?: string, description?: string): string {65 if (title && description) {66 return `${title}. ${description}`;67 }6869 return title ?? description ?? "Geographic map";70}7172export const GeoMap = memo(function GeoMap({73 id,74 role: _role,75 receipt: _receipt,76 title,77 description,78 markers,79 routes,80 clustering,81 viewport,82 showZoomControl = true,83 theme,84 className,85 style,86 tooltipClassName,87 popupClassName,88 onMarkerClick,89 onRouteClick,90}: GeoMapProps) {91 const inheritedTheme = useInheritedTheme();92 const resolvedTheme = theme ?? inheritedTheme;93// … truncated
What it pulls in
npm packages
Files it writes
More from tool-ui
All 27 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Approval Cardapproval-card | tool-ui | Blocks | Free | 2 deps · 11 files | |
| Audioaudio | tool-ui | Blocks | Free | 2 deps · 9 files | |
| Chartchart | tool-ui | Blocks | Free | 2 deps · 8 files | |
| Citationcitation | tool-ui | Blocks | Free | 2 deps · 15 files | |
| Code Blockcode-block | tool-ui | Blocks | Free | 3 deps · 11 files | |
| Code Diffcode-diff | tool-ui | Blocks | Free | 3 deps · 10 files | |
| Data Tabledata-table | tool-ui | Blocks | Free | 1 dep · 17 files | |
| Imageimage | tool-ui | Blocks | Free | 1 dep · 14 files |
