Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 小叶中的重绘标记_Javascript_Leaflet - Fatal编程技术网

Javascript 小叶中的重绘标记

Javascript 小叶中的重绘标记,javascript,leaflet,Javascript,Leaflet,我正试图重新绘制一组标记。图标源每分钟都在生成,但当我刷新站点时,标记仍在使用图标(该图标已存在) var markers = new L.LayerGroup().addTo(map); function createMarkers() { //Markers_start kopankyM = L.marker([48.9585,17.791666666667]).bindPopup("").bindLabel('6 kt, 90°', { noHide: true }).setIcon(n

我正试图重新绘制一组标记。图标源每分钟都在生成,但当我刷新站点时,标记仍在使用图标(该图标已存在)

var markers = new L.LayerGroup().addTo(map);

function createMarkers() {
//Markers_start
kopankyM = L.marker([48.9585,17.791666666667]).bindPopup("").bindLabel('6 kt, 90°', { noHide: true }).setIcon(new icon({iconUrl: 'img/kopanky.png'})).addTo(markers);
hvezdarnaM = L.marker([49.037666666667,17.646]).bindPopup("").bindLabel('11 kt, 145°', { noHide: true }).setIcon(new icon({iconUrl: 'img/hvezdarna.png'})).addTo(markers);
banovM = L.marker([48.984166666667,17.704333333333]).bindPopup("").bindLabel('15 kt, 180°', { noHide: true }).setIcon(new icon({iconUrl: 'img/banov.png'})).addTo(markers);
bojkoviceM = L.marker([48.984166666667,17.704333333333]).bindPopup("").bindLabel('11 kt, 180°', { noHide: true }).setIcon(new icon({iconUrl: 'img/bojkovice.png'})).addTo(markers);
vyskovM = L.marker([49.300166666667,17.025166666667]).bindPopup("").bindLabel('11 kt, 180°', { noHide: true }).setIcon(new icon({iconUrl: 'img/vyskov.png'})).addTo(markers);
uhhradisteM = L.marker([49.072833333333,17.462333333333]).bindPopup("").bindLabel('5 kt, 45°', { noHide: true }).setIcon(new icon({iconUrl: 'img/uhhradiste.png'})).addTo(markers);
//Markers_end
console.log("createMarkers");
}

createMarkers();
//createIcons();

setInterval(function(){
    markers.clearLayers();
    createMarkers();
    //createIcons();
}, 10000);

我应该添加或编辑什么才能使其正常工作?

听起来,出于这样或那样的原因,浏览器不会重新加载图像,而是使用缓存的图像

可能有几种解决方案,但其中一种可能不是很优雅,就是向图标URL添加一个虚假的查询参数,迫使浏览器重新加载它:

function createMarkers() {
//Markers_start
kopankyM = L.marker([48.9585,17.791666666667]).bindPopup("").bindLabel('6 kt, 90°', { noHide: true }).setIcon(new icon({iconUrl: 'img/kopanky.png?_cache=' + Math.random()})).addTo(markers);
hvezdarnaM = L.marker([49.037666666667,17.646]).bindPopup("").bindLabel('11 kt, 145°', { noHide: true }).setIcon(new icon({iconUrl: 'img/hvezdarna.png?_cache=' + Math.random()})).addTo(markers);
banovM = L.marker([48.984166666667,17.704333333333]).bindPopup("").bindLabel('15 kt, 180°', { noHide: true }).setIcon(new icon({iconUrl: 'img/banov.png?_cache=' + Math.random()})).addTo(markers);
bojkoviceM = L.marker([48.984166666667,17.704333333333]).bindPopup("").bindLabel('11 kt, 180°', { noHide: true }).setIcon(new icon({iconUrl: 'img/bojkovice.png?_cache=' + Math.random()})).addTo(markers);
vyskovM = L.marker([49.300166666667,17.025166666667]).bindPopup("").bindLabel('11 kt, 180°', { noHide: true }).setIcon(new icon({iconUrl: 'img/vyskov.png?_cache=' + Math.random()})).addTo(markers);
uhhradisteM = L.marker([49.072833333333,17.462333333333]).bindPopup("").bindLabel('5 kt, 45°', { noHide: true }).setIcon(new icon({iconUrl: 'img/uhhradiste.png?_cache=' + Math.random()})).addTo(markers);
//Markers_end
console.log("createMarkers");
}
另一个解决方案是检查浏览器缓存图像的原因-可能图标图像的缓存头设置不正确?

谢谢帮助,“缓存代码”工作正常。关于标题我什么都不知道,所以如果没有必要,我会尽量避免。这些图像是由PHP脚本生成的,我很高兴它能工作——我也有一些问题。