Leaflet / Leaflet.draw

Vector drawing and editing plugin for Leaflet
https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html
MIT License
1.96k stars 992 forks source link

Drawing a rectangle using leaflet.draw library doesn't work (it throws error in console). #1070

Open abhi5057 opened 3 months ago

abhi5057 commented 3 months ago

How to reproduce

What behaviour I'm expecting and which behaviour I'm seeing

Expectation: I should've been able to create a rectangle by clicking and dragging the cursor. Observation: We're unable to drag the cursor to create a rectangle.

Minimal example reproducing the issue

abhi5057 commented 3 months ago

The issue is seen in readableArea function in leaflet.draw's code base. There's a wrong reference to type variable and hence we see the issue.

        readableArea: function (area, isMetric, precision) {
            var areaStr,
                units,
                precision = L.Util.extend({}, defaultPrecision, precision);

            if (isMetric) {
                units = ['ha', 'm'];
                type = typeof isMetric;
                if (type === 'string') {
                    units = [isMetric];
                } else if (type !== 'boolean') {
                    units = isMetric;
                }

Instead if we change to this.type in all the 3 references to type variable here, then we're able to draw rectangle, however we're unable to see its area while creating the rectangle though.