-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(landing): adding debug information to map when ?debug=true (#809)
- Loading branch information
Showing
7 changed files
with
203 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { Basemaps } from './map'; | ||
import OSM from 'ol/source/OSM'; | ||
import TileLayer from 'ol/layer/Tile'; | ||
|
||
/** | ||
* VDom style document.createElement | ||
* @param name | ||
*/ | ||
function e(name: string): HTMLElement; | ||
function e(name: string, attrs: Record<string, unknown>, value?: string | HTMLElement | HTMLElement[]): HTMLElement; | ||
function e(name: string, attrs?: Record<string, unknown>, value?: string | HTMLElement | HTMLElement[]): HTMLElement { | ||
const el = document.createElement(name); | ||
if (value == null) { | ||
// noop | ||
} else if (Array.isArray(value)) { | ||
value.forEach((v) => el.appendChild(v)); | ||
} else if (typeof value == 'object') { | ||
el.appendChild(value); | ||
} else { | ||
el.innerHTML = value; | ||
} | ||
|
||
if (attrs) { | ||
Object.entries(attrs).forEach(([key, value]) => { | ||
(el as any)[key] = value; | ||
}); | ||
} | ||
return el; | ||
} | ||
|
||
function kv(key: string, value: string | HTMLElement): { value: HTMLElement; container: HTMLElement } { | ||
const valueEl: HTMLElement = typeof value == 'string' ? e('div', { className: 'debug__value' }, value) : value; | ||
const containerEl = e('div', { className: 'debug__info' }, [ | ||
e('label', { className: 'debug__label' }, key), | ||
valueEl, | ||
]); | ||
return { value: valueEl, container: containerEl }; | ||
} | ||
|
||
export function addDebugLayer(bm: Basemaps): void { | ||
// Hide header/footer | ||
Array.from(document.querySelectorAll('header')).forEach((f) => (f.style.display = 'none')); | ||
Array.from(document.querySelectorAll('footer')).forEach((f) => (f.style.display = 'none')); | ||
bm.el.style.height = '100vh'; | ||
bm.map.updateSize(); | ||
|
||
const debugEl = e('div', { id: 'debug', className: 'debug' }); | ||
const imageEl = kv('ImageId', bm.config.imageId); | ||
debugEl.appendChild(imageEl.container); | ||
|
||
const projectionEl = kv('Projection', bm.config.projection.toEpsgString()); | ||
debugEl.appendChild(projectionEl.container); | ||
|
||
const zoomEl = kv('Zoom', ''); | ||
debugEl.appendChild(zoomEl.container); | ||
|
||
// Change the background colors | ||
const purpleCheck = e('input', { type: 'checkbox' }) as HTMLInputElement; | ||
const colorButton = kv('Purple', purpleCheck); | ||
purpleCheck.onclick = (): void => { | ||
if (purpleCheck.checked) { | ||
document.body.style.backgroundColor = 'magenta'; | ||
} else { | ||
document.body.style.backgroundColor = ''; | ||
} | ||
}; | ||
debugEl.appendChild(colorButton.container); | ||
// Add a debug OSM layer | ||
const osmLayer = new TileLayer({ source: new OSM({}), className: 'osm' }); | ||
const osmRange = e('input', { | ||
type: 'range', | ||
min: 0, | ||
max: 1, | ||
value: 0, | ||
step: 0.05, | ||
className: 'osm__slider', | ||
}) as HTMLInputElement; | ||
const osmButton = kv('OSM', osmRange); | ||
osmRange.oninput = (): void => { | ||
const range = Number(osmRange.value); | ||
console.log('Range', { range }); | ||
if (range == 0) { | ||
bm.map.removeLayer(osmLayer); | ||
return; | ||
} | ||
const hasLayer = bm.map | ||
.getLayers() | ||
.getArray() | ||
.find((f) => f == osmLayer); | ||
if (hasLayer == null) bm.map.addLayer(osmLayer); | ||
osmLayer.setOpacity(range); | ||
}; | ||
debugEl.appendChild(osmButton.container); | ||
|
||
bm.map.addEventListener('postrender', () => { | ||
const view = bm.map.getView(); | ||
const zoom = Math.floor(view.getZoom() * 1e4) / 1e4; | ||
zoomEl.value.innerHTML = String(zoom); | ||
}); | ||
|
||
document.body.appendChild(debugEl); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import './global'; | ||
|
||
import { Basemaps } from './map'; | ||
import { addDebugLayer } from './debug'; | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const mapEl = document.getElementById('map'); | ||
if (mapEl == null) throw new Error('Cannot find #map element'); | ||
window.basemaps = new Basemaps(mapEl); | ||
const basemaps = new Basemaps(mapEl); | ||
window.basemaps = basemaps; | ||
|
||
if (basemaps.config.debug) addDebugLayer(basemaps); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
body { | ||
margin: 0; | ||
} | ||
|
||
html { | ||
overflow-y: auto !important; | ||
} | ||
|
||
#map { | ||
width: 100%; | ||
height: calc(100% - 58px); | ||
position: fixed; | ||
} | ||
|
||
.g-footer-wrapper { | ||
position: absolute; | ||
left: 0; | ||
bottom: 0; | ||
width: 100%; | ||
} | ||
|
||
#map .ol-control { | ||
background-color: inherit; | ||
} | ||
|
||
#map .ol-zoom button { | ||
background-color: white; | ||
color: #0f4c65; | ||
margin: 0; | ||
width: 28px; | ||
height: 32px; | ||
} | ||
|
||
#map .ol-zoom-in { | ||
border-radius: 4px 4px 0 0; | ||
} | ||
|
||
#map .ol-zoom-out { | ||
border-radius: 0 0 4px 4px; | ||
} | ||
|
||
.checker-board { | ||
background-image: linear-gradient(45deg, #00000010 25%, transparent 25%), | ||
linear-gradient(45deg, transparent 75%, #00000010 75%), | ||
linear-gradient(45deg, transparent 75%, #00000010 75%), | ||
linear-gradient(45deg, #00000010 25%, transparent 25%); | ||
background-size: 100px 100px; | ||
background-position: 0 0, 0 0, -50px -50px, 50px 50px; | ||
} | ||
|
||
|
||
.debug { | ||
font-size: 12px; | ||
position: absolute; | ||
top: 8px; | ||
right: 8px; | ||
width: 200px; | ||
background-color: rgba(255, 255, 255, 0.87); | ||
padding: 16px; | ||
} | ||
|
||
.debug__info { | ||
display: flex; | ||
justify-content: space-between; | ||
margin-bottom: 4px; | ||
} | ||
|
||
.debug__label { | ||
font-weight: 700; | ||
} | ||
|
||
|
||
.osm__slider { | ||
width: 75%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters