- "My Location" button with text label (was just an icon) - Two share buttons after results: - "Copy Link" — fixed coordinates, exact result - "Copy Link (use viewer's GPS)" — source=gps, dynamic per viewer - CopyLink JS hook copies full URL to clipboard with "Copied!" feedback
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
export const CopyLink = {
|
|
mounted() {
|
|
this.el.addEventListener("click", () => {
|
|
const url = window.location.origin + this.el.dataset.url
|
|
navigator.clipboard.writeText(url).then(() => {
|
|
const orig = this.el.innerHTML
|
|
this.el.innerHTML = '<span class="text-success">Copied!</span>'
|
|
setTimeout(() => { this.el.innerHTML = orig }, 1500)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
export const LocateMe = {
|
|
mounted() {
|
|
this.el.addEventListener("click", () => this.locate())
|
|
|
|
// Also respond to server-pushed request (for source=gps URLs)
|
|
this.handleEvent("request_gps", () => this.locate())
|
|
},
|
|
|
|
locate() {
|
|
if (!navigator.geolocation) {
|
|
alert("Geolocation is not supported by this browser")
|
|
return
|
|
}
|
|
|
|
this.el.classList.add("loading", "loading-spinner")
|
|
|
|
navigator.geolocation.getCurrentPosition(
|
|
(pos) => {
|
|
this.el.classList.remove("loading", "loading-spinner")
|
|
this.pushEvent("gps_location", {
|
|
lat: pos.coords.latitude,
|
|
lon: pos.coords.longitude
|
|
})
|
|
},
|
|
(err) => {
|
|
this.el.classList.remove("loading", "loading-spinner")
|
|
alert("Could not get location: " + err.message)
|
|
},
|
|
{ enableHighAccuracy: true, timeout: 10000 }
|
|
)
|
|
}
|
|
}
|