Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

geo-map

A zero-dependency map component using OpenStreetMap or CARTO tiles (or your own tile proxy). Renders a static map centred on given coordinates with a marker pin and address caption, and lazy-loads an accessible pan / zoom mode.

Overview

The <geo-map> component displays a map from free raster tiles. It computes the tiles needed to cover its box from lat/lng/zoom, re-lays them out when the element is resized, and draws a marker at the centre. Activating the map lazy-loads pan and zoom.

Key features:

  • Zero dependencies — no API keys, no external libraries
  • OpenStreetMap or CARTO tiles, or your own tile proxy, each with the credit its terms require
  • Progressive enhancement — the slotted <address> is visible before JS and names the map
  • Opt-in consent mode that contacts no tile server until the user agrees
  • On-screen zoom buttons, pinch, keyboard, and click-to-centre in interactive mode
  • CSS custom properties, CSS parts, and data-label-* strings for localisation

Attributes

Attribute Type Default Description
latNumber—Latitude of the map centre
lngNumber—Longitude of the map centre
zoomNumber15Tile zoom level (1–19)
markertrue | falsetrueShow the pin at the centre. Set to "false" to hide.
marker-colorCSS colourthemePin fill. Invalid values are ignored; without it the pin uses --geo-map-marker-color, then the theme’s --color-error.
providerosm | carto-light | carto-dark | carto-autoosmBuilt-in tile source. carto-auto follows the page’s data-mode (else prefers-color-scheme).
tile-urlString—Tile URL template overriding provider: {z} {x} {y}, {s} (subdomain a/b/c) and {r} (@2x on high-density screens).
attributionString—Credit text for a tile-url source.
attribution-hrefURL—Link for that credit (http/https only).
interactiveclick | eager | noneclickActivation mode: the map surface is an activation button; eager activates on load (without moving focus); none is static.
static-onlyBoolean—Never activate.
loadinglazy | eager | consentlazyTile loading. consent requests nothing from the tile host until the user presses “Load map”.
labelString—Accessible name of the map (default: “Map of …” from the address text, the src name, or place).
srcID—ID of an external <address data-lat data-lng> or <script type="application/ld+json"> to read coordinates from
placeString—Name matched against JSON-LD scripts on the page (data.name)
data-readyOutput—Set by the component once the static tiles have loaded.

Tile Providers

Each built-in provider shows the credit its terms require: OpenStreetMap shows “© OpenStreetMap contributors”; the CARTO styles add “© CARTO”. Keep the credit visible.

Your Own Tiles and Attribution

For privacy, swappability, caching control, or rate limiting, point <geo-map> at your own endpoint. tile-url takes a URL template; every {z}, {x}, {y} is substituted, {s} rotates through subdomains a/b/c, and {r} becomes @2x on high-density screens. See Server-Side Service Facade for a Cloudflare Worker that proxies and caches OSM tiles.

A tile-url source has no built-in credit — supply the credit its licence needs with attribution (and attribution-href), or slot your own element with slot="attribution". If you proxy OpenStreetMap, credit OpenStreetMap.

Privacy and Third-Party Requests

By default the static map fetches its tiles as soon as it is near the viewport, even with interactive="click". Each tile request sends the visitor’s IP address and the page as referrer to the tile host:

  • osm: https://tile.openstreetmap.org
  • carto-*: https://basemaps.cartocdn.com
  • tile-url: whatever host you configure (nothing third-party if it is same-origin)

With a Content Security Policy, allow the tile host in img-src (for example img-src 'self' https://tile.openstreetmap.org). The component adopts its styles as a constructable stylesheet, so it does not need style-src 'unsafe-inline' in browsers that support adoptedStyleSheets.

Set loading="consent" to show a placeholder naming the tile host instead; no tile is requested until the user presses “Load map” (which then also activates interactive mode). Hovering or focusing that button preconnects to the tile host. Keep a link in the slotted address so the placeholder is still useful.

Marker

The marker pin is an SVG drawn at the centre of the map. By default it uses the theme’s --color-error; set --geo-map-marker-color in CSS for a site-wide colour, marker-color for one map, or hide it with marker="false".

Caption

Slot an <address> (or any content) as a caption at the bottom of the map. It is also the no-JS fallback and, by default, the map’s accessible name (“Map of …”). Links in the caption stay clickable above the activation surface.

No-JS Fallback

Before the component upgrades, the slotted content is visible as a styled card. Include a link to OpenStreetMap so users can still find the location.

Data Binding

Coordinates can come from 6 sources, checked in priority order. The first match wins:

  1. Explicit lat/lng attributes — highest priority
  2. src → <address data-lat data-lng> — reference an external address element by ID
  3. src → <script type="application/ld+json"> — reference a JSON-LD script by ID
  4. Slotted <address data-lat data-lng> — address inside the component
  5. place attribute — scans all JSON-LD scripts for a matching name
  6. <meta name="geo.position"> — page-level fallback

src → address element

Point src to the ID of an <address> element with data-lat and data-lng attributes. The address stays visible as semantic content while the map reads its coordinates.

src → JSON-LD script

Point src to the ID of a <script type="application/ld+json"> element. The component reads geo.latitude and geo.longitude from the parsed JSON.

Slotted <address> with coordinates

Slot an <address> with data-lat and data-lng directly inside the component. The address appears as a caption and also provides the coordinates.

place attribute

Set place to a name that matches the name field in a JSON-LD Place script anywhere on the page. Useful when structured data already exists for SEO.

<meta> fallback

As a last resort, the component checks for a <meta name="geo.position"> tag in the document. The content format is "lat;lng".

JavaScript API

.data reads the map state; assigning a partial object writes the attributes as one batch and re-renders once. Assigning the current state is a no-op, an invalid markerColor is ignored, and '' clears it.

PropertyTypeDescription
data{ lat, lng, zoom, marker, markerColor }Get, or assign (partial) to update. Emits geo-map:data-changed.
markersArray<{ lat, lng, color }>Read-only. The centre marker as a one-element array, or [] without coordinates.
activeBooleanRead-only. True in interactive mode (also :state(active)).

Interactive Mode

With the default interactive="click" the whole map surface is the activation target: click or tap anywhere, or Tab to the “Activate interactive map” button and press Enter. On touch screens the button is always visible. Activation lazy-loads the pan / zoom layer and moves focus to the map.

In interactive mode you can drag to pan, click a point to centre the map on it (a single-pointer alternative to dragging), pinch with two fingers, scroll, or use the on-screen + / −, recenter and exit buttons. Use interactive="eager" to activate on load, or interactive="none" / static-only for a static map.

Keyboard

KeyAction
Arrow keysPan the map
+ / =Zoom in
-Zoom out
Home / 0Recenter on the original location and zoom
EscapeExit interactive mode; focus returns to the activate button
TabMove between the map and the zoom / recenter / exit buttons

CSS Custom Properties

PropertyDefaultDescription
--geo-map-height300pxComponent height
--geo-map-border-radius0.5remBorder radius
--geo-map-marker-colorvar(--color-error)Marker pin fill (the marker-color attribute wins)
--geo-map-marker-dot-color#fffDot inside the pin
--geo-map-marker-size32pxMarker pin dimensions
--geo-map-caption-bgtranslucent surfaceCaption background (light / dark aware)
--geo-map-caption-colorvar(--color-text)Caption text colour
--geo-map-caption-padding0.5rem 0.75remCaption padding
--geo-map-overlay-bgrgb(0 0 0 / 0.35)Activation overlay background on hover / focus
--geo-map-overlay-color#fffActivation overlay text colour
--geo-map-activate-bgrgb(0 0 0 / 0.6)Activate button background
--geo-map-consent-bgtranslucent surfaceConsent placeholder background
--geo-map-consent-colorvar(--color-text)Consent placeholder text colour
--geo-map-attribution-bgtranslucent surfaceAttribution background
--geo-map-attribution-colorvar(--color-text)Attribution text colour
--geo-map-attribution-font-size0.625remAttribution text size

CSS Parts

PartElementPurpose
containerOuter wrapperOverall sizing
viewportMap surfaceNamed image (static) or focusable map region (interactive)
tilesTile layerTranslated layer holding the tile images
markerSVG pinMarker styling
overlayActivation surfaceFull-surface click target containing the activate button
activateButtonActivate (or, in consent mode, “Load map”) button
consent-noteParagraphNames the tile host in consent mode
controlsButton groupOn-screen controls (interactive mode)
controlButtonEvery control button; also zoom-in, zoom-out, recenter, exit
captionSlot wrapperAddress / label display
attributionCreditProvider credit, attribution text, or the attribution slot
statusLive regionVisually hidden pan / zoom announcements

Localisation

Every built-in string is overridable with a data-label-* attribute: map, map-of ({name}), activate, consent, consent-note ({host}), zoom-in, zoom-out, recenter, exit, controls, instructions, moved ({lat}, {lng}, {zoom}), error-coords and error-tiles.

Events

EventDetailDescription
geo-map:ready{ lat, lng, zoom }Static tiles finished loading (data-ready is set)
geo-map:activate{ lat, lng, zoom }Interactive mode started
geo-map:move{ lat, lng, zoom }After a pan or zoom in interactive mode (new centre)
geo-map:data-changed{ data, source: 'property' }After a .data assignment that changed something
geo-map:error{ message }No coordinates resolved, or every tile failed to load

Contact Page Example

A common use case: pair <geo-map> with a contact form in a sidebar layout.

Accessibility

What the component provides:

  • The static map is an image named from label, the slotted <address>, the src name, or place — not raw coordinates.
  • The activate button’s accessible name is its visible text; on touch screens it is always visible, and the whole map surface activates.
  • In interactive mode the map is a focusable region with aria-roledescription="map", instructions via aria-describedby, and a polite live region announcing the new centre and zoom.
  • Single-pointer alternatives to dragging and pinching: click-to-centre and the on-screen zoom, recenter and exit buttons (WCAG 2.5.7). All controls work from the keyboard.
  • The marker is decorative (aria-hidden); attribution links open in a new tab.

Limits to be aware of:

  • Raster tiles are pictures: street names and landmarks on the map are not available to screen readers. Always put the address (and ideally a link to a full map service or directions) in the slotted <address> — that text, not the map, is the accessible content.
  • Tile colours come from the provider and are not themed; check that your marker colour contrasts with the tiles you use, and prefer carto-auto for dark pages.
  • Announcements report coordinates, not place names (there is no geocoding).

Related

↑