Search code examples
javascriptleaflet

How write text inside polygon leaflet draw


    var drawnItems = new L.FeatureGroup();
leafletMap.addLayer(drawnItems);

L.drawLocal.draw.toolbar.buttons.polygon = 'Draw  polygon!';

var drawControl = new L.Control.Draw({
    position: 'topright',
    draw: {
        polyline: {
            metric: true
        },

        polygon: {
            allowIntersection: false,
            showArea: true,
            drawError: {
                color: '#b00b00',
                timeout: 1000
            },

            shapeOptions: {
                color: '#bada55'
            }
        },
        circle: {

            shapeOptions: {
                color: '#662d91'
            }
        },
        circle:false,
        marker: false
    },
    edit: {
        featureGroup: drawnItems,
        remove: true
    }
});

Hello friends, i am using leaflet draw to draw polygon ,but after polygon is draw i want to show text inside that polygon, does that is possible.

thank you


Solution

  • I use a [bootbox] 1 dialog to ask for the text and [bindTooltip] 2 to put the text.

    map.on(L.Draw.Event.CREATED, function(e) {
        var layer = e.layer;
        bootbox.prompt({title: "Any comment?", closeButton: false, callback: putTooltip});
            function putTooltip(result) {
                layer.bindTooltip(result, {'permanent': true, 'interactive': true});
                }
        });