I am visualizing features from geoserver with OpenLayers using WMTS; I allow users to delete features using WFS-T; after a feature is deleted I would like for it to be removed from the map; however, the feature remains, unless, I zoom into a level at which the feature had not previously been displayed.

I have found a question about a similar issue here; however, that question is about OpenLayers 3; and did not have any solutions that worked for me. I have tried the following methods of refreshing the layer (and none of them worked):

wmtsLayer.dispatchChangeEvent();  // Method 1

wmtsLayer.getSource().dispatchChangeEvent();  // 2

wmtsLayer.getSource().updateParams({"time": Date.now()});  // 3

wmtsLayer.getSource().changed();  // 4

map.updateSize();  // 5

wmtsLayer.getSource().refresh();  // 6

// 7:
var source = wmtsLayer.getSource();

// 8 (deleting the layer and making a new one):
fetch(WMTS_URL + "&time="+ new Date().getTime()).then(function(response) {
    return response.text();
}).then(function(text) {
    var result = parser.read(text);
    var options = optionsFromCapabilities(result, {
        layer: FULL_LAYER_NAME,
        matrixSet: SRS_NAME

    wmtsLayer = new TileLayer({
        opacity: 1,
        source: new WMTS((options))

How do I get a WMTS tile to update when a change is made to the data (in my case, a feature is removed)?

  • If you can change your application to use WMS in single tile mode instead of WMTS the problem with refreshing should go away. It would be slower to use WMS but not necessarily too much slower. – user30184 Oct 19 '18 at 19:04
  • I will look into whether or not using WMS is a viable alternative; thank you for the suggestion. – B. Jones Oct 19 '18 at 19:15

Time isn't a valid WMTS parameter, all the valid ones are set individually in the source, not as a parameters object so updateParams() won't work as it does for WMS. You could however try adding a dummy parameter to end of the url when loading. Hopefully the server won't object to an unexpected parameter if it's after all the required parmeters.

tileLoadFunction: function(imageTile, src) {
  imageTile.getImage().src = src + '&time=' + Date.now();

or when you have built the layer from Capabilities

wmtsLayer.getSource().setTileLoadFunction( function(imageTile, src) {
  imageTile.getImage().src = src + '&time=' + Date.now();
} );

That will override any browser caching, but tiles already loaded won't reload without a wmtsLayer.getSource().refresh()

  • Unfortunately, I already tried adding a dummy parameter to the end of the url (in method 8); it didn't work; based on your answer I tried doing my method 8 in combination with a source.refresh(); but that didn't work either. – B. Jones Oct 19 '18 at 19:53
  • Method 8 won't work, the dummy parameter is only used when fetching the capabilities document, it won't be used to build the source. There is no way to put it in the source. If you could simply append it to the base url as the first argument it would be ?time= but the server would probably reject that. – Mike Oct 19 '18 at 20:09
  • Alright, I get what you're saying now, that makes sense; and it works; thank you. – B. Jones Oct 22 '18 at 12:28

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.