World Map
World map web component: countries shaded by a value (choropleth), with keyboard reading, selection and a screen-reader table.
- 17.1 KB gzipped
- @lit-material/world-map 1.8.0
- Renders on the server
Example
World map
Countries shaded by a value. Hover, or focus the map and use the arrow keys, to read values highest first.
Visitors by country
Not on the map
Singapore: 18 visitorsMalta: 3 visitors
| Country | Value (visitors) |
|---|---|
| United States | 1,240 |
| Germany | 310 |
| United Kingdom | 260 |
| India | 240 |
| Brazil | 150 |
| France | 120 |
| Poland | 95 |
| Japan | 80 |
| Canada | 70 |
| Australia | 44 |
| Ukraine | 40 |
| Singapore | 18 |
| South Africa | 12 |
| Malta | 3 |
Selectable
Click a country, or press Enter on it, to filter by it; again clears. Picked: none
Not on the map
| Country | Value (visitors) |
|---|---|
| United States | 1,240 |
| Germany | 310 |
| United Kingdom | 260 |
| India | 240 |
| Brazil | 150 |
| France | 120 |
| Poland | 95 |
| Japan | 80 |
| Canada | 70 |
| Australia | 44 |
| Ukraine | 40 |
| Singapore | 18 |
| South Africa | 12 |
| Malta | 3 |
Install
npm install @lit-material/world-map @lit-material/tokens
import "@lit-material/world-map";
Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide
API
<lit-material-world-map>
A world map shaded by a value per country (a choropleth), e.g. visitors by country.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
data | data | CountryValues | {} | Values by country code (case-insensitive). Non-finite and negative values are left out. |
label | label | string | "" | The map's accessible name, e.g. "Visitors by country". Unset, "World map", translated. |
unit | unit | string | "" | A unit appended to values, e.g. "visitors". |
selectable | selectable | boolean | false | Countries can be selected with a click, Enter or Space; fires change. |
selected | selected | string | "" | The selected country's code, or "". |
format | property only | (n: number) => string | undefined | none | Formats values. Default: the element's language, compact above 10,000. |
Events
| Event | Description |
|---|---|
change | With selectable, a country was selected or the selection cleared. detail: { code, value }. |
CSS parts
| Part | Description |
|---|---|
map | The SVG. |
tooltip | The hover/focus readout. |
legend | The colour scale under the map. |
elsewhere | The list of countries too small to draw. |
CSS custom properties
| Property | Description |
|---|---|
--lit-material-world-map-fill | Colour of the highest value (default: the first chart series colour). |
--lit-material-world-map-empty | Colour of countries with no value. |
--lit-material-world-map-border | Colour of the borders between countries. |