1

The default behaviour of Leaflet Draw is to expect a single click to create vertices for lines and polygons. I find this impractical, especially for mobile devices. For example when I try to draw a polygon on mobile phone and start dragging/zooming the map while drawing, the touch input is automatically registered as a vertex input. Is there a way to modify Leaflet Draw to prevent this?

I am using Leaflet.draw 1.0.4 with leaflet 1.7.1

Code adding the Draw Control to the map:

    // Leaflet Draw Control 

var customIcon = L.icon({
        iconUrl: 'marker.png',
        iconSize: [30, 30],
        iconAnchor: [15, 25],
        popupAnchor: [-3, -76] });
    
var drawControl = new L.Control.Draw({
    edit: {
        featureGroup: drawnItems
    },
    draw: {
        polygon: {
            shapeOptions: {
                color: '#94e50e',
                opacity: 1
            },
            showArea: true,
            metric: true
        },
        polyline: {
            shapeOptions: {
                color: '#94e50e',
                opacity: 1
            },
            showLength: true,
            metric: true
        },
        rectangle: false,
        circle: false,
        marker: {
            icon: customIcon
        },
        circlemarker: false
    } }); map.addControl(drawControl);
0

1 Answer 1

1

Taken from leaflet.draw issue #935

L.Draw.Polyline.prototype._onTouch = L.Util.falseFn;

Panning or Zooming while drawing Polylines and Polygons does not create new vertices. Tested on Mobile and Desktop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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