2014-11-09 53 views

回答

2

我剛剛合併到主分支中,提交了一個可以解決您的用例的提交。見https://github.com/openlayers/ol3/pull/2927

通過此提交,您可以以編程方式完成繪圖。下面的代碼片段展示瞭如何終止線時,它有兩個頂點:

var listenerKey; 
drawInteraction.on('drawstart', function(e) { 
    var feature = e.feature; 
    var lineString = feature.getGeometry(); 
    // finish the drawing when the linestring has 2 vertices 
    listenerKey = lineString.on('change', function(e) { 
    var lineString = e.target; 
    var vertices = lineString.getCoordinates(); 
    if (vertices.length == 3) { 
     drawInteraction.finishDrawing(); 
    } 
    }); 
}); 
drawInteraction.on('drawend', function(e) { 
    ol.Observable.unByKey(listenerKey); 
}); 
+0

是否可以在發行版本3.0中模仿這個finishDrawing()函數? – Bill 2014-11-17 15:52:41

+0

不需要。您必須使用。 – erilem 2014-11-17 18:38:58