From 0e91365859a4a76be8fce12dbed911cc94169c41 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 14 Nov 2018 15:40:37 +0100 Subject: [PATCH] Make the tile debug source useful for understanding tiles --- examples/canvas-tiles.html | 5 +---- examples/canvas-tiles.js | 13 ++++--------- src/ol/source/TileDebug.js | 26 +++++++++++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/canvas-tiles.html b/examples/canvas-tiles.html index dcf081a2f1..b1d3b1116f 100644 --- a/examples/canvas-tiles.html +++ b/examples/canvas-tiles.html @@ -4,10 +4,7 @@ title: Canvas Tiles shortdesc: Renders tiles with coordinates for debugging. docs: > The black grid tiles are generated on the client with an HTML5 canvas. The - displayed tile coordinates are OpenLayers tile coordinates. These increase - from bottom to top, but standard XYZ tiling scheme coordinates increase from - top to bottom. To calculate the `y` for a standard XYZ tile coordinate, use - `-y - 1`. + displayed tile coordinates are the XYZ tile coordinates. tags: "layers, openstreetmap, canvas" ---
diff --git a/examples/canvas-tiles.js b/examples/canvas-tiles.js index d4489120a2..b8fcb00220 100644 --- a/examples/canvas-tiles.js +++ b/examples/canvas-tiles.js @@ -1,26 +1,21 @@ import Map from '../src/ol/Map.js'; import View from '../src/ol/View.js'; import TileLayer from '../src/ol/layer/Tile.js'; -import {fromLonLat} from '../src/ol/proj.js'; import {OSM, TileDebug} from '../src/ol/source.js'; -const osmSource = new OSM(); const map = new Map({ layers: [ new TileLayer({ - source: osmSource + source: new OSM() }), new TileLayer({ - source: new TileDebug({ - projection: 'EPSG:3857', - tileGrid: osmSource.getTileGrid() - }) + source: new TileDebug() }) ], target: 'map', view: new View({ - center: fromLonLat([-0.1275, 51.507222]), - zoom: 10 + center: [0, 0], + zoom: 1 }) }); diff --git a/src/ol/source/TileDebug.js b/src/ol/source/TileDebug.js index 11b3bfc4aa..55c11c8914 100644 --- a/src/ol/source/TileDebug.js +++ b/src/ol/source/TileDebug.js @@ -6,7 +6,7 @@ import Tile from '../Tile.js'; import TileState from '../TileState.js'; import {createCanvasContext2D} from '../dom.js'; import {toSize} from '../size.js'; -import TileSource from './Tile.js'; +import XYZ from './XYZ.js'; import {getKeyZXY} from '../tilecoord.js'; @@ -51,10 +51,10 @@ class LabeledTile extends Tile { const tileSize = this.tileSize_; const context = createCanvasContext2D(tileSize[0], tileSize[1]); - context.strokeStyle = 'black'; + context.strokeStyle = 'grey'; context.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5); - context.fillStyle = 'black'; + context.fillStyle = 'grey'; context.textAlign = 'center'; context.textBaseline = 'middle'; context.font = '24px sans-serif'; @@ -74,7 +74,7 @@ class LabeledTile extends Tile { /** * @typedef {Object} Options - * @property {import("../proj.js").ProjectionLike} projection Projection. + * @property {import("../proj.js").ProjectionLike} [projection='EPSG:3857'] Optional projection. * @property {import("../tilegrid/TileGrid.js").default} [tileGrid] Tile grid. * @property {boolean} [wrapX=true] Whether to wrap the world horizontally. */ @@ -89,11 +89,15 @@ class LabeledTile extends Tile { * Uses Canvas context2d, so requires Canvas support. * @api */ -class TileDebug extends TileSource { +class TileDebug extends XYZ { /** - * @param {Options} options Debug tile options. + * @param {Options=} opt_options Debug tile options. */ - constructor(options) { + constructor(opt_options) { + /** + * @type {Options} + */ + const options = opt_options || {}; super({ opaque: false, @@ -115,8 +119,12 @@ class TileDebug extends TileSource { const tileSize = toSize(this.tileGrid.getTileSize(z)); const tileCoord = [z, x, y]; const textTileCoord = this.getTileCoordForTileUrlFunction(tileCoord); - const text = !textTileCoord ? '' : - this.getTileCoordForTileUrlFunction(textTileCoord).toString(); + let text; + if (textTileCoord) { + text = 'z:' + textTileCoord[0] + ' x:' + textTileCoord[1] + ' y:' + (-textTileCoord[2] - 1); + } else { + text = 'none'; + } const tile = new LabeledTile(tileCoord, tileSize, text); this.tileCache.set(tileCoordKey, tile); return tile;