Skip to content

Instantly share code, notes, and snippets.

@Scarysize
Created April 14, 2018 12:48
Show Gist options
  • Save Scarysize/df6890d590323cb605cee6041045d36c to your computer and use it in GitHub Desktop.
Save Scarysize/df6890d590323cb605cee6041045d36c to your computer and use it in GitHub Desktop.
Basic mapbox-gl animation loop necessary for smoothly animating GeoJSON sources.
const source = this.map.getSource('my-source');
function loop() {
source.on('data', requestFrame);
source.setData(updatedGeoJson);
}
function requestFrame(event) {
if (event.dataType !== 'source') {
return;
}
source.off('data', this.requestFrame);
requestAnimationFrame(loop);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment