diff options
Diffstat (limited to 'src/helper.js')
-rw-r--r-- | src/helper.js | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/helper.js b/src/helper.js index 2242d91..3a4cca0 100644 --- a/src/helper.js +++ b/src/helper.js @@ -45,23 +45,30 @@ function formatInt(num) { return ("00" + num).slice(-2) } -export function calcCrow(lat1, lon1, lat2, lon2) - { - var R = 6371; // km - var dLat = toRad(lat2-lat1); - var dLon = toRad(lon2-lon1); - var lat1 = toRad(lat1); - var lat2 = toRad(lat2); +export function calcCrow(lat1, lon1, lat2, lon2) { + var R = 6371; // km + var dLat = toRad(lat2 - lat1); + var dLon = toRad(lon2 - lon1); + var lat1 = toRad(lat1); + var lat2 = toRad(lat2); - var a = Math.sin(dLat/2) * Math.sin(dLat/2) + - Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2); - var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); - var d = R * c; - return d; - } + var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2); + var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + var d = R * c; + return d; +} + +// Converts numeric degrees to radians +function toRad(Value) { + return Value * Math.PI / 180; +} - // Converts numeric degrees to radians - function toRad(Value) - { - return Value * Math.PI / 180; - }
\ No newline at end of file +export default function debounce(func, wait) { + let timeout + return function (...args) { + const context = this + clearTimeout(timeout) + timeout = setTimeout(() => func.apply(context, args), wait) + } +} |