Kumo Svelte
  • Home
  • Installation
  • Colors
  • Accessibility
  • Changelog
  • Autocomplete
  • Badge
  • Banner
  • Breadcrumbs
  • Button
  • Checkbox
  • Clipboard Text
  • Cloudflare Logo
  • CodeHighlighted
  • Collapsible
  • Combobox
  • Command Palette
  • Date Picker
  • Dialog
  • Dropdown
  • Empty
  • Flow
  • Grid
  • Input
  • InputArea
  • InputGroup
  • Label
  • Layer Card
  • Link
  • Loader
  • MenuBar
  • Meter
  • Pagination
  • Popover
  • Radio
  • Select
  • Sensitive Input
  • Sidebar
  • Skeleton Line
  • Switch
  • Table
  • Table of Contents
  • Tabs
  • Text
  • Toast
  • Toolbar
  • Tooltip
  • Charts
  • Colors
  • Timeseries
  • Maps
  • Sankey
  • Custom Chart
  • Page Header
  • Resource List
  • Delete Resource
Maps
kumo-svelte

Maps

Map chart components for visualizing geographic data with GeoJSON.

<script lang="ts">
  import { mode } from "mode-watcher";
  import { BubbleMap, type MapGeoJson } from "kumo-svelte/components/chart";
  import { echarts } from "../chart-echarts";

  interface Props {
    geoJson: MapGeoJson | null;
  }

  let { geoJson }: Props = $props();
  let isDarkMode = $derived(mode.current === "dark");

  const data = [
    { city: "San Jose", requests: 1820000, longitude: -121.9, latitude: 37.3 },
    { city: "Ashburn", requests: 1240000, longitude: -77.5, latitude: 39.0 },
    { city: "London", requests: 980000, longitude: -0.1, latitude: 51.5 },
    { city: "Singapore", requests: 760000, longitude: 103.8, latitude: 1.3 },
    { city: "São Paulo", requests: 520000, longitude: -46.6, latitude: -23.5 },
  ];
</script>

{#if geoJson}
  <BubbleMap
    {echarts}
    {geoJson}
    {data}
    lng="longitude"
    lat="latitude"
    name="city"
    value="requests"
    {isDarkMode}
    valueFormat={(value) => `${(value / 1_000_000).toFixed(1)}M requests`}
  />
{/if}

Installation

BubbleMap requires echarts as a peer dependency. Consumers provide the GeoJSON feature collection; the component does not fetch map data or use map tiles.

pnpm add echarts

Import

Register the ECharts map, scatter, tooltip, geo, and renderer modules before rendering the component.

import { MapChart, ScatterChart } from "echarts/charts";
import { GeoComponent, TooltipComponent } from "echarts/components";
import * as echarts from "echarts/core";
import { CanvasRenderer } from "echarts/renderers";

echarts.use([MapChart, ScatterChart, GeoComponent, TooltipComponent, CanvasRenderer]);
import { BubbleMap } from "kumo-svelte/components/chart";

Usage

<script lang="ts">
  import { BubbleMap } from "kumo-svelte/components/chart";
  import { echarts } from "./chart-echarts";

  const data = [{ city: "London", requests: 980000, longitude: -0.1, latitude: 51.5 }];
</script>

<BubbleMap
  {echarts}
  geoJson={world}
  {data}
  lng="longitude"
  lat="latitude"
  name="city"
  value="requests"
/>

Examples

Bubble Map

Plot raw rows by longitude and latitude. The value accessor controls proportional bubble size.

<script lang="ts">
  import { mode } from "mode-watcher";
  import { BubbleMap, type MapGeoJson } from "kumo-svelte/components/chart";
  import { echarts } from "../chart-echarts";

  interface Props {
    geoJson: MapGeoJson | null;
  }

  let { geoJson }: Props = $props();
  let isDarkMode = $derived(mode.current === "dark");

  const data = [
    { city: "San Jose", requests: 1820000, longitude: -121.9, latitude: 37.3 },
    { city: "Ashburn", requests: 1240000, longitude: -77.5, latitude: 39.0 },
    { city: "London", requests: 980000, longitude: -0.1, latitude: 51.5 },
    { city: "Singapore", requests: 760000, longitude: 103.8, latitude: 1.3 },
    { city: "São Paulo", requests: 520000, longitude: -46.6, latitude: -23.5 },
  ];
</script>

{#if geoJson}
  <BubbleMap
    {echarts}
    {geoJson}
    {data}
    lng="longitude"
    lat="latitude"
    name="city"
    value="requests"
    {isDarkMode}
    valueFormat={(value) => `${(value / 1_000_000).toFixed(1)}M requests`}
  />
{/if}

Custom Tooltips

Provide tooltipFormatter when the default name/value tooltip is not enough. The formatter returns HTML rendered by ECharts, so escape user-provided values.

<BubbleMap
  {echarts}
  geoJson={map}
  {data}
  lng="longitude"
  lat="latitude"
  name="city"
  value="requests"
  tooltipFormatter={(row) =>
    `<strong>${row.city}</strong><br>${row.requests.toLocaleString()} requests`}
/>

API Reference

PropTypeDescription
echartstypeof echartsRegistered ECharts module instance.
geoJsonMapGeoJsonGeoJSON FeatureCollection used as the land base.
dataT[]Raw data rows.
lng / latMapAccessor<T, number>Longitude and latitude accessors.
valueMapAccessor<T, number>Value accessor used for bubble sizing.
nameMapAccessor<T, string>Optional label accessor used by the default tooltip.
mapNamestringOptional stable ECharts map registry name.
minRadius / maxRadiusnumberBubble radius range in pixels.
bubbleSize(value: number) => numberCustom bubble radius function.
bubbleColorMapStyle<T, string>Bubble fill color or row callback.
bubbleBorderColorMapStyle<T, string>Bubble border color or row callback.
bubbleBorderWidthMapStyle<T, number>Bubble border width or row callback.
center[number, number]Optional map center as [longitude, latitude].
zoomnumberInitial map zoom.
roambooleanEnables drag-to-pan and scroll-to-zoom.
showTooltipbooleanShows the default tooltip.
valueFormat(value: number) => stringFormats values in the default tooltip.
tooltipFormatter(row: T) => stringCustom tooltip HTML. Sanitize user-provided content before returning it.
onBubbleHover(row: T \| undefined) => voidCalled when the pointer enters or leaves a bubble.
onBubbleClick(row: T) => voidCalled when a bubble is clicked.
heightnumberChart height in pixels.
isDarkModebooleanUses the dark chart palette.
refECharts \| nullBindable chart instance.

On this page

  • Installation
  • Import
  • Usage
  • Examples
    • Bubble Map
    • Custom Tooltips
  • API Reference