Map Mini Map
terrae/mini-mapFreeComponent
Minimap overview navigation component.
Install it
npx shadcn@latest add https://www.terrae.dev/mini-map.jsonSource
1"use client"23import { useEffect, useRef, useState, useCallback } from "react"4import { useTheme } from "next-themes"5import type mapboxgl from "mapbox-gl"6import { mapgl } from "./map-library"7import { useMap } from "./hooks"8import { cn } from "@/lib/utils"9import { defaultMapStyles, defaultMapLibreStyles, type MapThemeStyles } from "./types"1011type MapMiniMapProps = {12 position?: "top-left" | "top-right" | "bottom-left" | "bottom-right"13 width?: number14 height?: number15 zoomOffset?: number16 style?: string17 styles?: MapThemeStyles18 boxColor?: string19 boxBorderWidth?: number20 rounded?: number | "full" | "none"21 draggable?: boolean22}2324const DEFAULT_BORDER_RADIUS = 82526type Position = { x: number; y: number }2728export function MapMiniMap({29 position = "bottom-right",30 width = 200,31 height = 150,32 zoomOffset = -4,33 style,34 styles,35 boxColor = "#3b82f6",36 boxBorderWidth = 2,37 rounded = DEFAULT_BORDER_RADIUS,38 draggable = false,39}: MapMiniMapProps) {40 const { map: mainMap, isLoaded, library } = useMap()41 const { resolvedTheme } = useTheme()42 const containerRef = useRef<HTMLDivElement>(null)43 const wrapperRef = useRef<HTMLDivElement>(null)44 const miniMapRef = useRef<mapboxgl.Map | null>(null)45 const [miniMapLoaded, setMiniMapLoaded] = useState(false)46 const [dragPosition, setDragPosition] = useState<Position | null>(null)47 const isDraggingRef = useRef(false)48 const dragStartRef = useRef<Position>({ x: 0, y: 0 })49 const positionStartRef = useRef<Position>({ x: 0, y: 0 })5051 const positionClasses = {52 "top-left": "top-4 left-4",53 "top-right": "top-4 right-4",54 "bottom-left": "bottom-4 left-4",55 "bottom-right": "bottom-4 right-4",56 }5758 const getMapStyle = () => {59 if (style) {60 return style61 }62 const defaults = library === "maplibre" ? defaultMapLibreStyles : defaultMapStyles63 if (styles) {64 const darkStyle = styles.dark ?? defaults.dark65 const lightStyle = styles.light ?? defaults.light66 return resolvedTheme === "dark" ? darkStyle : lightStyle67 }68 return resolvedTheme === "dark" ? defaults.dark : defaults.light69 }7071 const addViewportBox = (miniMap: mapboxgl.Map) => {72 miniMap.addSource("viewport-box", {73 type: "geojson",74 data: {75 type: "Feature",76 properties: {},77 geometry: { type: "Polygon", coordinates: [[]] },78 },79 })8081 miniMap.addLayer({82 id: "viewport-box-fill",83 type: "fill",84 source: "viewport-box",85// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from terrae
All 40 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Map Animated Circleanimated-circle | terrae | Components | Free | 1 dep | |
| Map Animated Footprintanimated-footprint | terrae | Components | Free | 2 deps | |
| Map Animated Polygonanimated-polygon | terrae | Components | Free | 1 dep | |
| Map Animated Pulseanimated-pulse | terrae | Components | Free | 1 dep | |
| Map Arc Animatedarc-animated | terrae | Components | Free | 1 dep | |
| Map Blur Areablur-area | terrae | Components | Free | 1 dep | |
| Map Camera Followcamera-follow | terrae | Components | Free | 1 dep | |
| Map Choroplethchoropleth | terrae | Components | Free | 1 dep |
