debug tiles: fade rather than instant clear
This commit is contained in:
@ -3,14 +3,15 @@
|
|||||||
|
|
||||||
|
|
||||||
window.RenderDebugTiles = function() {
|
window.RenderDebugTiles = function() {
|
||||||
this.CLEAR_CHECK_TIME = 2; // check for tiles to clear every 2 seconds
|
this.CLEAR_CHECK_TIME = 0.25;
|
||||||
|
this.FADE_TIME = 2.0;
|
||||||
|
|
||||||
this.debugTileLayer = L.layerGroup();
|
this.debugTileLayer = L.layerGroup();
|
||||||
window.addLayerGroup("DEBUG Data Tiles", this.debugTileLayer, false);
|
window.addLayerGroup("DEBUG Data Tiles", this.debugTileLayer, false);
|
||||||
|
|
||||||
this.debugTileToRectangle = {};
|
this.debugTileToRectangle = {};
|
||||||
this.debugTileClearTimes = {};
|
this.debugTileClearTimes = {};
|
||||||
this.timer();
|
this.timer = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.RenderDebugTiles.prototype.reset = function() {
|
window.RenderDebugTiles.prototype.reset = function() {
|
||||||
@ -57,20 +58,39 @@ window.RenderDebugTiles.prototype.setState = function(id,state) {
|
|||||||
if (clearDelay >= 0) {
|
if (clearDelay >= 0) {
|
||||||
var clearAt = Date.now() + clearDelay*1000;
|
var clearAt = Date.now() + clearDelay*1000;
|
||||||
this.debugTileClearTimes[id] = clearAt;
|
this.debugTileClearTimes[id] = clearAt;
|
||||||
|
|
||||||
|
if (!this.timer) {
|
||||||
|
this.startTimer(clearDelay*1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
window.RenderDebugTiles.prototype.timer = function() {
|
window.RenderDebugTiles.prototype.startTimer = function(waitTime) {
|
||||||
|
var _this = this;
|
||||||
|
if (!this.timer) {
|
||||||
|
this.timer = setTimeout ( function() { _this.timer = undefined; _this.runClearPass(); }, waitTime );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.RenderDebugTiles.prototype.runClearPass = function() {
|
||||||
|
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
for (var id in this.debugTileClearTimes) {
|
for (var id in this.debugTileClearTimes) {
|
||||||
if (this.debugTileClearTimes[id] <= now) {
|
var diff = now - this.debugTileClearTimes[id];
|
||||||
this.debugTileLayer.removeLayer(this.debugTileToRectangle[id]);
|
if (diff > 0) {
|
||||||
delete this.debugTileClearTimes[id];
|
if (diff > this.FADE_TIME*1000) {
|
||||||
|
this.debugTileLayer.removeLayer(this.debugTileToRectangle[id]);
|
||||||
|
delete this.debugTileClearTimes[id];
|
||||||
|
} else {
|
||||||
|
var fade = 1.0 - (diff / (this.FADE_TIME*1000));
|
||||||
|
|
||||||
|
this.debugTileToRectangle[id].setStyle ({ opacity: 0.4*fade, fillOpacity: 0.1*fade });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _this = this;
|
if (Object.keys(this.debugTileClearTimes).length > 0) {
|
||||||
setTimeout ( function() { _this.timer(); }, this.CLEAR_CHECK_TIME*1000 );
|
this.startTimer(this.CLEAR_CHECK_TIME*1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user