node: don't show "Start follow position" button at all if browser does not support navigator.geolocation

This commit is contained in:
Oliver Gerlich 2018-07-19 22:53:30 +02:00
parent 3a18da51c8
commit d7e98625e2
1 changed files with 27 additions and 27 deletions

View File

@ -91,26 +91,26 @@ export class NodeView extends View {
this.btnGPS = domlib.newAt(this.el, 'span'); this.btnGPS = domlib.newAt(this.el, 'span');
this.btnGPS.classList.add('btn'); if (navigator.geolocation) {
this.btnGPS.innerHTML = 'Start follow position'; this.btnGPS.classList.add('btn');
this.btnGPS.addEventListener('click', () => { this.btnGPS.innerHTML = 'Start follow position';
if (this.editLocationGPS != null) { this.btnGPS.addEventListener('click', () => {
if (this.gpsPosition) { if (this.editLocationGPS != null) {
this.updatePosition(this.gpsPosition.latitude, this.gpsPosition.longitude); if (this.gpsPosition) {
this.updatePosition(this.gpsPosition.latitude, this.gpsPosition.longitude);
}
else {
this.gpsStatusText.innerHTML = "";
}
this.btnGPS.innerHTML = 'Start follow position';
navigator.geolocation.clearWatch(this.editLocationGPS);
this.editLocationGPS = null;
return;
} }
else {
this.gpsStatusText.innerHTML = "";
}
this.btnGPS.innerHTML = 'Start follow position';
navigator.geolocation.clearWatch(this.editLocationGPS);
this.editLocationGPS = null;
return;
}
this.gpsPosition = null; this.gpsPosition = null;
this.btnGPS.innerHTML = 'Stop following'; this.btnGPS.innerHTML = 'Stop following';
this.gpsStatusText.innerHTML = "waiting for location..."; this.gpsStatusText.innerHTML = "waiting for location...";
if (navigator.geolocation) {
this.editLocationGPS = navigator.geolocation.watchPosition((position) => { this.editLocationGPS = navigator.geolocation.watchPosition((position) => {
this.gpsStatusText.innerHTML = "GPS location at " + this.gpsStatusText.innerHTML = "GPS location at " +
new Date(position.timestamp).toLocaleTimeString() + ": " + new Date(position.timestamp).toLocaleTimeString() + ": " +
@ -131,15 +131,15 @@ export class NodeView extends View {
console.error('a navigator geolocation error: ', error); console.error('a navigator geolocation error: ', error);
} }
}, },
{ {
'enableHighAccuracy': true, 'enableHighAccuracy': true,
'maximumAge': 30000, 'maximumAge': 30000,
'timeout': 27000 'timeout': 27000
}); });
} else { });
notify.send('error', 'Browser did not support Location'); } else {
} this.btnGPS.innerHTML = '(Browser does not support geo-location)';
}); }
this.gpsStatusText = domlib.newAt(this.el, 'span'); this.gpsStatusText = domlib.newAt(this.el, 'span');
this.gpsStatusText.classList.add('withTextMargins'); this.gpsStatusText.classList.add('withTextMargins');
} }