Get started with leaflet-contextmenu CDN
MIT licensed
Library leaflet-contextmenu: JS plugin for custom context menus on Leaflet maps.
Tags:- leaflet
- contextmenu
- mixin
- context
- menu
Stable version
Copied!
How to start using leaflet-contextmenu CDN
<!DOCTYPE html>
<html>
<head>
<title>Get started with leaflet-contextmenu CDN - cdnhub.io</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/leaflet/1.7.1/leaflet.css"/>
<script src="https://cdn.jsdelivr.net/leaflet/1.7.1/leaflet.js"></script>
<script src="https://cdn.cdnhub.io/leaflet-contextmenu/1.4.0/leaflet.contextmenu.min.js"></script>
<style>
#mapid { height: 400px; width: 100%; }
</style>
</head>
<body>
<div id="mapid"></div>
<script>
const map = L.map('mapid').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
maxZoom: 19
}).addTo(map);
L.contextMenu('contextmenu', [
{
text: 'Add Marker',
callback: function(ev) {
L.marker(ev.latlng).addTo(map);
}
}
]).addTo(map);
map.on('contextmenu', function(ev) {
this.openContextMenu('contextmenu', ev.latlng);
});
</script>
</body>
</html>
Copied!
Copied!
Copied!
Copied!