Openlayers 3删除绘制的功能

时间:2017-08-01 15:07:27

标签: openlayers openlayers-3

我在地图上添加“绘制互动”和绘制功能......

 webMapValues.drawObj = new ol.interaction.Draw({                                
                            features: features,
                            type: /** @type {ol.geom.GeometryType} */ (webMapValues.drawType)

                        });

我正在捕捉“drawend”事件......

 webMapValues.drawObj.on('drawend', function (e) {                            

                        //Here I am saving my feature to a data base
                          and displaying the saved vector...
                        control.UpdateObjects(e, "Draw");

                        //Here I would like to remove the vector that
                          draw interaction placed and just display the 
                          vector from the db


                    });

我无法弄清楚如何删除ol.interaction.Draw所放置的向量,以便在保存后只显示数据库中的向量?

我猜'drawend'不是这样做的地方......但我不确定如何实现我需要的功能......

非常感谢任何帮助!!

2 个答案:

答案 0 :(得分:1)

如果您在将功能插入ol.interaction.Draw()之前查看drawend互动ol.source的代码,请执行此操作。

finishDrawing()方法将插入要素对象。

以下是最新sourcecode

的摘要
  

/ ** *停止绘图并将草图特征添加到目标图层。

     

调度{@link ol.interaction.DrawEventType.DRAWEND}事件   在*插入功能之前。 * @api * /

     

ol.interaction.Draw.prototype.finishDrawing = function(){

因此您无法删除drawend事件中的功能。上面的代码片段是不言自明的。

答案 1 :(得分:-1)

function noDraw() {

  if (draw) {
        map.removeInteraction(webMapValues.drawObj);
  }


};
相关问题