diff --git a/css/main.css b/css/main.css index a4b069b..8117efe 100644 --- a/css/main.css +++ b/css/main.css @@ -409,7 +409,7 @@ button > * { right: 8px; } .ol-popup-closer:after { - content: "✖"; + content: "×"; } #switcher { diff --git a/js/src/mapapi/api_openlayers.js b/js/src/mapapi/api_openlayers.js index 2325e26..9ae353d 100644 --- a/js/src/mapapi/api_openlayers.js +++ b/js/src/mapapi/api_openlayers.js @@ -253,12 +253,9 @@ export default class OpenLayersApi { popupContent.id = 'popup-content'; popupContainer.appendChild(popupContent); const popupCloser = document.createElement('a'); - popupCloser.id = 'popup-closer'; popupCloser.className = 'ol-popup-closer'; - popupCloser.href = '#'; popupContainer.appendChild(popupCloser); - this.popup = new ol.Overlay({ element: popupContainer, autoPan: true, @@ -347,6 +344,9 @@ export default class OpenLayersApi { switcherContent.id = 'switcher-content'; switcherContent.className = 'ol-layerswitcher'; switcher.appendChild(switcherContent); + const switcherCloser = document.createElement('a'); + switcherCloser.className = 'ol-popup-closer'; + switcher.appendChild(switcherCloser); this.map.getLayers().forEach(/** @param {Layer} _layer */(_layer) => { const layerLabel = document.createElement('label'); @@ -387,6 +387,7 @@ export default class OpenLayersApi { } }; + switcherCloser.addEventListener('click', switcherHandle, false); switcherButton.addEventListener('click', switcherHandle, false); switcherButton.addEventListener('touchstart', switcherHandle, false); diff --git a/js/src/position.js b/js/src/position.js index 951a3f6..a52b725 100644 --- a/js/src/position.js +++ b/js/src/position.js @@ -83,4 +83,12 @@ export default class uPosition { hasImage() { return (this.image != null && this.image.length > 0); } + + get calculatedSpeed() { + return this.seconds ? this.meters / this.seconds : 0; + } + + get totalSpeed() { + return this.totalSeconds ? this.totalMeters / this.totalSeconds : 0; + } } diff --git a/js/src/positionset.js b/js/src/positionset.js index 736bad7..2de4b38 100644 --- a/js/src/positionset.js +++ b/js/src/positionset.js @@ -82,19 +82,33 @@ export default class uPositionSet extends uListItem { /** * Fetch latest position of each user. - * @return {Promise} + * @return {Promise} + */ + fetchLatest() { + this.clear(); + return uPositionSet.fetch({ last: true }).then((_positions) => { + this.fromJson(_positions); + }); + } + + /** + * Fetch latest position of each user. + * @return {Promise} */ static fetchLatest() { - return this.fetch({ last: true }).then((_positions) => { - if (_positions.length) { - const set = new uPositionSet(); - set.fromJson(_positions); + const set = new uPositionSet(); + return set.fetchLatest().then(() => { + if (set.length) { return set; } return null; }); } + /** + * @param params + * @return {Promise} + */ static fetch(params) { return uAjax.get('utils/getpositions.php', params); } diff --git a/js/src/user.js b/js/src/user.js index d4cef04..4459837 100644 --- a/js/src/user.js +++ b/js/src/user.js @@ -43,7 +43,7 @@ export default class uUser extends uListItem { } /** - * @return {Promise} + * @return {Promise} */ fetchLastPosition() { return uTrack.fetchLatest(this); @@ -51,7 +51,7 @@ export default class uUser extends uListItem { /** * @throws - * @return {Promise} + * @return {Promise} */ static fetchList() { return uAjax.get('utils/getusers.php').then((_users) => { diff --git a/js/src/utils.js b/js/src/utils.js index e79c8ef..f362b9b 100644 --- a/js/src/utils.js +++ b/js/src/utils.js @@ -294,24 +294,13 @@ export default class uUtils { static openUrl(url) { window.location.assign(url); } + + /** + * @param {Error} e + * @param {string} message + */ + static error(e, message) { + console.error(`${e.name}: ${e.message} (${e.stack})`); + alert(message); + } } - -// seconds to (d) H:M:S -Number.prototype.toHMS = function () { - let s = this; - const d = Math.floor(s / 86400); - const h = Math.floor((s % 86400) / 3600); - const m = Math.floor(((s % 86400) % 3600) / 60); - s = ((s % 86400) % 3600) % 60; - return ((d > 0) ? (d + ' d ') : '') + (('00' + h).slice(-2)) + ':' + (('00' + m).slice(-2)) + ':' + (('00' + s).slice(-2)) + ''; -}; - -// meters to km -Number.prototype.toKm = function () { - return Math.round(this / 10) / 100; -}; - -// m/s to km/h -Number.prototype.toKmH = function () { - return Math.round(this * 3600 / 10) / 100; -}; diff --git a/js/test/track.test.js b/js/test/track.test.js index 8d2aea8..a0183e8 100644 --- a/js/test/track.test.js +++ b/js/test/track.test.js @@ -70,22 +70,22 @@ describe('Track tests', () => { seconds = 0; jsonPosition = { - 'id': posId, - 'latitude': latitude, - 'longitude': longitude, - 'altitude': altitude, - 'speed': speed, - 'bearing': bearing, - 'timestamp': timestamp, - 'accuracy': accuracy, - 'provider': provider, - 'comment': comment, - 'image': image, - 'username': username, - 'trackid': trackid, - 'trackname': trackname, - 'meters': meters, - 'seconds': seconds + id: posId, + latitude: latitude, + longitude: longitude, + altitude: altitude, + speed: speed, + bearing: bearing, + timestamp: timestamp, + accuracy: accuracy, + provider: provider, + comment: comment, + image: image, + username: username, + trackid: trackid, + trackname: trackname, + meters: meters, + seconds: seconds }; }); diff --git a/scripts/import_cli.php b/scripts/import_cli.php index 30ff49d..215a790 100644 --- a/scripts/import_cli.php +++ b/scripts/import_cli.php @@ -158,7 +158,7 @@ foreach ($gpxFiles as $i => $gpxFile) { $provider = "gps"; if (!empty($point->extensions)) { // parse ulogger extensions - $ext = $point->extensions->children('ulogger', TRUE); + $ext = $point->extensions->children('ulogger', true); if (count($ext->speed)) { $speed = (double) $ext->speed; } if (count($ext->bearing)) { $bearing = (double) $ext->bearing; } if (count($ext->accuracy)) { $accuracy = (int) $ext->accuracy; }