2017-08-01 343 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)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。也請儘量不要用解釋性註釋來擠佔代碼,這會降低代碼和解釋的可讀性! –