How do I refresh a TMS layer in OpenLayers?

1.9k views Asked by At

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.

2

There are 2 answers

1
igorti On BEST ANSWER

As TMS layers inherits from Grid layer you could try to call clearGrid() method to remove all existing tiles and then spiralTileLoad() to load new ones.

0
rutsky On

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({});