Maplace.js

Your own look
on Google Maps
and MapLibre.

The provider's map styles, markers of your own HTML and CSS, one brand palette for areas, cluster badges and the list, or Maplace.js's styles turned off for yours.

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

Your map's look: the provider's own styles, and Maplace.js's parts drawn your way.

Markdown

26 Restyled venue map

A dark frame, pins coloured by category, a legend that filters them and a card of the venues, or of the one picked.

Styled by whats-on.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

A map that looks nothing like Maplace.js’s: a dark frame, pins of your own coloured by category, a count over the map, a legend on it whose chips show one category at a time, and beside it a card listing the venues shown, or the one picked. Each piece is one of Maplace.js’s hooks; together they are one idea, the whole look the page’s own.

  • Try it: press “Markets”, and the map, the count and the card’s list keep the markets, the list named “Markets”; press it again, and every venue is back. Point at a pin, and it lifts; pick one, and it grows, its name beside the count and its address, year and what it is known for in the card beside the map, under it on a phone, in place of the card’s list of venues; pick one from the list too, and the card’s × brings the list back.
  • HTML: a <template data-icon> in each <maplace-location>, with its group (Location attributes); the legend a list view of your own, defineListView, at list-position="bottom-left". The element puts one view of yours on the map, so the count is your own element over the map’s top left, where a control would sit, taking no clicks. The card’s details are each venue’s own data- attributes, read by the page’s script on the store’s selectionChange into the card’s <template>, added to the card while a venue is picked (Events); while none is, the card lists the venues shown, from listedLocations, each a button calling select.
  • Script and Bundler: an icon node per location (Icons), and the count and the legend put on the map with the adapter’s mountControl, the count rewritten from listedLocations, the name beside it from the snapshot’s selectedId, the press moved with the store’s filter as the store changes, and the card written from the venue’s data (Location fields) on selectionChange, its markup a <template> in the page, and while no venue is, a button per venue shown, rewritten from listedLocations when they change; a chip calls setFilter with its category, or with nothing to show them all.
  • React: markerIcon on <MaplaceMap>, and the count and the legend in two <MapControl>s, reading the store with useMaplace(), as the card does beside <MaplaceMap>, inside <MaplaceProvider>, its list read as the ids listed so a hover renders nothing, and flushSync rendering it at once so a press can move the focus into it.
  • On Google: its map-type, Street View and camera controls are off (map-options in HTML, mapOptions elsewhere), for the clean look, as the MapLibre map shows none either.
  • In every version: the look is one stylesheet, whats-on.css, in the examples’ styles/ folder, which each version’s HTML links, so the page, the script, the bundled and the React versions share it, scoped by the frame’s class, .whats-on, and the map’s, .whats-on-map. Every venue fitted with 80px of padding, clear of the count and the legend: the store’s view, { kind: "fit-all", padding: 80 } (The first view), or in HTML, which has no attribute for it, fitAll before the map opens. Maplace.js’s panel around what goes on the map is made nothing with .maplace-control { padding: 0; background: none; box-shadow: none; }, as its rules weigh nothing (Styling); each category’s colour is one custom property, --category, which its pins and its chip take; the pins’ hovered and selected looks are rules on data-hovered and data-selected, as in HTML markers with CSS states. A venue picked from the card’s list moves the focus to the card’s ×, named “Close”, which takes it back to that venue in the list, so a keyboard never loses its place. The name of the venue picked is a plain element, not a live region: Maplace.js already says each selection to a screen reader (On every map). The pins differ by colour alone, so the chips, named, are how a reader picks a category out.

27 A team around the world

Faces for markers, list entries of your own with each person's local time, filtered by team.

Fetches team.json

Styled by team.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

Each person is a face on the map, their initials on their team’s colour, and the list beside it is the page’s own: their name, role and city, and the time where they are next to how far that is from yours, turning as each minute begins.

  • Try it: find someone by name, city or role, or untick teams in the group filter to see one; pick a face on the map and the list follows. On MapLibre the earth opens as a globe, faces on its far side faded: turn it, or flatten it with the toggle.
  • HTML: a <template data-icon> in each <maplace-location> draws the face, and the person’s role, city and time zone are the page’s own data- attributes there, which Maplace.js leaves alone; the template makes the location’s icon a function (Templates). The list is a view of the page’s own, Maplace.defineListView around Maplace.createListView with render, which reads those attributes from the person’s <maplace-location> and draws the face with the location’s own icon (List views); group-filter, group-counts and search on the map still reach it as its options.
  • Script and Bundler: the people from team.json, each given an icon that draws the face from its data (Icons), and list.render building each entry (List view options). The times are written into each entry’s own span, and a timeout set to the next minute writes them again, so no location changes for the clock.
  • React: markerIcon on <MaplaceMap> and the entry as <LocationList>’s children (<LocationList>); each entry’s <LocalTime> keeps the minute in its state, so only the times render again as each minute begins.
  • Styling: each team’s colour, and the rings a face takes while pointed at or picked ([data-hovered], [data-selected]), in the examples’ styles/team.css (Styling).
  • On MapLibre, a globe: globe on the map (globe: true in the options; in React, createAdapter={() => createMapLibreAdapter({ globe: true })}) (Globe). Google’s map has no globe.

28 Map styles

The provider's own looks: a choice of styles, and on Google the map-type control.

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 provider’s own looks: on Google a light or dark map, or the visitor’s system setting, with Google’s map options; on MapLibre a choice of OpenFreeMap’s styles, or any style’s URL.

  • Try it: choose from Map style: the map opens again in that look, where it was, keeping its state.
  • HTML: on Google color-scheme, map-id and map-options, a change of color-scheme or map-options opening the map again (Provider attributes); on MapLibre map-style and map-options (Provider attributes).
  • Script and Bundler: createGoogleAdapter({ mapId, colorScheme, mapOptions }) (Map ID and styling) or createMapLibreAdapter({ mapStyle, mapOptions }) (Styles and tiles), and attach; a new look is a new adapter, attached where the last one was (Methods).
  • React: the same adapters through createAdapter, and a key on <MaplaceMap> that changes with the look, so a new one opens (<MaplaceMap>).

29 HTML markers with CSS states

Pins of your own markup, their hovered and selected looks in your 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

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.

  • Try it: point at a pin, and it lifts; pick one, and it turns red with a pop. Pick another, and the first goes back.
  • 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.

30 Brand colours

One palette across the delivery areas, the cluster badges and the list.

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

One palette across the map: the delivery areas, the cluster badge and the list, each through its own hook.

  • Try it: point at a delivery area, and its edge turns green; pick one, here or in the list, and it fills green, its entry too. Zoom in, and the brown badges, the old town’s shops and Christianshavn’s, split into single shops.
  • HTML: the areas’ fields in a <script type="application/json"> inside <maplace-map>, as a polygon’s path takes more than an attribute (Data); a circle written as a <maplace-location> takes them as shape-style, hovered-style and selected-style. cluster on the map, on maplace-element-cluster.iife.js on Google.
  • Script and Bundler: style, hoveredStyle and selectedStyle on each location, in hex, as every provider reads them (Styles), with cluster: true in the options, on the cluster script for the Script version on Google.
  • React: the same locations, and the cluster prop of <MaplaceProvider>.
  • In every version: the badge takes --maplace-cluster-background and --maplace-cluster-color on the map or any element around it (Cluster badges), and the list the page’s rules on .maplace-option[data-hovered] and .maplace-option[data-selected]; Maplace.js’s own rules are in :where(), so any of yours wins (Styling). The single shops keep Maplace.js’s default pin; for pins in the brand’s colours, an icon of your own, as in HTML markers with CSS states.

31 Default styles off

Maplace.js's styles off and nothing in their place: the map and its list as your page shows them, with no CSS but a height.

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

Maplace.js’s own styles switched off and nothing put in their place: the map and its list exactly as your page shows them with no CSS of yours but the one rule a map can’t do without, its height.

  • Try it: the list is plain lines in the page’s font, under the map; pick one and its popup opens, with nothing in the list marking it. It’s the starting point for a look of your own.
  • Off with the defaults: the map’s height, the list beside it, the list’s spacing, its hover and selected looks and its scrolling, and the popups’ dark text and inset, and on MapLibre their heading’s weight and its room beside the close button. On a dark page, give .maplace-popup and .maplace-popup-heading a dark colour: their text takes the page’s on the white bubble (Turning them off).
  • HTML: data-maplace-unstyled on <maplace-map>, and a height on its .maplace-map-pane: the map fills it, and the list goes under it.
  • Script and Bundler: data-maplace-unstyled on the element holding the map and its list, and a height on the map’s container.
  • React: the same attribute on the element around <MaplaceMap> and <LocationList>, and a height on the map’s class.
  • On this site: the site’s own styles stay out of anything inside data-maplace-unstyled, its keyboard focus ring apart, so what shows here is what your page shows: the list takes the site’s font and text colour as it would take yours. To draw a look of your own, style the classes Maplace.js’s markup carries (Classes).