Skip to content

Instantly share code, notes, and snippets.

@ebrensi
Created February 20, 2017 07:23
Show Gist options
  • Save ebrensi/b14b550f21e76b796b1c5b4e5efc1a16 to your computer and use it in GitHub Desktop.
Save ebrensi/b14b550f21e76b796b1c5b4e5efc1a16 to your computer and use it in GitHub Desktop.
fps display control for leaflet.js
/* 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