leaflet-draw delete button remove “clear all” action

后端 未结 2 1597
时光取名叫无心
时光取名叫无心 2021-01-18 06:09

How can I remove the \"clear all\" action from the delete button in the leaflet-draw edit toolbar?

I know you can remove the whole delete button but still need to re

2条回答
  •  心在旅途
    2021-01-18 06:32

    The edit toolbar tests the existence of a removeAllLayers member on the button handler. So, a simple but probably heavy handed way to disable the clear all action is to nuke removeAllLayers on the L.EditToolbar.Delete module:

    L.EditToolbar.Delete.include({
        removeAllLayers: false
    });
    
    new L.Control.Draw({
        edit: {
            featureGroup: drawnItems
        },
        draw: {
        }
    }).addTo(map);
    

    And a demo

    var map = L.map(document.getElementById('map'), {zoomControl: false}).setView([48.8583736, 2.2922926], 15);
    
    L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
        attribution: '© OpenStreetMap contributors'
    }).addTo(map);
    
    var drawnItems = new L.geoJson().addTo(map);
    
    map.on(L.Draw.Event.CREATED, function (event) {
        var layer = event.layer;
        drawnItems.addLayer(layer);
    });
    
    
    
    L.EditToolbar.Delete.include({
        removeAllLayers: false
    });
    
    new L.Control.Draw({
        edit: {
            featureGroup: drawnItems
        },
        draw: {
            polygon: false,
            rectangle: false,
            circlemarker: false
        }
    }).addTo(map);
    html, body {
      height: 100%;
      margin: 0;
    }
    #map {
      width: 100%;
      height: 100%;
    }
    
        
        
    
    
    
    

提交回复
热议问题