2017-08-01 337 views
0

我加入 “画互动” 和绘图功能在地图上...的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”是不是做这个的地方......但我不知道如何实现我需要那么功能...

任何帮助是极大的赞赏!

回答

0

如果您看ol.interaction.Draw()交互的代码drawend在功能插入到ol.source之前调用。

finishDrawing()方法会插入特征对象。

下面是最新的sourcecode

的片段/ ** *停止绘制并添加草图功能,目标层。在插入要素之前调度 {@link ol.interaction.DrawEventType.DRAWEND}事件。 * @api */

ol.interaction.Draw.prototype.finishDrawing =函数(){

所以你不能删除该功能在drawend事件。上面的代码片断是自解释的。

+0

那么我该如何达到理想的行为呢?我可以以某种方式调用finishDrawing并停止绘制草图功能? –

-1
function noDraw() { 

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


}; 
+0

虽然此代码段可能会解决问题,但[包括解释](// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)确实有助于提高帖子的质量。请记住,您将来会为读者回答问题,而这些人可能不知道您的代码建议的原因。也请尽量不要用解释性注释来挤占代码,这会降低代码和解释的可读性! –