Maplace.js

Markers and popups

HTML markers with CSS states

Markers made of your own HTML, their hovered and selected looks in your CSS.

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>
<!-- Markers drawn by your CSS: each pin is your own markup (a <template data-icon>), which Maplace.js
     marks data-hovered while the reader points at it and data-selected once they pick it, so your
     CSS gives each state its look. The pin is drawn anew for each state, so the pop is an animation,
     which starts on a new node, not a transition. -->
<style>
  #css-markers-maplibre-map .pin {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border: 2px solid #1d1d1b;
    border-radius: 999px;
    background: #fff;
    color: #1d1d1b;
    font: 600 0.8125rem/1.2 system-ui, sans-serif;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
    cursor: pointer;
  }
  #css-markers-maplibre-map .pin[data-hovered] { transform: translateY(-3px); }
  #css-markers-maplibre-map .pin[data-selected] {
    border-color: #c62828;
    background: #c62828;
    color: #fff;
    transform: scale(1.15);
  }
  @media (prefers-reduced-motion: no-preference) {
    #css-markers-maplibre-map .pin[data-selected] { animation: css-markers-maplibre-pop 0.3s ease-out; }
  }
  @keyframes css-markers-maplibre-pop { from { transform: scale(0.85); } }
</style>
<maplace-map id="css-markers-maplibre-map">
  <maplace-location location-id="rijks" lat="52.36" lng="4.8852" title="Rijksmuseum">
    <template data-icon><span class="pin">Rijks</span></template>
  </maplace-location>
  <maplace-location location-id="anne-frank" lat="52.3752" lng="4.884" title="Anne Frank House">
    <template data-icon><span class="pin">Anne Frank</span></template>
  </maplace-location>
  <maplace-location location-id="hermitage" lat="52.3654" lng="4.9025" title="Hermitage">
    <template data-icon><span class="pin">Hermitage</span></template>
  </maplace-location>
  <maplace-location location-id="nemo" lat="52.3738" lng="4.9123" title="NEMO Science Museum">
    <template data-icon><span class="pin">NEMO</span></template>
  </maplace-location>
  <maplace-location location-id="eye" lat="52.3843" lng="4.9008" title="Eye Filmmuseum">
    <template data-icon><span class="pin">Eye</span></template>
  </maplace-location>
</maplace-map>

How it works

Each pin is a node of yours, styled by the page’s CSS: Maplace.js marks it data-hovered while the reader points at it and data-selected once they pick it, so a rule on each attribute gives that state its look.

  • HTML: a <template data-icon> inside each <maplace-location> (Location attributes). The template is drawn anew for each state, so the pop is a CSS animation, which starts on a new node, rather than a transition; pointing at a selected pin plays it again.
  • Script and Bundler: an icon that is a node, the same node in every state (Icons).
  • React: markerIcon on <MaplaceMap>, whose output sits in a node Maplace.js keeps for each marker; that node carries the marks, so the rules read [data-selected] > .pin where the others read .pin[data-selected] (<MaplaceMap>).
  • Styling: every class and attribute Maplace.js’s markup carries, in Styling.