如何在多边形传单中绘制文本

时间:2017-04-12 05:47:08

标签: javascript leaflet

    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
    }
});

朋友你好,      我正在使用传单绘制来绘制多边形,但是在绘制多边形之后我想在该多边形内显示文本,这是否可行。

谢谢

2 个答案:

答案 0 :(得分:1)

我使用bootbox对话框询问文字,bindTooltip留下文字。

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});
            }
    });

答案 1 :(得分:0)

尝试使用L.Tooltip并将permanent设置为true

Leaflet.Draw github,此代码段与弹出窗口一起使用:

map.on(L.Draw.Event.CREATED, function (e) {
    var type = e.layerType,
        layer = e.layer;

    if (type === 'marker') {
        layer.bindPopup('A popup!');
    }

    editableLayers.addLayer(layer);
});

您可以修改该代码段以添加工具提示。