Maplace.js

Circles, lines and areas
on Google Maps
and MapLibre.

Circles, polylines, great-circle flights and polygons in your own colours, with popups and markers on the same map. Circles, polylines and polygons can be made editable, each edit written back to your data.

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

Circles, lines (straight, bowed or on great circles) and areas in their own colours, some to edit, and all of them with markers on one map.

Markdown

13 Circles

Areas in their own colours, with popups; resize the third and see its radius.

Run the map from

Radius: 8.0 km

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

Areas by radius in metres, each in its own colours, the first two with a popup, the centre selected at the start; the third resizes, its radius shown below the map as it changes.

  • Try it: pick “Within 15 km” and it turns orange, its selected style, its popup opening. Drag the edge of “Change my size”, which has neither, and the line below follows.
  • HTML: type="circle", radius, shape-style, selected-style and editable on <maplace-location>, a <template> inside each of the first two for its popup (Location attributes), selected-id on the map, and maplace-locationedit and maplace-locationchange listeners (Events).
  • Script and Bundler: type: "circle", radius, style, selectedStyle, content and editable on a location (Circles, Styles), and locationEdit while dragging and locationChange once dropped (Events).
  • React: the same circles, their text in data for popupContent on <MaplaceMap>, with onLocationEdit and onLocationChange on <MaplaceProvider> (Event props).

14 Editable polyline

A trail to edit, with places along it.

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 trail you can edit, Cinque Terre’s coastal path, with the villages along it as markers of their own and in the list beside the map.

  • Try it: drag a point of the line, or the middle of a segment to add one. Pick a village for its popup. The line itself is listed too, as a location.
  • HTML: a <script type="application/json"> inside <maplace-map> holding the data, as a path takes more than an attribute (Data); list and list-heading on the map (Map attributes).
  • Script and Bundler: type: "polyline", path and editable on a location (Polylines), and list: { container, heading } (List view options).
  • React: the same locations on <MaplaceProvider>, and <LocationList heading="Along the trail" /> beside the <MaplaceMap> (<LocationList>).

15 Flights

Great circles from one city to eight, the scheduled ones dashed; slide the flight to New York along its way.

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

London’s flights out, each along its great circle, the shortest way on the earth: a polyline of two points with geodesic: true, listed beside the map, while the cities and the plane are on the map only. The flights still scheduled are dashed, and the one to New York is in the air: drawn active, travelled as far as the slider says, with its plane there.

  • Try it: pick a flight in the list and the map goes to it, drawn heavier; click a flight on the map and the list follows. London to Tokyo crosses the Arctic, as the plane does. Drag the slider: the flight to New York fades behind its plane as it goes; hover or pick another flight and it draws over the active one.
  • HTML: a <script type="application/json"> inside <maplace-map> holding the data, as a path takes more than an attribute (Data); list and list-heading on the map (Map attributes); and a few lines of script for the slider, once the map is ready (maplace.whenReady()), setting the flight’s progress and the plane at Maplace.pointAlong through the element’s locations property (Properties and methods).
  • The looks: strokeDash: "dashed" in a flight’s style (Styles); active: true and progress on the flight in the air, its travelled part faded unless travelledStyle says otherwise (Polylines); the plane a marker at pointAlong(flight, progress) (A point along a line), moved with every new set of locations.
  • Script and Bundler: type: "polyline", path and geodesic on each flight (Curves and great circles), listed: false on each city (Common fields), and list: { container, heading } (List view options).
  • React: the same locations on <MaplaceProvider>, and <LocationList heading="Flights from London" /> beside the <MaplaceMap> (<LocationList>).
  • On MapLibre, a globe: globe on the map (globe: true in the options; in React, createAdapter={() => createMapLibreAdapter({ globe: true })}) opens it as the earth, with a “Globe” toggle that flattens it (Globe). The globe shows London’s half: turn it, or flatten it, to see every flight. Google’s map has no globe.

16 Trade lanes

Air and sea lanes by colour; hover one, pick one for its volume.

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

Sea and air lanes between ports and airports, each a bowed line in its mode’s colour, listed under Sea and Air.

  • Try it: hover a lane on the map and it is drawn wider; pick one, drawn wider still, on the map or in the list, for its volume in a popup. Shanghai to Los Angeles crosses the Pacific, the short way.
  • HTML: a <script type="application/json"> inside <maplace-map> holding the lanes (Data), and list and list-heading on the map (Map attributes).
  • Script and Bundler: curve on each lane (Curves and great circles), its group, its style, hoveredStyle and selectedStyle (Styles), its volume as content, and list: { container, heading } (List view options).
  • React: the same locations on <MaplaceProvider>, and <LocationList heading="Trade lanes" /> beside the <MaplaceMap> (<LocationList>).

17 Editable polygon

An area to edit: drag a corner, and the edit is written back.

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 three-cornered park you can edit: each edit is written back to the store and announced, for your page to save.

  • Try it: drag a corner, or the middle of an edge to add one; letting go calls the page’s save, which the site shows under the map.
  • HTML: a <script type="application/json"> inside <maplace-map> holding the polygon (Data), and a maplace-locationchange listener (Events).
  • Script and Bundler: type: "polygon", path and editable on a location (Polygons), and a locationChange listener (Events).
  • React: the same location, with onLocationChange on <MaplaceProvider> (Event props).

18 Markers and shapes together

A marker, a circle, an area and a line on one map and in one 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

A marker, a circle, a polygon and a polyline on one map and in one list: each location says what it is with its own type, and everything else about them works alike.

  • Try it: pick each entry in the list and the map goes to it. Click a shape or the marker on the map and the list follows.
  • HTML: list on the map, and a <script type="application/json"> inside <maplace-map> holding all four, as a path takes more than an attribute (Data).
  • Script and Bundler: type on each location (Markers, Circles, Polylines, Polygons), and list: { container } (List view options).
  • React: the same locations on <MaplaceProvider>, and <LocationList /> beside the <MaplaceMap> (<LocationList>).