From b395bad2ff538d1555d8baa3347ff68369ba4d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6kay=20=C5=9Eat=C4=B1r?= Date: Wed, 14 Aug 2024 12:54:56 +0300 Subject: [PATCH] Debugging - TileInvalidtions: Use the same section instead of rapidly deleting / adding new ones. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gökay Şatır Change-Id: I8ea85ff191b7dcb1681925c97f582987d1893fdf --- .../sections/InvalidationRectangleSection.ts | 80 +++++++++++++------ 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/browser/src/canvas/sections/InvalidationRectangleSection.ts b/browser/src/canvas/sections/InvalidationRectangleSection.ts index 39b9f6ca4fd74..ee59faaf17061 100644 --- a/browser/src/canvas/sections/InvalidationRectangleSection.ts +++ b/browser/src/canvas/sections/InvalidationRectangleSection.ts @@ -11,26 +11,34 @@ */ const sectionName = 'TileInvalidationRectangle'; -let counter = 0; // Unique counter. -let sectionCount = 0; class InvalidationRectangleSection extends CanvasSectionObject { name: string = sectionName; - documentObject: boolean = true; + + /* + We don't want visibility issues. + Since there will be more than one rectangles in this section, position property (thus document section) is not useful anymore. + */ + windowSection: boolean = true; showSection: boolean = true; zIndex: number = L.CSections.DefaultForDocumentObjects.zIndex; drawingOrder: number = L.CSections.DefaultForDocumentObjects.drawingOrder; processingOrder: number = L.CSections.DefaultForDocumentObjects.processingOrder; + interactable: boolean = false; constructor() { super(); + this.sectionProperties.rectangleList = []; + } + + addRectangle(x: number, y: number, width: number, height: number) { + const rectangleList: Array = this.sectionProperties + .rectangleList as Array; - this.name += ' ' + counter; - counter += 1; - sectionCount++; + if (rectangleList.length === 5) rectangleList.pop(); - this.sectionProperties.deletionTimeout = null; + rectangleList.unshift([x, y, width, height]); } onDraw( @@ -38,23 +46,50 @@ class InvalidationRectangleSection extends CanvasSectionObject { elapsedTime?: number, subsetBounds?: Bounds, ): void { - if ( - !this.sectionProperties.deletionTimeout && - (sectionCount > 1 || !app.map._docLayer._debug.tileInvalidationsOn) - ) - this.deleteThisSection(); - - this.context.globalAlpha = 0.5; + const rectangleList: Array = this.sectionProperties + .rectangleList as Array; this.context.strokeStyle = 'red'; - this.context.strokeRect(0, 0, this.size[0], this.size[1]); + + const anchor: number[] = this.containerObject.getDocumentAnchor(); + const xDiff = anchor[0] - this.documentTopLeft[0]; + const yDiff = anchor[1] - this.documentTopLeft[1]; + + for (let i = 0; i < rectangleList.length; i++) { + this.context.globalAlpha = 1 - 0.15 * i; + this.context.strokeRect( + xDiff + rectangleList[i][0], + yDiff + rectangleList[i][1], + rectangleList[i][2], + rectangleList[i][3], + ); + } this.context.globalAlpha = 1; } - deleteThisSection() { - sectionCount--; - this.sectionProperties.deletionTimeout = setTimeout(() => { + checkDeletion() { + if (this.sectionProperties.rectangleList.length > 0) { + this.sectionProperties.rectangleList.pop(); + setTimeout(() => { + this.checkDeletion(); + }, 1000); + } else { app.sectionContainer.removeSection(this.name); - }, 1000); + } + } + + private static getSection(): InvalidationRectangleSection { + let section: InvalidationRectangleSection; + if (app.sectionContainer.doesSectionExist(sectionName)) + section = app.sectionContainer.getSectionWithName(sectionName); + else { + section = new InvalidationRectangleSection(); + app.sectionContainer.addSection(section); + setTimeout(() => { + section.checkDeletion(); + }, 2000); // Start the cycle. + } + + return section; } public static setRectangle( @@ -63,10 +98,7 @@ class InvalidationRectangleSection extends CanvasSectionObject { width: number, height: number, ) { - const section = new InvalidationRectangleSection(); - app.sectionContainer.addSection(section); - section.size[0] = width; - section.size[1] = height; - section.setPosition(x, y); + const section = this.getSection(); + section.addRectangle(x, y, width, height); } }