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/v5.3.0/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
</head>
<body>
<div id="map" class="map"></div>
<label>
render with an opacity transition
<input id="transition" type="checkbox" checked>
</label>
<script>
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import XYZ from 'ol/source/XYZ.js';
var url = 'https://{a-c}.tiles.mapbox.com/v3/mapbox.world-bright/{z}/{x}/{y}.png';
var withTransition = new TileLayer({
source: new XYZ({url: url})
});
var withoutTransition = new TileLayer({
source: new XYZ({url: url, transition: 0}),
visible: false
});
var map = new Map({
layers: [withTransition, withoutTransition],
target: 'map',
view: new 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>