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"
This commit is contained in:
Oliver Gerlich 2018-07-15 23:23:56 +02:00 committed by Geno
parent ad7cc8d0aa
commit fb0f2f054d
1 changed files with 7 additions and 6 deletions

View File

@ -95,20 +95,21 @@ export class NodeView extends View {
this.btnGPS.innerHTML = 'Start follow position'; this.btnGPS.innerHTML = 'Start follow position';
this.btnGPS.addEventListener('click', () => { this.btnGPS.addEventListener('click', () => {
if (this.editLocationGPS != null) { if (this.editLocationGPS != null) {
if (this.btnGPS.innerHTML === 'Stop following') { if (this.gpsPosition) {
updatePosition(); this.updatePosition(this.gpsPosition.latitude, this.gpsPosition.longitude);
} }
this.btnGPS.innerHTML = 'Start follow position'; this.btnGPS.innerHTML = 'Start follow position';
navigator.geolocation.clearWatch(this.editLocationGPS); navigator.geolocation.clearWatch(this.editLocationGPS);
this.editLocationGPS = null; this.editLocationGPS = null;
return; return;
} }
this.gpsPosition = null;
this.btnGPS.innerHTML = 'Following position'; this.btnGPS.innerHTML = 'Following position';
if (navigator.geolocation) { if (navigator.geolocation) {
this.editLocationGPS = navigator.geolocation.watchPosition((position) => { this.editLocationGPS = navigator.geolocation.watchPosition((position) => {
this.btnGPS.innerHTML = 'Stop following'; this.btnGPS.innerHTML = 'Stop following';
this.this.storePosition = position.coords; this.gpsPosition = position.coords;
const latlng = [position.coords.latitude, position.coords.longitude]; const latlng = [position.coords.latitude, position.coords.longitude];
this.marker.setLatLng(latlng); this.marker.setLatLng(latlng);
@ -136,8 +137,8 @@ export class NodeView extends View {
updatePosition (lat, lng) { updatePosition (lat, lng) {
const node = store.getNode(this.currentNodeID) || store.createNode(this.currentNodeID), const node = store.getNode(this.currentNodeID) || store.createNode(this.currentNodeID),
localNodeCopy = Object.assign({}, node), localNodeCopy = Object.assign({}, node),
newLat = lat || this.storePosition.latitude || false, newLat = lat || this.gpsPosition.latitude || false,
newlng = lng || this.storePosition.longitude || false; newlng = lng || this.gpsPosition.longitude || false;
if (!newLat || !newlng) { if (!newLat || !newlng) {
return; return;