Dr.YSG
Dr.YSG

Reputation: 7591

leaflet.draw not showing distance markup

As shown below, with leaflet 1.0 and leaflet draw 0.2.4 I was getting text distance for lines, and area for rectangles.

Now I only get the area for circles, but the others do not show anything. Is this just me, and why does the below no longer work?

(I.e. I no longer see the 1425.65 km as shown below).enter image description here

function addDrawLayer() {
    var options = null
    var map = MAP.map
    var drawings = new L.FeatureGroup()
    MAP.drawLayer = drawings
    map.addLayer(drawings)

    options = {
        shapeOptions: {
            showArea: true,
            clickable: true
        },
        metric: true,
        edit: {
            featureGroup: drawings
        }
    }
    var drawControl = new L.Control.Draw(options)
    map.addControl(drawControl)
    map.on('draw:created', function (e) {
        var type = e.layerType
        var layer = e.layer
        if (type === 'marker') {
            layer.bindPopup('A popup!')
        }
        drawings.addLayer(layer)
    });
}

Upvotes: 0

Views: 1140

Answers (1)

Jon West
Jon West

Reputation: 27

Leaflet.Draw Issue

There was a bug for 0.4.9 that has been patched to 0.4.10 - However, Leaflet.Draw does not work with Leaflet 1.1.0 yet and it appears there are still some issues with the distance markup.

Whilst, your options object is the improper schema. ShapeOptions are part of each draw item may have a shapeOption for that draw tool.

draw: polygon: {shapeOptions: {showArea: true} }

JSFiddle

Upvotes: 1

Related Questions