I'm using Leaflet js and I want a user to be able to add a single point to the map (and not get trigger happy and add lots of pins), what do I need to do to modify the below so that this can happen.

map.on('click', function(e){
   var Marker = L.marker(e.latlng,{
       draggable: true



Here is an jQuery-based example where the user can click a button to enable adding a single marker. After adding a marker, the map click function is removed from the map - no additional markers can be added until the button is pressed again.


<button>Click to add a single marker</button>


$(button).on('click', function() {

function enableAddMarker() {
    map.on('click', addMarker)

function addMarker(e) {
    var Marker = L.marker(e.latlng,{
         draggable: true
    map.off('click', addMarker);


Maybe something like that:
Add a global variable to your code var count = 0;.
In your function add two things a line, count += 1.
In the function have an, if (count < 10){ draggable: true } else {draggable: false}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.