Search code examples
loopsopenlayerstile

OpenLayers loop layers function


In OpenLayers, I have a button (show), when I press on it, I got a layer on the map

My question: How can I show many layers consequently With a certain frame rate (Something like a loop!)


Solution

  • to show a new/other layer every X seconds, use setInterval

    let's assume that you somehow got an array of dates for which you have tiles, and a function displayLayerByDate(dateObject) that can show the layer.

    function animatedLayers(arrayOfDates) {
      let currentIdx = 0;
      const handle = setInterval(function() {
        const currentDate = arrayOfDates[currentIdx];
        displayLayerByDate(dateObject);
      }, 5000); 
    }