expanded-map
jolyui-ui/expanded-mapFreeComponent
jolyui/ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by jolyui/ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://jolyui.dev/r/expanded-map.jsonSource
1"use client";23import {4 AnimatePresence,5 motion,6 useMotionValue,7 useSpring,8 useTransform,9} from "motion/react";10import NextImage from "next/image";11import type React from "react";12import { useEffect, useMemo, useRef, useState } from "react";1314interface LocationMapProps {15 /** Location name to display */16 location?: string;17 /** Latitude coordinate */18 latitude?: number;19 /** Longitude coordinate */20 longitude?: number;21 /** Zoom level for the map (1-18) */22 zoom?: number;23 /** Additional CSS classes */24 className?: string;25 /** Map tile provider */26 tileProvider?: "openstreetmap" | "carto-light" | "carto-dark";27}2829// Convert lat/lng to tile coordinates30function latLngToTile(lat: number, lng: number, zoom: number) {31 const n = 2 ** zoom;32 const x = Math.floor(((lng + 180) / 360) * n);33 const latRad = (lat * Math.PI) / 180;34 const y = Math.floor(35 ((1 - Math.log(Math.tan(latRad) + 1 / Math.cos(latRad)) / Math.PI) / 2) * n,36 );37 return { x, y };38}3940// Get tile URL based on provider41function getTileUrl(provider: string, x: number, y: number, z: number) {42 switch (provider) {43 case "carto-light":44 return `https://cartodb-basemaps-a.global.ssl.fastly.net/light_all/${z}/${x}/${y}.png`;45 case "carto-dark":46 return `https://cartodb-basemaps-a.global.ssl.fastly.net/dark_all/${z}/${x}/${y}.png`;47 default:48 return `https://tile.openstreetmap.org/${z}/${x}/${y}.png`;49 }50}5152// Format coordinates for display53function formatCoordinates(lat: number, lng: number) {54 const latDir = lat >= 0 ? "N" : "S";55 const lngDir = lng >= 0 ? "E" : "W";56 return `${Math.abs(lat).toFixed(4)}° ${latDir}, ${Math.abs(lng).toFixed(4)}° ${lngDir}`;57}5859export function LocationMap({60 location = "San Francisco, CA",61 latitude = 37.7749,62 longitude = -122.4194,63 zoom = 14,64 className,65 tileProvider = "carto-light",66}: LocationMapProps) {67 const [isHovered, setIsHovered] = useState(false);68 const [isExpanded, setIsExpanded] = useState(false);69 const [tilesLoaded, setTilesLoaded] = useState(false);70 const containerRef = useRef<HTMLDivElement>(null);7172 const mouseX = useMotionValue(0);73 const mouseY = useMotionValue(0);7475 const rotateX = useTransform(mouseY, [-50, 50], [8, -8]);76 const rotateY = useTransform(mouseX, [-50, 50], [-8, 8]);7778 const springRotateX = useSpring(rotateX, { stiffness: 300, damping: 30 });79 const springRotateY = useSpring(rotateY, { stiffness: 300, damping: 30 });8081 const coordinates = useMemo(82// … truncated
What it pulls in
npm packages
Files it writes
More from jolyui/ui
All 199 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-prompt-boxai-prompt-box | jolyui/ui | Components | Free | 4 deps | |
| animated-beamanimated-beam | jolyui/ui | Components | Free | 1 dep | |
| animated-tableanimated-table | jolyui/ui | Components | Free | 2 deps | |
| animated-theme-toggleanimated-theme-toggle | jolyui/ui | Components | Free | 2 deps | |
| animated-toastanimated-toast | jolyui/ui | Components | Free | 2 deps | |
| animated-tooltipanimated-tooltip | jolyui/ui | Components | Free | 1 dep | |
| bento-gridbento-grid | jolyui/ui | Components | Free | no deps | |
| buttonbutton | jolyui/ui | Components | Free | 3 deps |
