Edit feature attributes in leaflet

只谈情不闲聊 提交于 2019-12-02 01:48:22

Here's a very simple and crude example which hopefully will point you in the right direction. In the onEachFeature function you have direct access to the feature so you can edit it:

function onEachFeature (feature, layer) {
    // Create an input
    var input = L.DomUtil.create('input', 'my-input');
    // Set a feature property as value
    input.value = feature.properties.name;
    // Add a listener to watch for change on input
    L.DomEvent.addListener(input, 'change', function () {
        // Input changed, change property value
        feature.properties.name = input.value;
    });
    // Bind popup to layer with input
    layer.bindPopup(input);
}

Here's an example on Plunker: http://plnkr.co/edit/VzUfSD?p=preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!