πŸ—ΊοΈ

GeoChoropleth

Color-coded regions based on data values like population or sales

πŸ”΅

GeoBubbleMap

Sized circles at geographic locations proportional to values

πŸ“Š

GeoSpikeMap

Vertical spikes showing magnitude at locations for 3D effect

GeoChoropleth - UK Regions

Hover over regions to see details. Click to select. Toggle between population and sales data.

1.9 9.3

Usage Examples

<script>
  import GeoChoropleth from '$lib/components/GeoChoropleth.svelte';
  import { FALLBACK_UK_REGION_DATA, GEO_COLOR_SCALES } from '$lib/constants';

  // geojson loaded from server or API
  let { data } = $props();

  function handleClick(region) {
    console.log('Selected:', region.name, region.value);
  }
</script>

<GeoChoropleth
  geojson={data.geojson}
  data={FALLBACK_UK_REGION_DATA}
  colorScale={{ type: 'sequential', colors: GEO_COLOR_SCALES.blues }}
  height={500}
  showLegend={true}
  showTooltip={true}
  onRegionClick={handleClick}
/>

Data Formats

GeoRegionData (Choropleth)

interface GeoRegionData {
  regionId: string;  // Matches GeoJSON feature ID
  value: number;     // Data value for coloring
  label?: string;    // Optional tooltip label
}

// Example:
{ regionId: 'E12000007', value: 8.80, label: 'London' }

GeoDataPoint (Bubble/Spike)

interface GeoDataPoint {
  id: string;        // Unique identifier
  name: string;      // Location name
  lat: number;       // Latitude
  long: number;      // Longitude
  value: number;     // Data value (size/height)
  category?: string; // Optional category
  color?: string;    // Optional custom color
}

// Example:
{ id: 'london', name: 'London', lat: 51.5074, long: -0.1278, value: 8982 }

Component Comparison

FeatureGeoChoroplethGeoBubbleMapGeoSpikeMap
Best ForRegional dataPoint magnitudesDramatic visual impact
Data TypeRegions (polygons)Points (lat/long)Points (lat/long)
Value EncodingFill colorCircle areaSpike height
Background MapRequiredOptionalOptional
Tooltipsβœ…βœ…βœ…
Click Eventsβœ…βœ…βœ…
LabelsVia tooltipβœ… On large bubblesVia tooltip
Legendβœ… Color gradientβœ… Size comparisonβœ… Height comparison

Dependencies

These components use LayerChart for SVG rendering and D3 for projections and scales.

bun add layerchart

LayerChart includes D3 geo/scale dependencies. No additional packages required.