Created
September 10, 2012 17:20
-
-
Save tmcw/3692271 to your computer and use it in GitHub Desktop.
Spy on requests through MM and call a callback with ms inflight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function spy(layer, callback) { | |
var inflight = {}; | |
var rt = layer.requestManager.requestTile; | |
layer.requestManager.requestTile = function() { | |
inflight[arguments[0]] = +new Date(); | |
rt.apply(layer.requestManager, arguments); | |
}; | |
layer.requestManager.addCallback('requestcomplete', function(s, img) { | |
callback(+new Date() - inflight[img.id]); | |
delete inflight[img.id]; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment