Map Image
terrae/imageFreeComponent
Image overlay layers on the map.
Install it
npx shadcn@latest add https://www.terrae.dev/image.jsonSource
1"use client"23import { useEffect, useRef } from "react"4import { useMap } from "./hooks"5import type { MapImageCorners } from "./types"67type MapImageProps = {8 id: string9 url: string10 coordinates: MapImageCorners11 opacity?: number12}1314export const MapImage = ({ id, url, coordinates, opacity = 1 }: MapImageProps) => {15 const { map, isLoaded } = useMap()16 const initializedRef = useRef(false)1718 useEffect(() => {19 if (!map || !isLoaded || initializedRef.current) return2021 const sourceId = `${id}-source`22 const layerId = `${id}-layer`2324 map.addSource(sourceId, {25 type: "image",26 url,27 coordinates,28 })2930 map.addLayer({31 id: layerId,32 type: "raster",33 source: sourceId,34 paint: {35 "raster-opacity": opacity,36 },37 })3839 initializedRef.current = true4041 return () => {42 if (map) {43 try {44 if (map.getLayer && map.getLayer(layerId)) map.removeLayer(layerId)45 if (map.getSource && map.getSource(sourceId)) map.removeSource(sourceId)46 } catch {47 // Silently handle cleanup errors48 }49 }50 initializedRef.current = false51 }52 }, [map, isLoaded, id, url, coordinates, opacity])5354 return null55}
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 |
