使用jsfiddle here,想要检查正确的方法,将第2个标记{2}的icon
fillColor
按顺序更改为["#FF0000", "#00FF00", "#0000FF"]
之一到["#0000FF", "#00FF00", "#FF0000"]
之一作为第二个标记。我应该使用setInterval
吗?
答案 0 :(得分:2)
这可能就是你的目标
let x = 1;
setInterval(() => {
let newShade;
switch (x) {
case 1:
newShade = colors[0];
x = 2;
break;
case 2:
newShade = colors[1];
x = 3;
break;
case 3:
newShade = colors[2];
x = 1;
break;
}
let count = 0;
console.log(`Running fn inside setInterval`);
for (let marker of markers) {
console.log(`trying to get icon for ${count+=1} ${marker}`)
let icon = marker.getIcon();
icon.strokeColor = newShade;
icon.fillColor = newShade;
marker.setIcon(icon);
}
}, 5000);