Util methods for animation loops.
This commit is contained in:
@@ -1697,3 +1697,40 @@ OpenLayers.Util.getFormattedLonLat = function(coordinate, axis, dmsOption) {
|
|||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
OpenLayers.Util.requestAnimationFrame = (function() {
|
||||||
|
return window.requestAnimationFrame ||
|
||||||
|
window.webkitRequestAnimationFrame ||
|
||||||
|
window.mozRequestAnimationFrame ||
|
||||||
|
window.oRequestAnimationFrame ||
|
||||||
|
window.msRequestAnimationFrame ||
|
||||||
|
function(callback, element) {
|
||||||
|
window.setTimeout(callback, 16);
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var counter = 0;
|
||||||
|
var loops = {};
|
||||||
|
var request = OpenLayers.Util.requestAnimationFrame;
|
||||||
|
|
||||||
|
OpenLayers.Util.loopAnimation = function(duration, callback, element) {
|
||||||
|
var id = ++counter;
|
||||||
|
var start = +new Date;
|
||||||
|
loops[id] = function() {
|
||||||
|
if (loops[id] && +new Date - start <= duration) {
|
||||||
|
callback();
|
||||||
|
request(loops[id], element);
|
||||||
|
} else {
|
||||||
|
delete loops[id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request(loops[id], element);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenLayers.Util.stopAnimation = function(id) {
|
||||||
|
delete loops[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user