2

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 = 'http://127.0.0.1/tiles/{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 '16 at 21:37
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 = 'http://127.0.0.1/tiles/{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.

1

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();
    source.tileCache.expireCache({});
    source.tileCache.clear();
    source.refresh();
}
0

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

indoorSource.dispatchChangeEvent()

http://ol3js.org/en/master/apidoc/ol.source.XYZ.html#dispatchChangeEvent

  • 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 '14 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 '14 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 '14 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 '15 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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