Maplace.js

Live data and loading

Locations fetched as JSON and swapped in live, a GeoJSON file drawn as a layer, a map that loads only when the visitor presses a button, and a link that opens the map on the place picked.

Markdown

Examples

  • Live data from JSON

    Data sets fetched as JSON and swapped in live: markers, an area, a circle, and on Google a route.

  • GeoJSON layer

    A GeoJSON file as the map's layer: points as markers, a line, an area, each with a popup.

  • Load the map on click

    A panel in the map's place: the map loads only when the visitor presses its button.

  • Shareable link to a place

    A shareable link to the place picked, shown under the map, that opens the map on it.

Map images: © OpenStreetMap contributors, © OpenMapTiles, OpenFreeMap.

Reference

Properties and methods, from the Element reference

Property What
locations The locations, as an array; once set, it wins over those written inside the element
route The route drawn, or undefined (until the store exists, even after a route is set)
sanitize The store’s sanitize option, so locations given as JSON or through locations can use html. Set it before the map opens; set later, it is misuse
markerIcon (1.3) The store’s markerIcon, the icon of every marker without its own: an image URL, a node, or a function building each marker’s icon from its location (({ data }) => …). Read when the store is made, as sanitize is, so a page’s script sets it before the map opens, and before it reads maplace; set later, it is misuse. It wins over the map’s <template data-icon>
computeRoute Your own routing, for a map on MapLibre, which has none (routes on MapLibre); read when the map opens, so set it before; Google ignores it. On MapLibre, not a function is misuse
maplace The underlying store, for anything the attributes don’t cover
loadState error while a misuse stands, else the store’s: idle, loading, ready or error
release release() starts loading at once an element held with hold or waiting with loading="lazy"

Load states, from the Element reference

The map The line
On Google “Loads from Google”
On MapLibre with no map-style “Loads from OpenFreeMap”
On MapLibre, map-style an http or https URL “Loads from” and the URL’s host, its port kept
On MapLibre with a JSON style, a relative URL or another scheme None, only the button: there is no one host to name
On a provider of your own (defineProvider) Its registered name
With provider naming one not registered yet That name, then the provider’s own once it registers
With no provider, and none or several registered None, only the button