-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from TDT4290-group-4/10-show-coordinates-on-sc…
…reen 10 show coordinates on screen
- Loading branch information
Showing
6 changed files
with
136 additions
and
2 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,27 @@ | ||
| #canvasContainer { | ||
| display: flex; | ||
| flex-direction: column; | ||
| position: absolute; | ||
| right: 10px; | ||
| bottom: 10px; | ||
| } | ||
|
|
||
| #posCanvas { | ||
| position: relative; | ||
| width: 300px; | ||
| height: 50px; | ||
| background-color: #19282c; | ||
| z-index: 10; | ||
| border-radius: 5px; | ||
| } | ||
|
|
||
| #elevationCanvas { | ||
| position: relative; | ||
| width: 300px; | ||
| height: 50px; | ||
| background-color: #19282c; | ||
| z-index: 10; | ||
| margin-bottom: 10px; | ||
| border-radius: 5px; | ||
| } | ||
|
|
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,80 @@ | ||
| import { ecef } from "../config.js"; | ||
| import { wgs84 } from "../config.js"; | ||
|
|
||
| const posCanvas = document.getElementById('posCanvas') // lat/lon | ||
| const elevationCanvas = document.getElementById('elevationCanvas') | ||
|
|
||
| export let posCtx | ||
| export let elevationCtx | ||
|
|
||
| /** | ||
| * Initializes the canvases and their contexts. | ||
| */ | ||
| export function initCoordinateCanvases() { | ||
| posCtx = resizeCanvas(posCanvas) | ||
| elevationCtx = resizeCanvas(elevationCanvas) | ||
| } | ||
|
|
||
| /** | ||
| * Resizes the canvas and its context to account for device pixel ratio. | ||
| * @param {*} canvas - The canvas element to resize. | ||
| * @returns {*} - The resized canvas context. | ||
| */ | ||
| function resizeCanvas(canvas) { | ||
| const dpr = window.devicePixelRatio || 1 | ||
| const ctx = canvas.getContext('2d') | ||
|
|
||
| canvas.width = canvas.clientWidth * dpr | ||
| canvas.height = canvas.clientHeight * dpr | ||
|
|
||
| // Scale context so drawing uses CSS pixels | ||
| ctx.setTransform(dpr, 0, 0, dpr, 0, 0) | ||
| return ctx | ||
| } | ||
|
|
||
| /** | ||
| * Draw the text on a given canvas. | ||
| */ | ||
| function drawText(ctx, text, canvas) { | ||
| const centerX = canvas.clientWidth / 2 | ||
| const centerY = canvas.clientHeight / 2 | ||
| ctx.clearRect(0, 0, canvas.width, canvas.height) | ||
| ctx.fillStyle = '#cccccc' | ||
| ctx.font = '20px Arial' | ||
| ctx.textAlign = 'center' | ||
| ctx.textBaseline = 'middle' | ||
| ctx.fillText(text, centerX, centerY) | ||
| } | ||
|
|
||
| /** | ||
| * Updates the lat/lon coordinates. | ||
| */ | ||
| export function updateCoordinateText() { | ||
| const cam = window.potreeViewer.scene.view.position | ||
| const [lon, lat] = proj4(ecef, wgs84, [cam.x, cam.y, cam.z]) | ||
| drawText( | ||
| posCtx, | ||
| `lat = ${lat.toFixed(5)}˚ lon = ${lon.toFixed(5)}˚`, | ||
| posCanvas | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Shows target elevations if camera is in orbit mode. | ||
| */ | ||
| export function updateTargetElevation() { | ||
| const pivot = window.potreeViewer.scene.view.getPivot() | ||
| const controls = window.potreeViewer.getControls() | ||
| const height = proj4(ecef, wgs84, [pivot.x, pivot.y, pivot.z])[2] | ||
|
|
||
| if (controls === window.potreeViewer.orbitControls) { | ||
| elevationCanvas.style.display = 'inline' | ||
| drawText( | ||
| elevationCtx, | ||
| `Target elevation = ${height.toFixed(4)}m`, | ||
| elevationCanvas | ||
| ) | ||
| } else { | ||
| elevationCanvas.style.display = 'none' | ||
| } | ||
| } |
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