Skip to content
LoidoltTheme 0.11.1
Svelte 5

Component

MapView

A MapLibre map on the loidolt basemap, recoloured with the theme and moved by keyboard as well as pointer.

import { MapView } from '@loidolt/theme-maps';

Example

The workshop's delivery area in central Portland. Focus the map to move it: arrow keys pan, plus and minus zoom, Shift with the arrows rotates and tilts.

Centre 45.5231, -122.6765 · zoom 12.0

Notes

  • The default basemap is drawn in the loidolt palette from OpenFreeMap’s free, keyless OpenMapTiles tiles; basemap="blank" draws land colour only and makes no network requests. Pass tiles to use another OpenMapTiles-schema provider, or mapStyle for a style of your own.
  • The canvas is named by label and described by description plus a sentence on the keyboard controls. Arrow keys pan and + and − zoom when it has focus; after a keyboard move, where the map landed is announced.
  • A theme change repaints the basemap in place — no reload — and data layers with a paint function follow it too.
  • center and zoom are bindable both ways. MapLibre loads in the browser only; the server renders the frame and description, and a browser without WebGL gets a message instead of a broken canvas.

Props

Generated from the component source, so it cannot drift from the implementation.

MapView props
PropTypeDefaultNotes
label required string—Names the map for assistive tech — say what it shows, e.g. "Delivery stops".
announceMoves booleantrueAnnounce where the map lands after a keyboard pan or zoom — the non-visual answer to "where am I now?".
attribution stringOPENFREEMAP_ATTRIBUTIONAttribution for tiles. Required by most tile providers — OpenFreeMap's is the default.
basemap bindablestring'default'default draws the loidolt basemap from OpenMapTiles-schema tiles (OpenFreeMap's unless tiles says otherwise); blank draws land colour only, with no network requests. Bindable, so a BasemapSwitcher can drive it.
bearing number0
bounds LngLatBounds—Fit the view to this box on load and whenever it changes. Wins over center/zoom.
boundsPadding number32Space kept around bounds, in pixels.
center bindableLngLat[0, 20][longitude, latitude]. Bindable: follows the map as it moves.
children Snippet—Sources, layers, markers and controls. Rendered once the style has loaded.
class string—
controlPosition Corner'top-right'Corner for the built-in controls.
cooperativeGestures booleanfalseRequire two fingers or Ctrl + wheel to move the map, so it cannot trap page scrolling.
description string—What the map shows, read after the label. The keyboard controls are appended, so a screen-reader user knows the map can be moved.
errorTitle string'Map unavailable'
fullscreenControl booleanfalse
geolocateControl booleanfalse
glyphs stringOPENFREEMAP_GLYPHSGlyph URL template for labels.
height number | string400Map height: pixels, or any CSS length.
interactive booleantruePan and zoom by pointer and keyboard.
map bindableMapLibreMap | nullnullThe live MapLibre map. Bindable; null until created.
mapStyle string | StyleSpecification—A style URL or document of your own. Overrides basemap, and is not recoloured.
maxBounds LngLatBounds—Keep the view inside this box.
maxZoom number—
minZoom number—
navigationControl booleantrue
onClick (event: MapClickEvent) => void—
onError (error: Error) => void—
onLoad (map: MapLibreMap) => void—
onMoveEnd (view: MapViewState) => void—
pitch number0
ref bindableHTMLDivElement | nullnull
scaleControl booleanfalse
scaleUnit 'metric' | 'imperial''metric'
tiles stringOPENFREEMAP_TILESOpenMapTiles-schema tiles for the default basemap: a TileJSON URL or {z}/{x}/{y} template.
unavailableText string'The map could not be shown in this browser.'Shown when the map cannot be drawn at all (no WebGL, or MapLibre failed to load).
zoom bindablenumber1.5Bindable: follows the map as it zooms.

Plus the attributes of Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onclick' | 'onerror'>, forwarded to the root element.