Maplace.js

Live data and loading

Load the map on click

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

Markdown

Map and code

Run the examples on

Loading the map…

The map couldn't load.

Loading the map…

The map couldn't load.

Loading the map…

The map couldn't load.

Loading the map…

The map couldn't load.

Loading the map…

The map couldn't load.

Loading the map…

The map couldn't load.

Loading the map…

The map couldn't load.

Loading the map…

The map couldn't load.

These maps come from Google Maps and OpenFreeMap, which see your IP address. They stay off until you say so, once for the whole site. What loading the maps sends

<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- hold keeps the map idle, asking its provider for nothing, until the reader presses its Load map button. -->
<maplace-map id="load-on-demand-maplibre-map" hold>
  <maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome"></maplace-location>
  <maplace-location location-id="milan" lat="45.4642" lng="9.19" title="Milan"></maplace-location>
  <maplace-location location-id="naples" lat="40.8518" lng="14.2681" title="Naples"></maplace-location>
</maplace-map>

How it works

The map stays idle in its place, its tiles and its provider’s requests waiting, until the visitor presses a button: for a heavy map low on a page, or to ask first.

  • HTML: hold on <maplace-map> shows the panel; its button calls release(), which a script of yours can call too. load-label and load-from-label set its words. For a map that waits until it scrolls into view instead, loading="lazy" (Load states).
  • Script and Bundler: a panel of yours, a line naming whom the map loads from and a button, with createGoogleMap or createMapLibreMap in the button’s click listener, so nothing is created until then (Creating a store). The panel goes with the press, focus moved to the map’s box first, so a keyboard reader isn’t sent back to the top of the page.
  • React: state for whether it was pressed, rendering the panel or the <MaplaceProvider> and <MaplaceMap>, the press moving the focus (<MaplaceMap>).