1
我在我的網頁中有一個div,其中包含許多選項卡,每個選項卡中都包含一個開發者地圖。將事件綁定到openlayer3地圖
問題是,當我使用下面的代碼附加一個單擊事件到地圖,它不工作。
但是,當我使用下面的代碼附加事件其工作正常。
//create map in given div ID//
createMap : function(id) {
var _this = this;//To refer this dojo AMD module
//Array of maps.
//_this.index to track the total no. of maps.
_this.maps[_this.index] = new ol.Map({
controls: [],
interactions: [],
//layers: [_this.raster],
target: id,
view: new ol.View({
center: [0, 0],
zoom: 4,
})
});
//get the latlong on
//map click
var thisMap = _this.maps[_this.index];
//Attaching the event
_this.maps[_this.index].getViewport().addEventListener("click", function(evt){
console.log(evt);
});
}
但我不希望使用第二種方法,因爲第一種方法是openlayer的一部分註冊事件,我可以用的MouseEvent參數做這麼多事情像我能得到的緯度和經度直。
此前都被用來工作,但後來我使用Dojo小部件後第一個方法停止工作重新創建我的GUI。
任何人都可以幫我解決問題嗎?或者使用第一種方法需要額外的東西?
是如何從OP的代碼,這有什麼不同? – balajeerc