2017-05-05 302 views

回答

2

我很難自己找到解決方案,但在調試ol代碼後,我想出了這個解決方案。

當在ol中創建事件時,所有交互都從上次迭代到第一次。捕捉交互取代指針座標(如果捕捉)以及之前的所有交互(在迭代之後,因爲向後迭代)將獲得該座標。

所以,無論是在自定義交互運行代碼或打字稿使用自定義交互exctract座標,像這樣的例子:

let snapCoordinate: ol.Coordinate; 
let getSnapCoordinateInteraction = new ol.interaction.Interaction({ 
    handleEvent: (evt: ol.MapBrowserEvent) => { 
     snapCoordinate = evt.coordinate; 
     return true; 
    } 
}); 
this.map.addInteraction(getSnapCoordinateInteraction); 

// Snap, should always be last of all interactions that should use the snap coordinate. 
this.snap = new ol.interaction.Snap({ 
    source: this.source, 
}); 
this.map.addInteraction(this.snap);