【问题标题】:How to delete a selected shape in openlayers如何在openlayers中删除选定的形状
【发布时间】:2016-03-10 07:52:13
【问题描述】:

我目前正在看到这个 openlayers 示例 (http://openlayers.org/en/v3.14.2/examples/draw-features.html),它在地图上绘制线条、圆圈等。我编辑了代码以便能够选择绘图。我想知道如何删除选定的图纸?以下是我选择图纸的方法:

var select = new ol.interaction.Select();

有什么想法吗?谢谢!

【问题讨论】:

标签: javascript openlayers-3


【解决方案1】:

您可以在选择该要素后通过将其从图层中删除来删除该要素。在交互中选择的功能上使用“添加”侦听器,并将其从图层源中删除。 使用

select = new ol.interaction.Select();
select.getFeatures().on('add', function(feature){
  //source is layer.getSource()
  source.removeFeature(feature.element);
  feature.target.remove(feature.element);
});
map.addInteraction(select);

JSFiddle 链接(在下拉列表中选择删除以选择和删除功能): http://jsfiddle.net/anushamc/edms856o/

【讨论】:

    猜你喜欢
    • 2017-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多