Leaflet & OpenStreetMap
Leaflet is the lightweight alternative engine behind
<x-wirekit::map>. It renders raster tiles (pre-rendered
image tiles from a provider), is tiny (~40 KB), and is distributed under the
BSD-2-Clause license. Like MapLibre, it is a peer dependency — you load it;
WireKit never bundles it.
Its classic pairing is OpenStreetMap (OSM): a free, crowd-sourced map of the world. OSM is not a JavaScript library — it is a tile source (and the underlying map data) that an engine renders. The two are different layers of the same map: Leaflet draws, OSM supplies the imagery. That's why this page covers them together — install the engine first, then point it at the tiles.
This guide covers the Leaflet engine and the OpenStreetMap tile source. For the marker model, the accessible list, the props, and Livewire wiring — all engine-independent — see the Map overview. OSM gives you free, detailed, worldwide street tiles with no API key — ideal for prototypes and low-traffic sites; for production scale, read OSM Usage Policy & Cost below before you ship.
Install
# 1. Install Leaflet (a peer dependency — not bundled by WireKit).
npm install leaflet
Then load the engine in your layout — order matters, WireKit's glue looks for it at Alpine init:
<!-- 2. Load Leaflet's JS + CSS BEFORE @wirekitScripts so window.L exists
when WireKit's map glue initializes. -->
<link href="https://unpkg.com/leaflet/dist/leaflet.css" rel="stylesheet" />
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
@wirekitScripts
Then set provider="leaflet" on the component. Once window.L is present, the
map upgrades from the marker-list fallback to a live Leaflet canvas.
Tiles & Attribution
Leaflet needs a raster tile source — point styleUrl at a tile-URL template
(the {z}/{x}/{y} placeholders are the zoom/column/row). For OpenStreetMap
that's the standard template below; whatever source you pick, pass its required
credit via attribution:
<x-wirekit::map
provider="leaflet"
style-url="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution="© OpenStreetMap contributors"
:center="[52.52, 13.405]"
:zoom="12"
:markers="$stores"
/>
OpenStreetMap's tile policy requires a visible © OpenStreetMap contributors
credit on every map. A linked credit is best practice:
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
The attribution prop is not optional for most tile sources. Omitting the
OpenStreetMap credit violates the OSM tile usage policy and the ODbL data
license — your tile access can be blocked without notice. Commercial
providers have their own mandatory attribution. Never ship a tiled map
without it.
Store Locator
A multi-marker Leaflet map over OpenStreetMap tiles — every location is a marker on the canvas and a focusable row in the accessible list.
Interactive map needs a map library — the locations are listed alongside.
The intent on each marker colors both its list dot and — once a map engine is
loaded — the map pin itself; hovering a pin shows the store name with its opening
hours (the body line). The status word in each label carries the meaning, so the
locator never relies on color alone. This demo also opts into the fill selection
highlight (highlight="fill" highlight-color="success") — click a store to see
the tinted-tile alternative to the default ring frame.
Pin Tooltips
Pin tooltips work the same on Leaflet as on MapLibre — the bubble content follows the marker's data shape, with no extra configuration:
- Text only — just a
label: a single bold line. - Styled text —
label+body: a small card with the name on top and a muted detail line (address, opening hours) below. - Text with photo — add an
imageURL: the photo renders as a card above the text, like showing the storefront at its location. - Photo only —
image+tooltip: 'image': the bubble is just the photo; the label still names the pin for screen readers and stays in the marker list.
Sanitize image URLs you don't control — the adapter escapes the src.
Interactive map needs a map library — the locations are listed alongside.
Street-Level Locations
OSM tiles carry full street detail at high zoom, so several locations across a city read clearly. Every marker is a list entry too — the accessible companion.
Interactive map needs a map library — the locations are listed alongside.
Map Only
Drop the sidebar with list="false" for a clean Leaflet canvas — the list stays
sr-only for assistive tech.
Interactive map needs a map library — the locations are listed alongside.
Locations ()
- No locations
OSM Usage Policy & Cost
The public OSM tile server (tile.openstreetmap.org) is run by volunteers on a
best-effort basis. Its tile usage policy
sets hard limits:
- No bulk downloading or pre-fetching tiles the user isn't actively viewing.
- Cache tiles and send a valid, identifying
User-Agent. - No SLA — availability is best-effort and access can be withdrawn at any time.
- Not for heavy or commercial production dependent on guaranteed uptime.
For anything beyond a prototype or low-traffic site, use a commercial tile
provider (which bills per load and handles attribution) or self-host OSM
tiles you render from the data yourself. Either way the styleUrl + attribution
props stay the same — only the tile host changes.
MapLibre or Leaflet?
| Leaflet | MapLibre GL | |
|---|---|---|
| Tiles | Raster (image) | Vector (styleable) |
| Footprint | ~40 KB | ~200 KB |
| Styling | Tile-baked | Full client-side styling |
| Best for | A small footprint + any raster source | Custom-styled, themeable maps |
Pick Leaflet when you want a small dependency and a ready raster tile source;
pick MapLibre GL when you want to style the map
yourself. The <x-wirekit::map> API and the accessible list are identical either
way — only provider and the tiles change.
Licenses
Two separate licenses apply on this page, one per layer:
- Leaflet (the engine) is distributed under the BSD-2-Clause license (a permissive open-source license). It is an optional peer dependency — you install and load it; WireKit never bundles or relicenses it.
- OpenStreetMap (the data + tiles) is published under the Open Database License (ODbL) 1.0. The required credit for derived maps and tiles is © OpenStreetMap contributors.
See Also
- Map overview — the engine-independent API, markers, list, and Livewire wiring
- MapLibre GL — the vector-tile default engine
- Leaflet documentation
- OpenStreetMap copyright & license
- OSM tile usage policy