Maplace.js

Styling

Map styles

The provider's own map styles to choose from, and on Google the map-type control.

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>
<!-- MapLibre's own look: a style, here one of OpenFreeMap's, and MapLibre's map options (here a
     compact attribution). Choosing a style opens the map again in it, where it was. Any style URL
     works in map-style: MapTiler's, Stadia's, your own. -->
<p><label for="styled-maplibre-style">Map style</label> <select id="styled-maplibre-style" autocomplete="off">
  <option value="https://tiles.openfreemap.org/styles/bright">Bright</option>
  <option value="https://tiles.openfreemap.org/styles/liberty">Liberty</option>
  <option value="https://tiles.openfreemap.org/styles/positron">Positron</option>
  <option value="https://tiles.openfreemap.org/styles/dark">Dark</option>
</select></p>
<maplace-map id="styled-maplibre-map" map-style="https://tiles.openfreemap.org/styles/bright"
  map-options='{"attributionControl":{"compact":true}}'>
  <maplace-location location-id="lisbon" lat="38.7223" lng="-9.1393" title="Lisbon"></maplace-location>
  <maplace-location location-id="porto" lat="41.1579" lng="-8.6291" title="Porto"></maplace-location>
  <maplace-location location-id="coimbra" lat="40.2033" lng="-8.4103" title="Coimbra"></maplace-location>
  <maplace-location location-id="faro" lat="37.0194" lng="-7.9304" title="Faro"></maplace-location>
</maplace-map>
<script>
  document.getElementById('styled-maplibre-style').addEventListener('change', (event) => {
    document.getElementById('styled-maplibre-map').setAttribute('map-style', event.currentTarget.value);
  });
</script>

How it works

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.

  • 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>).