Free Version
Installation
Supported Leaflet versions
Leaflet-Geoman Free 2.20 works with Leaflet 1.2 and later in the 1.x line (its peer dependency is leaflet@^1.2.0). Our guides and examples are tested with Leaflet 1.9.4, the latest stable Leaflet release. Leaflet 2.0 is still in beta and falls outside that peer range, so stay on Leaflet 1.9.x for production. See the changelog for Geoman releases.
npm i leaflet@^1.9.4 @geoman-io/leaflet-geoman-free@^2.20.6
Install via npm
npm i @geoman-io/leaflet-geoman-free@^2.20.6
Install Manually
Download leaflet-geoman.css and leaflet-geoman.js and include them in your project.
Include via CDN
CSS
<link
rel="stylesheet"
href="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.css"
/>
JS
<script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.js"></script>
Include as ES6 Module
import * as L from "leaflet";
import "leaflet/dist/leaflet.css";
import "@geoman-io/leaflet-geoman-free";
import "@geoman-io/leaflet-geoman-free/dist/leaflet-geoman.css";
Getting Started
Init Leaflet-Geoman
Just include leaflet-geoman.js right after Leaflet. It initializes itself.
Exclude layers
If you want certain layers to be ignored by Leaflet-Geoman, pass pmIgnore: true to
their options when creating them.
Example:
L.marker([51.50915, -0.096112], { pmIgnore: true }).addTo(map);
Enable Leaflet-Geoman again on an ignored layer:
layer.options.pmIgnore = false;
L.PM.reInitLayer(layer);
This logic is reversed when using Opt-In (see below).
Opt-In
This section is only relevant if you don't want Leaflet-Geoman to initialize itself. If you want to use Leaflet-Geoman as Opt-In, call the following function right after importing:
L.PM.setOptIn(true);
And to disable it:
L.PM.setOptIn(false);
To enable Leaflet-Geoman on a map or a layer, you need to pass pmIgnore: false so they are not ignored anymore.
Enable on a map:
const map = L.map("map", { pmIgnore: false });
Enable on a layer:
L.marker([51.50915, -0.096112], { pmIgnore: false }).addTo(map);
Opt-In also causes newly drawn layers to be ignored. You can initialize them right after they have been drawn like this:
map.on("pm:create", (e) => {
e.layer.options.pmIgnore = false;
L.PM.reInitLayer(e.layer);
});