Maplace.js

Live data, clusters and routes
on Google Maps
and MapLibre.

Locations fetched as JSON and swapped in live, markers grouped into clusters that show a count, the world's countries shaded by a value, a month of earthquakes as a heatmap, a map that loads only when the visitor presses a button, a link that opens the map on a place, and a driving route through your stops.

GitHub

Google Maps

<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<maplace-map api-key="YOUR_KEY" list>
  <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-map>

MapLibre, no key

<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<maplace-map list>
  <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-map>

Install

npm and CDN script

Google Maps

npm install @maplacejs/maplace

MapLibre

npm install @maplacejs/maplace maplibre-gl

CDN script

Google Maps

<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1.2.0/dist/maplace-element.iife.js"
  integrity="sha384-OgwZw1NQ78VKxQUXntJyiiRILF/Ck2chxPi2kbY+gNOcSqZIIsBVXI1BAPbqs6LV" crossorigin="anonymous"></script>

MapLibre

<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1.2.0/dist/maplace-element-maplibre.iife.js"
  integrity="sha384-NTx1K+93ZQC7ezi/smTAvSpiQCrdWid6IfMLQuIS6oT/63JARr9b+gD1devKzZqV" crossorigin="anonymous"></script>

Maplace.js 1.2.0, checked by the browser against its hash.

Run the examples on

Data fetched and swapped in live, thousands of points clustered, countries shaded by a value, a heatmap of earthquakes, a drive through your places, a map loaded on a press, a link to a place.

Markdown

19 Live data from JSON

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

Fetches live-data-a.json, live-data-b.json, live-data-c.json, live-data-d.json, live-data-e.json

Run the map from

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

Data sets your page fetches and swaps in while the map stays: markers, an area, a circle, and on Google a route through some of them. The map’s element never fetches anything itself.

  • Try it: press each button above the map, Markers, More markers, Area and Circle: the map and the list take the new set, and the map fits it. On Google a fifth, Route, draws a route through its places, and leaving that set takes its route with it; MapLibre, which routes only through your own routing and has no route stored for these places, has no such button. A slower answer to an earlier press is dropped.
  • HTML: list on an empty <maplace-map>, and a script assigning the locations property, and on Google route (Properties and methods), then calling maplace.fitAll().
  • Script and Bundler: setLocations and fitAll on the store createGoogleMap or createMapLibreMap returns, and on Google setRoute.
  • React: locations as a prop of <MaplaceProvider>, and on Google route, from your state (<MaplaceProvider>), and a small component calling fitAll through useMaplace() when they change.

20 Marker clustering

4,000 points, those near each other drawn as one badge counting them.

Fetches points-4k.json

Run the map from

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

4,000 points fetched by the page: those near each other are drawn as one badge counting them, so the map stays fast and readable.

  • Try it: zoom in on a badge, and it splits into smaller badges, then single pins.
  • HTML: cluster on <maplace-map>, on a CDN script that bundles clustering: maplace-element-cluster.iife.js on Google, while MapLibre’s script always does (Map attributes). The element never fetches: a script assigns locations.
  • Script and Bundler: cluster: true in the map’s options, then setLocations with the points (Options). The Script version on Google is on the same cluster script; from npm, each provider loads its clustering only for a map that clusters (on Google, on MapLibre).
  • React: the cluster prop of <MaplaceProvider> (<MaplaceProvider>).
  • Their look: Cluster badges has the badge’s colours, as Brand colours uses them.
  • With a list: a list of every point is too long to use; one that lists only what is in the map’s view is in This area.

21 Choropleth of the world

Every country filled by its GDP per person, its value on hover, with a legend on the map.

Fetches countries.json

Styled by choropleth.css

Run the map from

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

The world’s countries, each filled by its GDP per person: a country of several polygons, as the United States with Alaska and Hawaii, is one multipolygon location, hovered, selected and listed as one.

  • Try it: hover a country for its value; Alaska lights up the whole United States. Pick a country in the legend’s select, from the keyboard too, and the map shows it, at its largest polygon: France, not French Guiana. On a touch screen a tap shows the value.
  • The data: countries.json, Natural Earth’s 1:110m countries, which are public domain, as GeoJSON, each with its GDP per person (its GDP over its population, for years from 2007 to 2019, mostly 2019; none under 10,000 people). Its borders are Natural Earth’s, as they stand on the ground; Antarctica is left out.
  • HTML: popup-open-on="hover" on <maplace-map>, which opens a country’s popup under the pointer (Map attributes), and a list view of your own, holding the legend and a select of the countries, placed in a corner with list-position (List views), defined in a plain script so it exists before the map opens; a module script then fetches the countries and assigns locations, as the element never fetches.
  • Script and Bundler: locationsFromGeoJSON, each country’s style, hoveredStyle and selectedStyle set from its value (Styles), popup: { openOn: "hover" } (Popup options), and mountControl with a createListView select inside the legend.
  • React: the same locations on <MaplaceProvider popup>, and a <MapControl> holding the legend and <LocationList as="select"> (<MapControl>).
  • On MapLibre, a globe: globe on the map opens it as the earth, with a “Globe” toggle that flattens it (Globe). Google’s map has no globe.

22 Heatmaps

A month of earthquakes as a heatmap by magnitude, dots when zoomed in, volcanoes as pins, a checkbox for each.

Fetches earthquakes.json, volcanoes.json

Run the map from

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

A month of earthquakes of magnitude 4.5 and up, drawn as a heatmap weighted by magnitude, with a dozen volcanoes as pins: the quakes are locations as any other, so the list’s search and its checkbox for each group narrow the heat with them.

  • Try it: zoom in on Japan or Chile: over two zooms the heat fades into a dot per quake, sized and coloured by its magnitude, and a click on a dot selects its quake in the list. Type “Japan” in the search box: the heat shrinks to Japan’s quakes, and the volcanoes leave the map. Open Groups and untick Quakes: the heat goes, the volcanoes stay; the checkboxes keep what the search found, as they set only the filter’s groups (List view options).
  • The data: earthquakes.json, a month of the USGS’s earthquakes of magnitude 4.5 and up, to November 2026 (public domain), each with its magnitude as weight; volcanoes.json, a dozen well-known volcanoes.
  • HTML: heatmap="Quakes" on <maplace-map> draws the markers of the group Quakes as heat, group-filter adds a Groups button above the list that opens the checkboxes, and heatmap-max-zoom sets where it gives way to the dots (Map attributes); a quake’s weight is its magnitude.
  • Script and Bundler: heatmap: { groups: ["Quakes"] } in the map’s options, maxZoom beside it (Heatmaps), groupFilter: true in its list, and weight on each quake (Markers).
  • React: the same heatmap on <MaplaceProvider>, beside a <LocationList search groupFilter> (<LocationList>).
  • On both providers: MapLibre draws the heat and the dots in its own layers, under the pins; Google, on a canvas over the map, the dots as markers. A marker in the heat has no icon and isn’t editable: it is drawn as heat and a dot.

23 Driving route

A drive through your own places, with directions by leg: Google computes it live; on MapLibre it's one stored route, as your own routing service would answer.

Fetches route-milan-munich.json (used by MapLibre)

Run the map from

Total:

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

A drive through your own places, passing through one without stopping, with its directions leg by leg below the map. On Google, Google computes it live, for any stops you give it. MapLibre has no routing of its own: the page’s computeRoute answers, and here it replays one route stored beside the example, Milan to Munich (computed once by OSRM; roads © OpenStreetMap contributors, ODbL), so on MapLibre this route is fixed. In your page, computeRoute asks a routing service, and any stops route as on Google.

  • Try it: pick a place in the list, and the route stays. Switch to MapLibre: the same drive, replayed from the stored route. Read the directions below the map, each leg under a heading with its distance, and the total under them.
  • HTML: the route property, { stops, via, travelMode }, naming your locations by id (Properties and methods), and a maplace-routechange listener writing the directions from the result’s legs and steps (Events).
  • Script and Bundler: route in the map’s options, or setRoute, and a routeChange listener (Routes); Routes on Google has its limits.
  • React: the route prop and onRouteChange on <MaplaceProvider> (<MaplaceProvider>, Event props).
  • On MapLibre: the same, plus computeRoute: the element’s property, createMapLibreMap’s option or createMapLibreAdapter’s; Routes on MapLibre shows one asking a live OSRM server.

24 Load on demand

A panel in the map's place: nothing draws until the visitor presses its button.

Run the map from

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

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.

  • Try it: press Load map and the map draws. Every version shows the same panel, a line naming whom the map loads from and the button: the HTML version’s is the element’s own, the others write their own with its look. On this site the map’s script is loaded once you accept maps, so what waits for the press is the map and its tiles.
  • 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>).