Make the tile debug source useful for understanding tiles
This commit is contained in:
@@ -4,10 +4,7 @@ title: Canvas Tiles
|
|||||||
shortdesc: Renders tiles with coordinates for debugging.
|
shortdesc: Renders tiles with coordinates for debugging.
|
||||||
docs: >
|
docs: >
|
||||||
The black grid tiles are generated on the client with an HTML5 canvas. The
|
The black grid tiles are generated on the client with an HTML5 canvas. The
|
||||||
displayed tile coordinates are OpenLayers tile coordinates. These increase
|
displayed tile coordinates are the XYZ tile coordinates.
|
||||||
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`.
|
|
||||||
tags: "layers, openstreetmap, canvas"
|
tags: "layers, openstreetmap, canvas"
|
||||||
---
|
---
|
||||||
<div id="map" class="map"></div>
|
<div id="map" class="map"></div>
|
||||||
|
|||||||
@@ -1,26 +1,21 @@
|
|||||||
import Map from '../src/ol/Map.js';
|
import Map from '../src/ol/Map.js';
|
||||||
import View from '../src/ol/View.js';
|
import View from '../src/ol/View.js';
|
||||||
import TileLayer from '../src/ol/layer/Tile.js';
|
import TileLayer from '../src/ol/layer/Tile.js';
|
||||||
import {fromLonLat} from '../src/ol/proj.js';
|
|
||||||
import {OSM, TileDebug} from '../src/ol/source.js';
|
import {OSM, TileDebug} from '../src/ol/source.js';
|
||||||
|
|
||||||
|
|
||||||
const osmSource = new OSM();
|
|
||||||
const map = new Map({
|
const map = new Map({
|
||||||
layers: [
|
layers: [
|
||||||
new TileLayer({
|
new TileLayer({
|
||||||
source: osmSource
|
source: new OSM()
|
||||||
}),
|
}),
|
||||||
new TileLayer({
|
new TileLayer({
|
||||||
source: new TileDebug({
|
source: new TileDebug()
|
||||||
projection: 'EPSG:3857',
|
|
||||||
tileGrid: osmSource.getTileGrid()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
target: 'map',
|
target: 'map',
|
||||||
view: new View({
|
view: new View({
|
||||||
center: fromLonLat([-0.1275, 51.507222]),
|
center: [0, 0],
|
||||||
zoom: 10
|
zoom: 1
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import Tile from '../Tile.js';
|
|||||||
import TileState from '../TileState.js';
|
import TileState from '../TileState.js';
|
||||||
import {createCanvasContext2D} from '../dom.js';
|
import {createCanvasContext2D} from '../dom.js';
|
||||||
import {toSize} from '../size.js';
|
import {toSize} from '../size.js';
|
||||||
import TileSource from './Tile.js';
|
import XYZ from './XYZ.js';
|
||||||
import {getKeyZXY} from '../tilecoord.js';
|
import {getKeyZXY} from '../tilecoord.js';
|
||||||
|
|
||||||
|
|
||||||
@@ -51,10 +51,10 @@ class LabeledTile extends Tile {
|
|||||||
const tileSize = this.tileSize_;
|
const tileSize = this.tileSize_;
|
||||||
const context = createCanvasContext2D(tileSize[0], tileSize[1]);
|
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.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5);
|
||||||
|
|
||||||
context.fillStyle = 'black';
|
context.fillStyle = 'grey';
|
||||||
context.textAlign = 'center';
|
context.textAlign = 'center';
|
||||||
context.textBaseline = 'middle';
|
context.textBaseline = 'middle';
|
||||||
context.font = '24px sans-serif';
|
context.font = '24px sans-serif';
|
||||||
@@ -74,7 +74,7 @@ class LabeledTile extends Tile {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Options
|
* @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 {import("../tilegrid/TileGrid.js").default} [tileGrid] Tile grid.
|
||||||
* @property {boolean} [wrapX=true] Whether to wrap the world horizontally.
|
* @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.
|
* Uses Canvas context2d, so requires Canvas support.
|
||||||
* @api
|
* @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({
|
super({
|
||||||
opaque: false,
|
opaque: false,
|
||||||
@@ -115,8 +119,12 @@ class TileDebug extends TileSource {
|
|||||||
const tileSize = toSize(this.tileGrid.getTileSize(z));
|
const tileSize = toSize(this.tileGrid.getTileSize(z));
|
||||||
const tileCoord = [z, x, y];
|
const tileCoord = [z, x, y];
|
||||||
const textTileCoord = this.getTileCoordForTileUrlFunction(tileCoord);
|
const textTileCoord = this.getTileCoordForTileUrlFunction(tileCoord);
|
||||||
const text = !textTileCoord ? '' :
|
let text;
|
||||||
this.getTileCoordForTileUrlFunction(textTileCoord).toString();
|
if (textTileCoord) {
|
||||||
|
text = 'z:' + textTileCoord[0] + ' x:' + textTileCoord[1] + ' y:' + (-textTileCoord[2] - 1);
|
||||||
|
} else {
|
||||||
|
text = 'none';
|
||||||
|
}
|
||||||
const tile = new LabeledTile(tileCoord, tileSize, text);
|
const tile = new LabeledTile(tileCoord, tileSize, text);
|
||||||
this.tileCache.set(tileCoordKey, tile);
|
this.tileCache.set(tileCoordKey, tile);
|
||||||
return tile;
|
return tile;
|
||||||
|
|||||||
Reference in New Issue
Block a user