Map Marker
terrae/markerFreeComponent
Customizable map markers with popup support.
Install it
npx shadcn@latest add https://www.terrae.dev/marker.jsonSource
1"use client"23import { createContext, useContext, useEffect, useRef, useState, type ReactNode } from "react"4import { createPortal } from "react-dom"5import type mapboxgl from "mapbox-gl"6import { mapgl } from "./map-library"7import { X } from "lucide-react"8import { cn } from "@/lib/utils"9import { useMap } from "./hooks"10import type { MapCoordinates, LngLatCoordinates } from "./types"1112type MarkerContextValue = {13 markerRef: React.RefObject<mapboxgl.Marker | null>14 markerElementRef: React.RefObject<HTMLDivElement | null>15 map: mapboxgl.Map | null16 // State triggers re-render when marker element is ready.17 // Refs don't cause re-renders, so children would see null without this.18 isMounted: boolean19}2021type MapMarkerProps = {22 coordinates: MapCoordinates23 children: ReactNode24 onClick?: (e: MouseEvent) => void25 onMouseEnter?: (e: MouseEvent) => void26 onMouseLeave?: (e: MouseEvent) => void27 onDragStart?: (lngLat: LngLatCoordinates) => void28 onDrag?: (lngLat: LngLatCoordinates) => void29 onDragEnd?: (lngLat: LngLatCoordinates) => void30 draggable?: boolean31 offset?: [number, number]32 rotation?: number33 rotationAlignment?: "map" | "viewport" | "auto"34 pitchAlignment?: "map" | "viewport" | "auto"35}3637type MarkerCallbacks = {38 onClick?: (e: MouseEvent) => void39 onMouseEnter?: (e: MouseEvent) => void40 onMouseLeave?: (e: MouseEvent) => void41 onDragStart?: (lngLat: LngLatCoordinates) => void42 onDrag?: (lngLat: LngLatCoordinates) => void43 onDragEnd?: (lngLat: LngLatCoordinates) => void44}4546type MarkerContentProps = {47 children?: ReactNode48 className?: string49}5051type MarkerPopupProps = {52 children: ReactNode53 className?: string54 closeButton?: boolean55 offset?: number | [number, number]56 maxWidth?: string57}5859type MarkerTooltipProps = {60 children: ReactNode61 className?: string62 offset?: number | [number, number]63 maxWidth?: string64}6566type MarkerLabelProps = {67 children: ReactNode68 className?: string69 position?: "top" | "bottom"70}7172type MarkerLabelPosition = "top" | "bottom"7374type MarkerStatusColor = "green" | "red" | "yellow" | "blue"7576type MarkerAvatarProps = {77 src: string78 alt: string79 size?: number80 online?: boolean81 statusColor?: MarkerStatusColor82 className?: string83}8485type MarkerAvatarPinProps = {86 src: string87 alt: string88 size?: number89 borderWidth?: number90 className?: string91}9293const DEFAULT_DRAGGABLE = false94const DEFAULT_CLOSE_BUTTON = false95const DEFAULT_POPUP_OFFSET = 1696const DEFAULT_TOOLTIP_OFFSET = 1697// … 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 |
