首页 > 解决方案 > 如何刷新openlayers中的单个图块?

问题描述

我正在尝试构建一个随时间变化的应用程序。到目前为止,我只能刷新整个图块源。但是,每当您刷新它时,整个图片都会短暂闪烁 - 图片被删除并重新绘制。但是,如果图块正在加载,则仅重绘加载新图块的部分图像。我想得到类似的行为

var Source=new ol.source.OSM({
                url: 'http://localhost:900/{z}-{x}-{y}.png',
                attributions:[],
                wrapX: false    ,
                tileLoadFunction:function(imageTile, src) {var mr = Math.random();    imageTile.getImage().src = src+'?t='+mr;}
            });

加上清爽:

Source.tileCache.expireCache({});
            Source.tileCache.clear();
            Source.refresh();

标签: openlayers

解决方案


我解决了它 - 你不能刷新整个源,而只是从缓存中删除磁贴:

function RefreshIndividual(z,x, y) {
            var index= z+'-'+x+'-'+y;
            var index2= z+'/'+x+'/'+(-y-1);
            updateTimes[index] = new Date().getTime();
            console.log(index,'t'+updateTimes[index]);
            Source.tileCache.remove(index2);
            Source.changed();

        }

推荐阅读