Map Radar
terrae/radarFreeComponent
Animated radar sweep signal overlay on map coordinates.
Install it
npx shadcn@latest add https://www.terrae.dev/radar.jsonSource
1"use client"23import { useEffect, useId, useRef, useState } from "react"4import { createPortal } from "react-dom"5import { mapgl } from "./map-library"6import { useMap } from "./hooks"7import type { MapCoordinates } from "./types"89type RgbColor = { r: number; g: number; b: number }1011type MapRadarProps = {12 coordinates: MapCoordinates13 size?: number14 color?: string15 gridColor?: string16 backgroundColor?: string17 duration?: number18 rings?: number19 showCrosshairs?: boolean20 pitchAlignment?: "map" | "viewport" | "auto"21}2223type RadarContentProps = {24 instanceId: string25 size: number26 color: string27 gridColor: string28 backgroundColor: string29 duration: number30 rings: number31 showCrosshairs: boolean32}3334type RadarGridProps = {35 radius: number36 gridColor: string37 rings: number38 showCrosshairs: boolean39}4041type RadarSweepProps = {42 instanceId: string43 radius: number44 color: string45 duration: number46}4748type SweepGradientProps = {49 radius: number50 sweepRadius: number51 rgb: RgbColor52}5354type SweepSegmentProps = {55 radius: number56 sweepRadius: number57 rgb: RgbColor58 segmentIndex: number59}6061const DEFAULT_SIZE = 20062const DEFAULT_COLOR = "rgba(0, 255, 70, 1)"63const DEFAULT_GRID_COLOR = "rgba(0, 255, 70, 0.3)"64const DEFAULT_BACKGROUND_COLOR = "rgba(0, 20, 0, 0.8)"65const DEFAULT_DURATION = 200066const DEFAULT_RINGS = 467const DEFAULT_CROSSHAIRS = true68const DEFAULT_PITCH_ALIGNMENT = "map" as const69const SWEEP_SEGMENT_COUNT = 2070const SWEEP_ARC = Math.PI / 2.57172const createMarker = (73 map: mapboxgl.Map,74 container: HTMLDivElement,75 coordinates: MapCoordinates,76 pitchAlignment: "map" | "viewport" | "auto"77) => {78 return new mapgl.Marker({79 element: container,80 anchor: "center",81 pitchAlignment,82 })83 .setLngLat(coordinates)84 .addTo(map)85}8687export const MapRadar = ({88 coordinates,89 size = DEFAULT_SIZE,90 color = DEFAULT_COLOR,91 gridColor = DEFAULT_GRID_COLOR,92 backgroundColor = DEFAULT_BACKGROUND_COLOR,93 duration = DEFAULT_DURATION,94 rings = DEFAULT_RINGS,95 showCrosshairs = DEFAULT_CROSSHAIRS,96 pitchAlignment = DEFAULT_PITCH_ALIGNMENT,97}: MapRadarProps) => {98 const { map, isLoaded } = useMap()99 const instanceId = useId()100 const markerRef = useRef<mapboxgl.Marker | null>(null)101 const containerRef = useRef<HTMLDivElement | null>(null)102 const [isMounted, setIsMounted] = useState(false)103104 useEffect(() => {105 if (!map || !isLoaded) {106 return107 }108109 const container = document.createElement("div")110// … 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 |
