[英]How to Update marker icon's source in Leaflet
I'm creating x markers on map in leaflet. 我正在传单中的地图上创建x标记。 (Generating via php script, but it shouldn't be important) Problem is, that I generate new image every 60 seconds, but icons on web maps are not updating. (通过php脚本生成,但这并不重要)问题是,我每60秒生成一次新图像,但是网络地图上的图标没有更新。
I want to update icons every X seconds - not important again. 我想每X秒更新一次图标-不再重要。 I couldn't find any methods to update icons. 我找不到任何更新图标的方法。 So I tried removing markers and them recreating them, but wasn't successful too - marker is not defined. 因此,我尝试删除标记,并重新创建它们,但也没有成功-标记未定义。 Is there any way how to do it? 有什么办法吗?
Edited code: 编辑代码:
var icon = L.Icon.extend({
options: {
iconSize: [35, 35]
}
});
function createIcons() {
//Icons_start
kopanky = new icon({iconUrl: 'img/kopanky.png'});
kopankyM.setIcon(kopanky);
kopankyM.update();
}
function testCreate() {
kopanky = new icon({iconUrl: 'img/hvezdarna.png'});
kopankyM.setIcon(kopanky);
kopankyM.update();
console.log("test");
}
function createMarkers() {
//Markers_start
kopankyM = L.marker([48.9585,17.791666666667]).bindPopup("Kopanky Bile Karpaty").bindLabel('9 kt, 145°', { noHide: true }).addTo(map);
}
createMarkers();
createIcons();
setInterval(function(){
testCreate();
}, 5000);
I can't refresh via meta-tag, because when I do it, I lost user's current map settings. 我无法通过元标记进行刷新,因为执行此操作时,我丢失了用户的当前地图设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.