Add Show tile coordinates option
This commit is contained in:
@@ -10,18 +10,24 @@ tags: "reprojection, projection, proj4js, epsg.io, graticule"
|
|||||||
---
|
---
|
||||||
<div id="map" class="map"></div>
|
<div id="map" class="map"></div>
|
||||||
<form class="form-inline">
|
<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" />
|
<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>
|
<button id="epsg-search" class="btn">Search</button>
|
||||||
<span id="epsg-result"></span>
|
<span id="epsg-result"></span>
|
||||||
<div>
|
</form>
|
||||||
<label for="render-edges">
|
<form class="form-inline">
|
||||||
Render reprojection edges
|
<label for="render-edges">
|
||||||
<input type="checkbox" id="render-edges">
|
Render reprojection edges:
|
||||||
</label>
|
<input type="checkbox" id="render-edges" />
|
||||||
<label for="show-graticule">
|
</label>
|
||||||
Show graticule
|
|
||||||
<input type="checkbox" id="show-graticule" />
|
<label for="show-tiles">
|
||||||
</label>
|
Show tile coordinates:
|
||||||
</div>
|
<input type="checkbox" id="show-tiles" />
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="show-graticule">
|
||||||
|
Show graticule:
|
||||||
|
<input type="checkbox" id="show-graticule" />
|
||||||
|
</label>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import Graticule from '../src/ol/layer/Graticule.js';
|
|||||||
import Map from '../src/ol/Map.js';
|
import Map from '../src/ol/Map.js';
|
||||||
import OSM from '../src/ol/source/OSM.js';
|
import OSM from '../src/ol/source/OSM.js';
|
||||||
import Stroke from '../src/ol/style/Stroke.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 TileLayer from '../src/ol/layer/Tile.js';
|
||||||
import View from '../src/ol/View.js';
|
import View from '../src/ol/View.js';
|
||||||
import proj4 from 'proj4';
|
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 {get as getProjection, getTransform} from '../src/ol/proj.js';
|
||||||
import {register} from '../src/ol/proj/proj4.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({
|
const graticule = new Graticule({
|
||||||
// the style to use for the lines, optional.
|
// the style to use for the lines, optional.
|
||||||
strokeStyle: new Stroke({
|
strokeStyle: new Stroke({
|
||||||
@@ -25,8 +35,9 @@ const graticule = new Graticule({
|
|||||||
const map = new Map({
|
const map = new Map({
|
||||||
layers: [
|
layers: [
|
||||||
new TileLayer({
|
new TileLayer({
|
||||||
source: new OSM(),
|
source: osmSource,
|
||||||
}),
|
}),
|
||||||
|
debugLayer,
|
||||||
graticule,
|
graticule,
|
||||||
],
|
],
|
||||||
target: 'map',
|
target: 'map',
|
||||||
@@ -41,6 +52,7 @@ const queryInput = document.getElementById('epsg-query');
|
|||||||
const searchButton = document.getElementById('epsg-search');
|
const searchButton = document.getElementById('epsg-search');
|
||||||
const resultSpan = document.getElementById('epsg-result');
|
const resultSpan = document.getElementById('epsg-result');
|
||||||
const renderEdgesCheckbox = document.getElementById('render-edges');
|
const renderEdgesCheckbox = document.getElementById('render-edges');
|
||||||
|
const showTilesCheckbox = document.getElementById('show-tiles');
|
||||||
const showGraticuleCheckbox = document.getElementById('show-graticule');
|
const showGraticuleCheckbox = document.getElementById('show-graticule');
|
||||||
|
|
||||||
function setProjection(code, name, proj4def, bbox) {
|
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 () {
|
renderEdgesCheckbox.onchange = function () {
|
||||||
map.getLayers().forEach(function (layer) {
|
osmSource.setRenderReprojectionEdges(renderEdgesCheckbox.checked);
|
||||||
if (layer instanceof TileLayer) {
|
};
|
||||||
const source = layer.getSource();
|
showTilesCheckbox.onchange = function () {
|
||||||
if (source instanceof TileImage) {
|
debugLayer.setVisible(showTilesCheckbox.checked);
|
||||||
source.setRenderReprojectionEdges(renderEdgesCheckbox.checked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle checkbox change event.
|
|
||||||
*/
|
|
||||||
showGraticuleCheckbox.onchange = function () {
|
showGraticuleCheckbox.onchange = function () {
|
||||||
graticule.setVisible(showGraticuleCheckbox.checked);
|
graticule.setVisible(showGraticuleCheckbox.checked);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user