Maplace.js

Circles and polygons

Editable polygon

A polygon to edit: drag a corner, and the edit is written back.

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>
<!-- An editable area; edits are written back and announced. -->
<maplace-map id="polygon-maplibre-map">
  <script type="application/json">
    [{ "id": "park", "type": "polygon", "title": "Hyde Park", "editable": true,
       "path": [{ "lat": 51.512, "lng": -0.175 }, { "lat": 51.513, "lng": -0.16 }, { "lat": 51.503, "lng": -0.155 }] }]
  </script>
</maplace-map>
<script>
  document.getElementById('polygon-maplibre-map').addEventListener('maplace-locationchange', (event) => save(event.detail.location));
</script>

How it works

A three-cornered park you can edit: each edit is written back to the store and announced, for your page to save.

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