From f7bd8102c53e1eca463da788d56c79fc93ca2224 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Tue, 29 Jun 2021 11:01:30 +0100 Subject: [PATCH] Add Show tile coordinates option --- examples/reprojection-by-code.html | 28 ++++++++++++++---------- examples/reprojection-by-code.js | 34 +++++++++++++++++------------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/examples/reprojection-by-code.html b/examples/reprojection-by-code.html index df386d4864..d09702f50f 100644 --- a/examples/reprojection-by-code.html +++ b/examples/reprojection-by-code.html @@ -10,18 +10,24 @@ tags: "reprojection, projection, proj4js, epsg.io, graticule" ---
+ diff --git a/examples/reprojection-by-code.js b/examples/reprojection-by-code.js index 2926a94486..2e169c1340 100644 --- a/examples/reprojection-by-code.js +++ b/examples/reprojection-by-code.js @@ -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); };