Maplace.js

Search and filters

Filter by tags

Places with several tags: tick some to see those with all of them.

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>
<!-- Places with several tags, in a list on the map under their one group; the checkboxes show those with all the ticked tags. -->
<p id="tags-maplibre-filters">
  <label><input type="checkbox" value="parking" /> Parking</label>
  <label><input type="checkbox" value="open-late" /> Open late</label>
</p>
<maplace-map id="tags-maplibre-map" list list-position="top-right" list-heading="Places" group-counts>
  <maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome" group="Centre" tags="parking open-late"></maplace-location>
  <maplace-location location-id="bologna" lat="44.4949" lng="11.3426" title="Bologna" group="Centre"></maplace-location>
  <maplace-location location-id="milan" lat="45.4642" lng="9.19" title="Milan" group="North" tags="parking"></maplace-location>
  <maplace-location location-id="turin" lat="45.0703" lng="7.6869" title="Turin" group="North" tags="open-late"></maplace-location>
  <maplace-location location-id="naples" lat="40.8518" lng="14.2681" title="Naples" group="South" tags="parking open-late"></maplace-location>
</maplace-map>
<script>
  document.getElementById('tags-maplibre-filters').addEventListener('change', (event) => {
    const ticked = event.currentTarget.querySelectorAll(':checked');
    document.getElementById('tags-maplibre-map').maplace.setFilter({ tags: Array.from(ticked, (box) => box.value) });
  });
</script>

How it works

A location has one group, its heading in the list, and as many tags as it needs. Tick a box and the map and the list keep the places with all the ticked tags; untick them all and every place is back. The boxes sit above the map, the list on it, top right.

  • HTML: tags="parking open-late" on <maplace-location>, the tags split on spaces (Location attributes), group-counts on <maplace-map> for the numbers (Map attributes), and a script calling the element’s maplace.setFilter.
  • Script and Bundler: tags: ["parking", "open-late"] on a location (Every location), groupCounts on the list (List view options), and setFilter({ tags }) with what is ticked: no tags ask for nothing, so no branch is needed for none.
  • React: <LocationList groupCounts /> and the filter prop of <MaplaceProvider>, filter={{ tags }}, applied when its value changes.
  • With groups: setFilter({ groups: ["North"], tags: ["parking"] }) keeps what matches both; setFilter(["North"]), a list of groups alone, is what the Dropdown of places example does.