Created
February 20, 2017 07:23
-
-
Save ebrensi/b14b550f21e76b796b1c5b4e5efc1a16 to your computer and use it in GitHub Desktop.
fps display control for leaflet.js
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
/* fps display control for leaflet*/ | |
/* Efrem Rensi 2017/2/19 */ | |
L.Control.fps = L.Control.extend({ | |
lastCalledTime: 1, | |
options: { | |
position: "topright" | |
}, | |
onAdd: function (map) { | |
// Control container | |
this._container = L.DomUtil.create('div', 'leaflet-control-fps'); | |
L.DomEvent.disableClickPropagation(this._container); | |
this.update(0); | |
return this._container; | |
}, | |
update: function(now=Date.now()) { | |
let fps = 500 / (now - this.lastCalledTime); | |
this._container.innerHTML = "FPS: " + 2 * Math.floor(fps); | |
this.lastCalledTime = now; | |
return fps | |
} | |
}); | |
//constructor registration | |
L.control.fps = function(options) { | |
return new L.Control.fps(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment