javascript - 编辑传单中的功能属性

标签 javascript attributes leaflet edit

我希望允许用户在单击某个要素时编辑要素属性。我知道 ArcGIS JS API 有一个非常好的实现,但我无法使用 ArcGIS JS,因为我的功能是从 geojson 创建的。 此时我唯一拥有的是这个bindPopup 窗口,我想扩展它以便用户可以实际选择一个属性并编辑它。

我见过this帖子,但不知道如何将其应用到我的案例中。 不幸的是,谷歌搜索也没有帮助。

这是我的脚本,带有一个简单的弹出窗口。 任何帮助将不胜感激。

<script>
  var map = L.map('map').setView([52.52,13.384], 13);
  L.tileLayer('http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png').addTo(map);

  function onEachFeature(feature, layer) {
  if (feature.properties) {
      layer.bindPopup("<b>" + feature.properties.linkstr + "</b> has flow " + feature.properties.flow + ".");
    }
  }

  var streets = new L.geoJson(arcs, {
      onEachFeature: onEachFeature
  }).addTo(map);
</script>

最佳答案

这是一个非常简单粗暴的示例,希望能为您指明正确的方向。在 onEachFeature 函数中,您可以直接访问该功能,以便对其进行编辑:

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

以下是 Plunker 的示例:http://plnkr.co/edit/VzUfSD?p=preview

关于javascript - 编辑传单中的功能属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32834401/

相关文章:

javascript - 在 HTML 表格单元格中附加背景颜色

javascript - 按钮 onclick 在其位置更改时不会触发

java - 私有(private)最终静态属性与私有(private)最终属性

Python:仅将 csv 文件中的一些属性提取到 numpy 数组

c# - ASP.NET MVC 显示没有时间的日期

reactjs - React-leaflet 获取当前 latlng onClick

javascript - 使用正则表达式删除 phpbb 标签

javascript - 如何在不使用 margin 属性的情况下将内容居中放置在 div 中

leaflet - 如何将默认标记替换为航点中的自定义图标(传单路由)

javascript - 在其他标记之上显示传单circleMarker?