用openlayers3 绘制了一个点,可以选中、修改,如何删除这个要素? |
您所在的位置:网站首页 › openlayers3示例 › 用openlayers3 绘制了一个点,可以选中、修改,如何删除这个要素? |
删除draw的问题我也遇到了,leaflet用的比较多,那上面删除是删除layer就行,但这在openlayer中行不通了,我最后参考的是一个网友的做法。实测可行,但不确定是删除了这个draw实例还是只是清空了它的坐标。 var drawLayer = new ol.layer.Vector({ //layer所对应的source source: new ol.source.Vector(), }) var draw; let delete1; //把layer加入到地图中 map.addLayer(drawLayer); function addInteraction() { // draw = new ol.interaction.Draw({ // source: drawLayer.getSource(), // type: 'LineString' // }); // map.addInteraction(draw); draw = new ol.interaction.Draw({ source: drawLayer.getSource(), type: 'LineString', style: new ol.style.Style({ fill: new ol.style.Fill({ color: '#ffcc33' }), stroke: new ol.style.Stroke({ color: '#ffcc33', width: 2 }), image: new ol.style.Circle({ radius: 7, fill: new ol.style.Fill({ color: '#ffcc33' }) }) }) }); map.addInteraction(draw); draw.on('drawend', function (e) { delete1=(e.feature); // drawLayer.removeInteraction(e); // drawLayer.removeLayer(e); }) } addInteraction(); $("#c11").click(function(){ drawLayer.getSource().removeFeature(delete1); }) 只粘贴了关键的做法,总觉得哪里能删除layer,如果它保存了的话,目前removeFeature()功能能实现删除效果,可以先用着。 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |