diff options
Diffstat (limited to 'examples/location/mapviewer/MapViewer/helper.js')
-rw-r--r-- | examples/location/mapviewer/MapViewer/helper.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/location/mapviewer/MapViewer/helper.js b/examples/location/mapviewer/MapViewer/helper.js new file mode 100644 index 000000000..a42040518 --- /dev/null +++ b/examples/location/mapviewer/MapViewer/helper.js @@ -0,0 +1,44 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +.pragma library + +function roundNumber(number, digits) +{ + var multiple = Math.pow(10, digits); + return Math.round(number * multiple) / multiple; +} + +function formatTime(sec) +{ + var value = sec + var seconds = value % 60 + value /= 60 + value = (value > 1) ? Math.round(value) : 0 + var minutes = value % 60 + value /= 60 + value = (value > 1) ? Math.round(value) : 0 + var hours = value + if (hours > 0) value = hours + "h:"+ minutes + "m" + else value = minutes + "min" + return value +} + +function formatDistance(meters) +{ + var dist = Math.round(meters) + if (dist > 1000 ){ + if (dist > 100000){ + dist = Math.round(dist / 1000) + } + else{ + dist = Math.round(dist / 100) + dist = dist / 10 + } + dist = dist + " km" + } + else{ + dist = dist + " m" + } + return dist +} |