简体   繁体   中英

How do I refresh a TMS layer in OpenLayers?

I have a TMS layer that looks something like this:

var v = 1;
my_tms = new OpenLayers.Layer.TMS(
    "My TMS",
    "my_mapserver.php?v="+my_var+"&",
     { transparent: 'true', type:'png', getURL:get_my_url }
);

Where my_mapserver.php returns map tiles according to the value of v.

The app allows users to change v, and I simply want to refresh the my_tms layer, however, so far the only way I can get it to refresh is by destroying the map and recreating it.

I thought I could just do something like this:

v = 2;
my_tms = new OpenLayers.Layer.TMS(
    "My TMS",
    "my_mapserver.php?v="+my_var+"&",
     { transparent: 'true', type:'png', getURL:get_my_url }
);
my_tms.redraw();

However, these tiles are not getting requested when I redraw().

Any help is appreciated.

由于TMS图层是从Grid图层继承的,因此您可以尝试调用clearGrid()方法来删除所有现有的图块,然后再调用spiralTileLoad()来加载新的图块。

layer.redraw(); , OpenLayers.Strategy.Refresh and clearGrid() didn't help me in reloading tiles of OpenLayers.Layer.TMS layer in OpenLayers 2.13.1, but helped:

layer.mergeNewParams({});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM