Skip to content

Commit

Permalink
Draw debug tiles for source with greatest max zoom and Add overscaled…
Browse files Browse the repository at this point in the history
…Z to debug tile text
  • Loading branch information
Asheem Mamoowala authored and ryanhamley committed Oct 28, 2019
1 parent a312d88 commit 1d7ed44
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/render/draw_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function drawDebug(painter: Painter, sourceCache: SourceCache, coords: Array<Ove
}
}

function drawDebugTile(painter, sourceCache, coord) {
function drawDebugTile(painter, sourceCache, coord: OverscaledTileID) {
const context = painter.context;
const gl = context.gl;

Expand All @@ -45,7 +45,11 @@ function drawDebugTile(painter, sourceCache, coord) {
const tileSizeKb = Math.floor(tileByteLength / 1024);
const tileSize = sourceCache.getTile(coord).tileSize;
const scaleRatio = 512 / Math.min(tileSize, 512);
const vertices = createTextVertices(`${coord.toString()} ${tileSizeKb}kb`, 50, 200 * scaleRatio, 5 * scaleRatio);
let tileIdText = coord.canonical.toString();
if (coord.overscaledZ !== coord.canonical.z) {
tileIdText += ` => ${coord.overscaledZ}`;
}
const vertices = createTextVertices(`${tileIdText} ${tileSizeKb}kb`, 50, 200 * scaleRatio, 5 * scaleRatio);
const debugTextArray = new PosArray();
const debugTextIndices = new LineIndexArray();
for (let v = 0; v < vertices.length; v += 2) {
Expand Down
20 changes: 17 additions & 3 deletions src/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import EXTENT from '../data/extent';
import pixelsToTileUnits from '../source/pixels_to_tile_units';
import SegmentVector from '../data/segment';
import {RasterBoundsArray, PosArray, TriangleIndexArray, LineStripIndexArray} from '../data/array_types';
import {values} from '../util/util';
import rasterBoundsAttributes from '../data/raster_bounds_attributes';
import posAttributes from '../data/pos_attributes';
import ProgramConfiguration from '../data/program_configuration';
Expand Down Expand Up @@ -431,9 +432,22 @@ class Painter {
}

if (this.options.showTileBoundaries) {
for (const id in sourceCaches) {
draw.debug(this, sourceCaches[id], coordsAscending[id]);
break;
//Use source with highest maxzoom
let selectedSource;
let sourceCache;
const layers = values(this.style._layers);
layers.forEach((layer) => {
if (layer.source && !layer.isHidden(this.transform.zoom)) {
if (layer.source !== (sourceCache && sourceCache.id)) {
sourceCache = this.style.sourceCaches[layer.source];
}
if (!selectedSource || (selectedSource.getSource().maxzoom < sourceCache.getSource().maxzoom)) {
selectedSource = sourceCache;
}
}
});
if (selectedSource) {
draw.debug(this, selectedSource, selectedSource.getVisibleCoordinates());
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/source/tile_id.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export class CanonicalTileID {
(coord.x * tilesAtZoom - this.x) * EXTENT,
(coord.y * tilesAtZoom - this.y) * EXTENT);
}

toString() {
return `${this.z}/${this.x}/${this.y}`;
}
}

export class UnwrappedTileID {
Expand Down
Binary file modified test/integration/render-tests/debug/tile-overscaled/expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/integration/render-tests/debug/tile/expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions test/integration/render-tests/debug/tile/style.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
],
"zoom": 14,
"sources": {
"satellite": {
"type": "raster",
"tiles": [
"local://tiles/{z}-{x}-{y}.satellite.png"
],
"maxzoom": 1,
"tileSize": 256
},
"mapbox": {
"type": "vector",
"maxzoom": 14,
Expand All @@ -30,6 +38,14 @@
"background-color": "white"
}
},
{
"id": "raster",
"type": "raster",
"source": "satellite",
"paint": {
"raster-fade-duration": 0
}
},
{
"id": "line",
"type": "symbol",
Expand Down

0 comments on commit 1d7ed44

Please sign in to comment.