TrackAsiaTrackAsia GL JS DocsExamplesAnimate a series of images

Animate a series of images

Use a series of image sources to create an animation.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Animate a series of images</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src="https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.js"></script>
<link href="https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.css" rel="stylesheet" />
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = new trackasiagl.Map({
container: 'map',
style: 'https://maps.track-asia.com/styles/v1/streets.json?key=public_key',
maxZoom: 6,
minZoom: 3,
zoom: 4,
center: [107.595111,16.577234]
});
var frameCount = 5;
var currentImage = 0;
function getPath() {
return (
'https://docs.track-asia.com/assets/radar' + currentImage + '.gif'
);
}
map.on('load', function () {
map.addSource('radar', {
type: 'image',
url: getPath(),
coordinates: [[105.484359,16.071151],[116.301964,16.071151],[116.301964,6.9526],[105.484359,6.9526]]
});
map.addLayer({
id: 'radar-layer',
'type': 'raster',
'source': 'radar',
'paint': {
'raster-fade-duration': 0
}
});
setInterval(function () {
currentImage = (currentImage + 1) % frameCount;
map.getSource('radar').updateImage({ url: getPath() });
}, 200);
});
</script>
</body>
</html>