Heatmap
mapcn/heatmapFreeBlock
Globe-projected heatmap visualizing earthquake density with zoom-dependent styling.
Install it
npx shadcn@latest add https://mapcn.dev/r/heatmap.jsonSource
1"use client";23import { useEffect, useId } from "react";45import { Map, useMap } from "@/components/ui/map";67const EARTHQUAKE_GEOJSON_URL =8 "https://maplibre.org/maplibre-gl-js/docs/assets/earthquakes.geojson";910const HEATMAP_GRADIENT_COLORS = [11 "#fff7bc",12 "#fee391",13 "#fec44f",14 "#fe9929",15 "#d7301f",16];1718const HEATMAP_COLOR_STOPS: [number, string][] = [19 [0.15, HEATMAP_GRADIENT_COLORS[0]],20 [0.35, HEATMAP_GRADIENT_COLORS[1]],21 [0.55, HEATMAP_GRADIENT_COLORS[2]],22 [0.75, HEATMAP_GRADIENT_COLORS[3]],23 [1, HEATMAP_GRADIENT_COLORS[4]],24];2526function GlobeHeatmapLayers() {27 const { map, isLoaded } = useMap();28 const id = useId();29 const sourceId = `heatmap-source-${id}`;30 const heatLayerId = `heatmap-layer-${id}`;31 const pointLayerId = `heatmap-point-layer-${id}`;3233 useEffect(() => {34 if (!map || !isLoaded) return;3536 if (!map.getSource(sourceId)) {37 map.addSource(sourceId, {38 type: "geojson",39 data: EARTHQUAKE_GEOJSON_URL,40 });41 }4243 if (!map.getLayer(heatLayerId)) {44 map.addLayer({45 id: heatLayerId,46 type: "heatmap",47 source: sourceId,48 maxzoom: 6,49 paint: {50 "heatmap-weight": [51 "interpolate",52 ["linear"],53 ["get", "mag"],54 0,55 0,56 6,57 0.8,58 ],59 "heatmap-intensity": [60 "interpolate",61 ["linear"],62 ["zoom"],63 0,64 0.55,65 6,66 1.25,67 ],68 "heatmap-color": [69 "interpolate",70 ["linear"],71 ["heatmap-density"],72 0,73 "rgba(59, 130, 246, 0)",74 ...HEATMAP_COLOR_STOPS.flat(),75 ],76 "heatmap-radius": ["interpolate", ["linear"], ["zoom"], 0, 8, 6, 34],77 "heatmap-opacity": [78 "interpolate",79 ["linear"],80 ["zoom"],81 4.5,82 0.75,83 6.5,84 0.08,85 ],86 },87 });88 }8990 if (!map.getLayer(pointLayerId)) {91 map.addLayer({92 id: pointLayerId,93 type: "circle",94 source: sourceId,95 minzoom: 4.5,96 paint: {97 "circle-radius": [98 "interpolate",99 ["linear"],100 ["get", "mag"],101 1,102 3,103 6,104 10,105 ],106 "circle-color": [107 "interpolate",108 ["linear"],109// … truncated
What it pulls in
Other registry items
Files it writes
More from mapcn
All 9 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Analytics Cardanalytics-card | mapcn | Blocks | Free | 1 dep · 2 files | |
| Analytics Mapanalytics-map | mapcn | Blocks | Free | 2 deps · 4 files | |
| Choroplethchoropleth | mapcn | Blocks | Free | 2 deps · 3 files | |
| Delivery Trackerdelivery-tracker | mapcn | Blocks | Free | 1 dep · 2 files | |
| Logistics Networklogistics-network | mapcn | Blocks | Free | 1 dep · 4 files | |
| Store Locatorstore-locator | mapcn | Blocks | Free | 1 dep · 4 files | |
| Uptime Monitoruptime-monitor | mapcn | Blocks | Free | 1 dep · 4 files |
