0
任何人都可以幫助我如何更新FeatureGroup中的標記以獲取單張嗎?我在該組中有數百個標記,但想要用戶點擊標記的圖標進行更改。到目前爲止我的代碼:操縱FeatureGroup中的單個標記
var swpts=new L.FeatureGroup();
var data; //an array of information for the markers
for (i=0; i<data.length; i++){
ticon=L.icon({
...//some stuff that has different types of icons for the different markers
});
var tmarker=L.marker([data[i].lat,data[i].lon], {icon: ticon});
tmarker.on('click', function(i){
return function(){
tmarker.setIcon(icons[include(nidilist,nidi)]);
//function to pull a new kind of icon out of an array icons
//plus other things to happen when the listener is activated which require
//access to i
};
}(i),false);
swpts.addLayer(tmarker);
};
swpts.addTo(map);
監聽器工作正常進行其他操作,但我似乎無法得到它來操縱FeatureGroup
實際標記。通常我沒有問題,因爲標記可以在偵聽器中引用自己,所以我不確定爲什麼.setIcon
在這裏不起作用。我也嘗試添加一個只改變圖標的簡單偵聽器,但這也不起作用。感謝您的任何幫助或建議。
感謝您的信息 - 我已經以不同的方式檢查了聽衆,並且確實在該級別工作。我還有其他的事情,也是在激活監聽器時發生的,並且他們工作正常。使用警報,我還發現'圖標'數組也被正確調用。它看起來特定於「setIcon」調用。 – user3398945 2014-09-04 09:00:06