Merge pull request #12373 from mike-000/patch-1
Rework TileDebug to allow TMS coordinates and to fix reprojection
This commit is contained in:
14
examples/canvas-tiles-tms.html
Normal file
14
examples/canvas-tiles-tms.html
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
layout: example.html
|
||||
title: Custom Canvas Tiles
|
||||
shortdesc: Renders tiles with TMS coordinates for debugging.
|
||||
docs: >
|
||||
The black grid tiles are generated on the client with an HTML5 canvas.
|
||||
The displayed TMS tile coordinates are produced using a custom template
|
||||
for TMS, the vector tile source's 512 pixel tile grid and the
|
||||
<code>zDirection</code> setting for vector tiles.
|
||||
Notice how the country polygons can be split between tiles and vector
|
||||
labels may appear in each tile.
|
||||
tags: "layers, vector tiles, tms, canvas"
|
||||
---
|
||||
<div id="map" class="map"></div>
|
||||
61
examples/canvas-tiles-tms.js
Normal file
61
examples/canvas-tiles-tms.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import MVT from '../src/ol/format/MVT.js';
|
||||
import Map from '../src/ol/Map.js';
|
||||
import TileDebug from '../src/ol/source/TileDebug.js';
|
||||
import TileLayer from '../src/ol/layer/Tile.js';
|
||||
import VectorTileLayer from '../src/ol/layer/VectorTile.js';
|
||||
import VectorTileSource from '../src/ol/source/VectorTile.js';
|
||||
import View from '../src/ol/View.js';
|
||||
import {Fill, Stroke, Style, Text} from '../src/ol/style.js';
|
||||
|
||||
const style = new Style({
|
||||
fill: new Fill({
|
||||
color: 'rgba(255, 255, 255, 0.6)',
|
||||
}),
|
||||
stroke: new Stroke({
|
||||
color: '#319FD3',
|
||||
width: 1,
|
||||
}),
|
||||
text: new Text({
|
||||
font: '12px Calibri,sans-serif',
|
||||
fill: new Fill({
|
||||
color: '#000',
|
||||
}),
|
||||
stroke: new Stroke({
|
||||
color: '#fff',
|
||||
width: 3,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
const vtLayer = new VectorTileLayer({
|
||||
declutter: true,
|
||||
source: new VectorTileSource({
|
||||
maxZoom: 15,
|
||||
format: new MVT(),
|
||||
url:
|
||||
'https://ahocevar.com/geoserver/gwc/service/tms/1.0.0/' +
|
||||
'ne:ne_10m_admin_0_countries@EPSG%3A900913@pbf/{z}/{x}/{-y}.pbf',
|
||||
}),
|
||||
style: function (feature) {
|
||||
style.getText().setText(feature.get('name'));
|
||||
return style;
|
||||
},
|
||||
});
|
||||
|
||||
const debugLayer = new TileLayer({
|
||||
source: new TileDebug({
|
||||
template: 'z:{z} x:{x} y:{-y}',
|
||||
projection: vtLayer.getSource().getProjection(),
|
||||
tileGrid: vtLayer.getSource().getTileGrid(),
|
||||
zDirection: 1,
|
||||
}),
|
||||
});
|
||||
|
||||
const map = new Map({
|
||||
layers: [vtLayer, debugLayer],
|
||||
target: 'map',
|
||||
view: new View({
|
||||
center: [0, 6000000],
|
||||
zoom: 4,
|
||||
}),
|
||||
});
|
||||
@@ -10,18 +10,24 @@ tags: "reprojection, projection, proj4js, epsg.io, graticule"
|
||||
---
|
||||
<div id="map" class="map"></div>
|
||||
<form class="form-inline">
|
||||
<label for="epsg-query">Search projection:</label>
|
||||
<label for="epsg-query">Search projection: </label>
|
||||
<input type="text" id="epsg-query" placeholder="4326, 27700, 3031, US National Atlas, Swiss, France, ..." class="form-control" size="50" />
|
||||
<button id="epsg-search" class="btn">Search</button>
|
||||
<span id="epsg-result"></span>
|
||||
<div>
|
||||
<label for="render-edges">
|
||||
Render reprojection edges
|
||||
<input type="checkbox" id="render-edges">
|
||||
</label>
|
||||
<label for="show-graticule">
|
||||
Show graticule
|
||||
<input type="checkbox" id="show-graticule" />
|
||||
</label>
|
||||
</div>
|
||||
</form>
|
||||
<form class="form-inline">
|
||||
<label for="render-edges">
|
||||
Render reprojection edges:
|
||||
<input type="checkbox" id="render-edges" />
|
||||
</label>
|
||||
|
||||
<label for="show-tiles">
|
||||
Show tile coordinates:
|
||||
<input type="checkbox" id="show-tiles" />
|
||||
</label>
|
||||
|
||||
<label for="show-graticule">
|
||||
Show graticule:
|
||||
<input type="checkbox" id="show-graticule" />
|
||||
</label>
|
||||
</form>
|
||||
|
||||
@@ -2,7 +2,7 @@ import Graticule from '../src/ol/layer/Graticule.js';
|
||||
import Map from '../src/ol/Map.js';
|
||||
import OSM from '../src/ol/source/OSM.js';
|
||||
import Stroke from '../src/ol/style/Stroke.js';
|
||||
import TileImage from '../src/ol/source/TileImage.js';
|
||||
import TileDebug from '../src/ol/source/TileDebug.js';
|
||||
import TileLayer from '../src/ol/layer/Tile.js';
|
||||
import View from '../src/ol/View.js';
|
||||
import proj4 from 'proj4';
|
||||
@@ -10,6 +10,16 @@ import {applyTransform} from '../src/ol/extent.js';
|
||||
import {get as getProjection, getTransform} from '../src/ol/proj.js';
|
||||
import {register} from '../src/ol/proj/proj4.js';
|
||||
|
||||
const osmSource = new OSM();
|
||||
|
||||
const debugLayer = new TileLayer({
|
||||
source: new TileDebug({
|
||||
tileGrid: osmSource.getTileGrid(),
|
||||
projection: osmSource.getProjection(),
|
||||
}),
|
||||
visible: false,
|
||||
});
|
||||
|
||||
const graticule = new Graticule({
|
||||
// the style to use for the lines, optional.
|
||||
strokeStyle: new Stroke({
|
||||
@@ -25,8 +35,9 @@ const graticule = new Graticule({
|
||||
const map = new Map({
|
||||
layers: [
|
||||
new TileLayer({
|
||||
source: new OSM(),
|
||||
source: osmSource,
|
||||
}),
|
||||
debugLayer,
|
||||
graticule,
|
||||
],
|
||||
target: 'map',
|
||||
@@ -41,6 +52,7 @@ const queryInput = document.getElementById('epsg-query');
|
||||
const searchButton = document.getElementById('epsg-search');
|
||||
const resultSpan = document.getElementById('epsg-result');
|
||||
const renderEdgesCheckbox = document.getElementById('render-edges');
|
||||
const showTilesCheckbox = document.getElementById('show-tiles');
|
||||
const showGraticuleCheckbox = document.getElementById('show-graticule');
|
||||
|
||||
function setProjection(code, name, proj4def, bbox) {
|
||||
@@ -125,22 +137,14 @@ searchButton.onclick = function (event) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle checkbox change event.
|
||||
* Handle checkbox change events.
|
||||
*/
|
||||
renderEdgesCheckbox.onchange = function () {
|
||||
map.getLayers().forEach(function (layer) {
|
||||
if (layer instanceof TileLayer) {
|
||||
const source = layer.getSource();
|
||||
if (source instanceof TileImage) {
|
||||
source.setRenderReprojectionEdges(renderEdgesCheckbox.checked);
|
||||
}
|
||||
}
|
||||
});
|
||||
osmSource.setRenderReprojectionEdges(renderEdgesCheckbox.checked);
|
||||
};
|
||||
showTilesCheckbox.onchange = function () {
|
||||
debugLayer.setVisible(showTilesCheckbox.checked);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle checkbox change event.
|
||||
*/
|
||||
showGraticuleCheckbox.onchange = function () {
|
||||
graticule.setVisible(showGraticuleCheckbox.checked);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user