Added copy coords function

This commit is contained in:
Alexis
2025-05-04 18:33:42 +02:00
parent f003df7d58
commit 4cf2f66d42
6 changed files with 93 additions and 16 deletions

View File

@@ -602,6 +602,19 @@ map.on('moveend', () => {
setupToURL()
})
/**
* Listener for querying a copy of the current coordinates
*/
window.addEventListener('on-copy-coords', () => {
const lon = convertScaleToX(Number(localStorage.getItem('lastHeldXPosition')))
const lat = convertScaleToY(Number(localStorage.getItem('lastHeldYPosition')))
const coordsText = JSON.stringify({ x: lon, y: lat })
navigator.clipboard.writeText(coordsText)
window.dispatchEvent(new CustomEvent('on-toast-push', { bubbles: true, detail: { preset: 'copied-coords' }}))
})
/**
* UTILITIES
*/
@@ -609,7 +622,7 @@ map.on('moveend', () => {
* Convert x coords to scale with ratio, zoom and offset
* @param {number} x
*/
function convertXToScale(x) {
function convertXToScale(x) {
return (x * xRatio * zoomRatio) + xOffset
}
/**