PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 13, 2022

[FIXED] How do I remove the “Cancel” option from the Draw button on the Leaflet.draw plugin?

 July 13, 2022     angularjs, javascript, leaflet, leaflet.draw, web-deployment     No comments   

Issue

As seen in the image below, I’d like to remove the option to cancel a drawing. Here’s my code:


Solution

With that code you can remove the "cancel" button on all shapes:

L.DrawToolbar.prototype.getActions = function (handler) {
        return [
            {
                enabled: handler.completeShape,
                title: L.drawLocal.draw.toolbar.finish.title,
                text: L.drawLocal.draw.toolbar.finish.text,
                callback: handler.completeShape,
                context: handler
            },
            {
                enabled: handler.deleteLastVertex,
                title: L.drawLocal.draw.toolbar.undo.title,
                text: L.drawLocal.draw.toolbar.undo.text,
                callback: handler.deleteLastVertex,
                context: handler
            }
      
        ];
    }

Original code: Doc

Also you can allow the cancel button for handlers when you add a if and test if the correct handler is passed.

PS: For a newer "leaflet-draw" you can use Leaflet-Geoman



Answered By - Falke Design
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing