From a860eaec35bf1e7bc1e0765c6293b8fda00c8dc7 Mon Sep 17 00:00:00 2001 From: Mark Jessop Date: Mon, 7 Oct 2019 16:50:24 +1030 Subject: [PATCH] Copy predicted landing lat/lng to clipboard on marker click. --- static/js/balloon.js | 9 ++++++++- static/js/predictions.js | 9 ++++++++- static/js/utils.js | 11 +++++++++++ templates/index.html | 1 - 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/static/js/balloon.js b/static/js/balloon.js index 6a8f30d..a6298be 100644 --- a/static/js/balloon.js +++ b/static/js/balloon.js @@ -61,9 +61,16 @@ function add_new_balloon(data){ // Landing position marker // Only add if there is data to show if (data.pred_landing.length == 3){ + var _landing_text = callsign + " Landing " + data.pred_landing[0].toFixed(5) + ", " + data.pred_landing[1].toFixed(5); balloon_positions[callsign].pred_marker = L.marker(data.pred_landing,{title:callsign + " Landing", icon: balloonLandingIcons[balloon_positions[callsign].colour]}) - .bindTooltip(callsign + " Landing",{permanent:false,direction:'right'}) + .bindTooltip(_landing_text,{permanent:false,direction:'right'}) .addTo(map); + // Add listener to copy prediction coords to clipboard. + // This is also duplicated in prediction.js, until I rearrange things... + balloon_positions[callsign].pred_marker.on('click', function(e) { + var _landing_pos_text = e.latlng.lat.toFixed(5) + ", " + e.latlng.lng.toFixed(5); + textToClipboard(_landing_pos_text); + }); } else{ balloon_positions[callsign].pred_marker = null; } diff --git a/static/js/predictions.js b/static/js/predictions.js index 337df00..cb2d556 100644 --- a/static/js/predictions.js +++ b/static/js/predictions.js @@ -18,14 +18,21 @@ function handlePrediction(data){ } // Add the landing marker if it doesnt exist. + var _landing_text = _callsign + " Landing " + data.pred_landing[0].toFixed(5) + ", " + data.pred_landing[1].toFixed(5); if (balloon_positions[_callsign].pred_marker == null){ balloon_positions[_callsign].pred_marker = L.marker(data.pred_landing,{title:_callsign + " Landing", icon: balloonLandingIcons[balloon_positions[_callsign].colour]}) - .bindTooltip(_callsign + " Landing",{permanent:false,direction:'right'}); + .bindTooltip(_landing_text ,{permanent:false,direction:'right'}); if (balloon_positions[_callsign].visible == true){ balloon_positions[_callsign].pred_marker.addTo(map); + // Add listener to copy prediction coords to clipboard. + balloon_positions[_callsign].pred_marker.on('click', function(e) { + var _landing_pos_text = e.latlng.lat.toFixed(5) + ", " + e.latlng.lng.toFixed(5); + textToClipboard(_landing_pos_text); + }); } }else{ balloon_positions[_callsign].pred_marker.setLatLng(data.pred_landing); + balloon_positions[_callsign].pred_marker.setTooltipContent(_landing_text); } if(data.burst.length == 3){ // There is burst data! diff --git a/static/js/utils.js b/static/js/utils.js index 0621010..4f24938 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -136,4 +136,15 @@ function calculate_lookangles(a, b) { 'range': distance, 'bearing': str_bearing }; +} + +function textToClipboard(text) { + // Copy a string to the user's clipboard. + // From here: https://stackoverflow.com/questions/33855641/copy-output-of-a-javascript-variable-to-the-clipboard + var dummy = document.createElement("textarea"); + document.body.appendChild(dummy); + dummy.value = text; + dummy.select(); + document.execCommand("copy"); + document.body.removeChild(dummy); } \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index f692d69..e92c882 100644 --- a/templates/index.html +++ b/templates/index.html @@ -27,7 +27,6 @@ -