-
Notifications
You must be signed in to change notification settings - Fork 0
10 show coordinates on screen #23
Merged
+136
−2
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7372c13
feat(#10): :sparkles: coordinates possible to see on scene
kleinc c405e67
feat(#10): :sparkles: Made the text clearer, added a box for elevatio…
kleinc 3d6ec5e
docs(#10): :memo: Added function documentation
kleinc fd23c74
refactor(#10): Changed to new coordinate system, generalized code
kleinc cbe01f8
refactor(#10): moved init function to main
kleinc 0b5b038
refactor(#10): Added more decimals to lat/lon and elevation target
kleinc 9ed3eec
Merge branch 'dev' of git.ntnu.no:TDT4290-group-4/MolloyExplorer into…
kleinc 74016ea
refactor(#10): Fix merge conflict and apply new changes
kleinc b24f3aa
refactor(#10): Refactored code according to comments
kleinc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,23 @@ | ||
| #posCanvas { | ||
| position: absolute; | ||
| left: 10px; | ||
| bottom: 10px; | ||
| width: 300px; | ||
| height: 50px; | ||
| pointer-events: none; | ||
| background-color: #19282c; | ||
| z-index: 10; | ||
| border-radius: 5px; | ||
| } | ||
|
|
||
| #elevationCanvas { | ||
| position: absolute; | ||
| right: 100px; | ||
| top: 15px; | ||
| width: 300px; | ||
| height: 50px; | ||
| pointer-events: none; | ||
| background-color: #19282c; | ||
| z-index: 10; | ||
| border-radius: 5px; | ||
| } | ||
This file contains hidden or 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 @@ | ||
| const ecef = '+proj=geocent +datum=WGS84 +units=m +no_defs' // EPSG:4978 (geocentric coordinates) | ||
| const wgs84 = '+proj=longlat +datum=WGS84 +no_defs' // EPSG:4326 (geographic coordinates) | ||
adriahso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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 initCanvases() { | ||
adriahso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 position. | ||
| */ | ||
| export function updatePosition() { | ||
adriahso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.