Skip to content

Commit

Permalink
query location in the beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Jan 31, 2019
1 parent cf47316 commit 68db9c8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
51 changes: 45 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"author": "Michael Straßburger <[email protected]>",
"license": "MIT",
"dependencies": {
"@derhuerst/location": "^1.0.0",
"@mapbox/vector-tile": "^1.3.1",
"bluebird": "^3.5.3",
"bresenham": "0.0.4",
Expand Down
18 changes: 18 additions & 0 deletions src/Mapscii.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'use strict';
const keypress = require('keypress');
const TermMouse = require('term-mouse');
const queryLocation = require('location');

const Renderer = require('./Renderer');
const TileSource = require('./TileSource');
Expand Down Expand Up @@ -52,6 +53,7 @@ class Mapscii {
this._initRenderer();
this._draw();
this.notify('Welcome to MapSCII! Use your cursors to navigate, a/z to zoom, q to quit.');
this.requestLocation(false);
}


Expand Down Expand Up @@ -221,6 +223,9 @@ class Mapscii {
case 'c':
config.useBraille = !config.useBraille;
break;
case 'l':
this.requestLocation(true);
break;
default:
draw = false;
}
Expand Down Expand Up @@ -251,6 +256,19 @@ class Mapscii {
return footer;
}

requestLocation(zoom = false) {
this.notify('Querying your location…');
return queryLocation()
.then((location) => {
this.setCenter(location.latitude, location.longitude);
// TODO: set zoom level according to precision
if (zoom) this.zoom = 16;
this._draw();
}, () => {
this.notify(`Couldn't query your location.`);
});
}

notify(text) {
config.onUpdate && config.onUpdate();
if (!config.headless) {
Expand Down

0 comments on commit 68db9c8

Please sign in to comment.