Tile Transitions

Custom configuration for opacity transitions on tiles.

By default tiles are rendered with an opacity transition - fading in over 250 ms. To disable this behavior, set the transition option of the tile source to 0.

<!DOCTYPE html>
<html>
  <head>
    <title>Tile Transitions</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.6.4/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src=""></script>
    <script src="https://openlayers.org/en/v4.6.4/build/ol.js"></script>
  </head>
  <body>
    <div id="map" class="map"></div>
    <label>
      render with an opacity transition
      <input id="transition" type="checkbox" checked>
    </label>
    <script>
      var url = 'https://{a-c}.tiles.mapbox.com/v3/mapbox.world-bright/{z}/{x}/{y}.png';

      var withTransition = new ol.layer.Tile({
        source: new ol.source.XYZ({url: url})
      });

      var withoutTransition = new ol.layer.Tile({
        source: new ol.source.XYZ({url: url, transition: 0}),
        visible: false
      });

      var map = new ol.Map({
        layers: [withTransition, withoutTransition],
        target: 'map',
        view: new ol.View({
          center: [0, 0],
          zoom: 2,
          maxZoom: 11
        })
      });

      document.getElementById('transition').addEventListener('change', function(event) {
        var transition = event.target.checked;
        withTransition.setVisible(transition);
        withoutTransition.setVisible(!transition);
      });
    </script>
  </body>
</html>