From 7c60ebddf5c96c32ec430741919d174adfcc09ae Mon Sep 17 00:00:00 2001 From: Oliver Gerlich Date: Sun, 15 Jul 2018 23:23:56 +0200 Subject: [PATCH] node page: some fixes for GPS-following - rename storePosition to gpsPosition - don't check for btnGPS.innerHTML contents (this is fragile); check for this.gpsPosition instead - fix call to updatePosition() when clicking "Stop following" --- webroot/js/view/node.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/webroot/js/view/node.js b/webroot/js/view/node.js index b3c6181..e112bcc 100644 --- a/webroot/js/view/node.js +++ b/webroot/js/view/node.js @@ -95,20 +95,21 @@ export class NodeView extends View { this.btnGPS.innerHTML = 'Start follow position'; this.btnGPS.addEventListener('click', () => { if (this.editLocationGPS != null) { - if (this.btnGPS.innerHTML === 'Stop following') { - updatePosition(); + if (this.gpsPosition) { + this.updatePosition(this.gpsPosition.latitude, this.gpsPosition.longitude); } this.btnGPS.innerHTML = 'Start follow position'; navigator.geolocation.clearWatch(this.editLocationGPS); this.editLocationGPS = null; - return; } + + this.gpsPosition = null; this.btnGPS.innerHTML = 'Following position'; if (navigator.geolocation) { this.editLocationGPS = navigator.geolocation.watchPosition((position) => { this.btnGPS.innerHTML = 'Stop following'; - this.this.storePosition = position.coords; + this.gpsPosition = position.coords; const latlng = [position.coords.latitude, position.coords.longitude]; this.marker.setLatLng(latlng); @@ -136,8 +137,8 @@ export class NodeView extends View { updatePosition (lat, lng) { const node = store.getNode(this.currentNodeID) || store.createNode(this.currentNodeID), localNodeCopy = Object.assign({}, node), - newLat = lat || this.storePosition.latitude || false, - newlng = lng || this.storePosition.longitude || false; + newLat = lat || this.gpsPosition.latitude || false, + newlng = lng || this.gpsPosition.longitude || false; if (!newLat || !newlng) { return;