I want to display an indoor map. My problem is that when I change to another floor (the URL changes) the tiles are not refetched. The following code is used:

var indoorSource = new ol.source.XYZ({
    crossOrigin: null,
    tileUrlFunction: parseUrl,
    maxZoom: 45
var indoorLayer = new ol.layer.Tile({
    source: indoorSource

The parseUrl function is the following:

var parseUrl = function (tileCoords, pixelRatio, projection) {
    var url = '{z}/{level}/{x}/{y}';
    var innerMap = LocalUserData.currentInnerMap();

    url = url.replace('{level}', innerMap.level || 0);
    url = url.replace('{z}', tileCoords.z || 0);
    url = url.replace('{x}', tileCoords.x || 0);
    url = url.replace('{y}', tileCoords.y || 0);
    return url;

Is there a way to force a reload of the tiles?

  • I have found that reprojection makes none of the above options work on XYZ
    – ScottH
    Oct 18, 2016 at 21:37

3 Answers 3


There are 2 ways to avoid getting cached data.

  1. Add additional parameter in your request and make it's value to Math.random() , so every time browser will deal with this request as new and will fetch it from source and will not depend on cache. for example:
var mr = Math.random();  
var url = '{z}/{level}/{x}/{y}&AutoKey=' + mr ;
  1. Another way that you use POST in your request instead of GET, indeed you are forcing the browser to get data from server.

I have already went through a similar issue specially with IE but my problem was fetching cached vector data while they have been changed already.


I have the same problem and finally I could fix it. You can see here

Use this refresh function whenever you need:

function refresh() {
    var source = layer.getSource();

Dispatching a change event from your source notifies the map something has changed and should redraw the layer.



  • I tried that but it does not work. Probably because the XYZ source uses an internal cache which uses x, y, z parameters for equality, those don't change so the tiles are not reloaded. Maybe I have to provide my own Tile Source implementation but would be glad if there is a simpler solution.
    – megges
    Mar 28, 2014 at 13:32
  • 1
    I guess source.setTileUrlFunction may have work, as it clears the cache, but seems not to be exported ( github.com/tonio/ol3/blob/default_editing_style/src/ol/source/… )
    – tonio
    Mar 28, 2014 at 13:38
  • 1
    That works. I'm using the following the following code to reload the tiles: var refreshTiles = function () { indoorSource.setTileUrlFunction(parseUrl); };
    – megges
    Mar 28, 2014 at 14:01
  • For me, for a local xyz tile layer, this method of calling setTileUrlFunction() on the layer's source is the only thing that appears to work to cause openlayers to re-query all the layer's tiles.
    – M Katz
    Jun 13, 2015 at 2:16
  • Update: Now that I'm using OpenLayers 6, the solution by @Ahmad Azimi works for me.
    – M Katz
    Apr 1, 2023 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.