Maplace.js

Markers and popups

Place cards in popups

A place card in each popup: photo, rating, hours, and buttons to open it in Maps or get there.

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

Styled by popups.css

<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- This example's look lives in the examples' styles/popups.css, which every version links. -->
<link rel="stylesheet" href="../../styles/popups.css">
<!-- A place card in each popup, from each place's template: photo, category, hours and rating,
     then the Open in Maps and Directions links. The ratings, reviews and hours are sample figures. -->
<maplace-map id="popups-maplibre-map" center="44,11" zoom="6" open-in-maps-link directions-link>
  <maplace-location location-id="colosseum" lat="41.8902" lng="12.4922" title="Colosseum">
    <template>
      <div class="place-card">
        <img class="place-photo" src="/examples/data/photos/colosseum.webp" alt="The Colosseum's arches behind a row of cypresses">
        <p class="place-meta"><span class="place-category">Landmark</span> · Open <span class="place-hours">9:00–19:15</span></p>
        <p class="place-rating">★ <span class="place-score">4.7</span> <span class="place-reviews">(412,301 reviews)</span></p>
      </div>
    </template>
  </maplace-location>
  <maplace-location location-id="duomo" lat="45.4641" lng="9.1919" title="Duomo di Milano">
    <template>
      <div class="place-card">
        <img class="place-photo" src="/examples/data/photos/duomo.webp" alt="The Duomo's white Gothic facade over its square">
        <p class="place-meta"><span class="place-category">Cathedral</span> · Open <span class="place-hours">9:00–19:00</span></p>
        <p class="place-rating">★ <span class="place-score">4.8</span> <span class="place-reviews">(198,442 reviews)</span></p>
      </div>
    </template>
  </maplace-location>
  <maplace-location location-id="st-marks" lat="45.4345" lng="12.3397" title="St Mark's Basilica">
    <template>
      <div class="place-card">
        <img class="place-photo" src="/examples/data/photos/st-marks.webp" alt="The mosaics and domes of St Mark's Basilica's facade">
        <p class="place-meta"><span class="place-category">Basilica</span> · Open <span class="place-hours">9:30–17:15</span></p>
        <p class="place-rating">★ <span class="place-score">4.7</span> <span class="place-reviews">(156,018 reviews)</span></p>
      </div>
    </template>
  </maplace-location>
</maplace-map>

How it works

Picking a place opens a card: its title as the popup’s heading, then its photo, category, opening hours and rating, and two buttons, one showing the place in a maps site, one getting directions there.

  • Note: the ratings, reviews and hours are sample figures.
  • HTML: a <template> inside each <maplace-location> holds its card (Templates), and open-in-maps-link and directions-link on <maplace-map> add the two links, styled through .maplace-popup-links (Styling), and center and zoom set the first view (Map attributes).
  • Script and Bundler: each place’s details in its data, and content, a function filling the page’s card <template> from them (Content); popup: { openInMapsLink: true, directionsLink: true } in the map’s options (Popup options), and view for the first view (The first view).
  • React: popupContent on <MaplaceMap> renders the card from data (<MaplaceMap>), and the same popup and view are props of <MaplaceProvider> (<MaplaceProvider>).
  • Photos: from Wikimedia Commons, each under CC0: the Colosseum by Wilfredor, the Duomo by Leonhard Lenz and St Mark’s Basilica by Gary Houston.