如何从 Leaflet.draw 插件的绘图按钮中删除“取消”选项?

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

如下图所示,我想去掉取消绘图的选项。这是我的代码:

使用该代码,您可以删除所有形状上的“取消”按钮:

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
            }
      
        ];
    }

原代码:Doc

您还可以在添加 if 并测试是否传递了正确的处理程序时允许处理程序的取消按钮。

PS:对于较新的“leaflet-draw”,您可以使用 Leaflet-Geoman