Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query current location & center map #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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':
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW this would conflict with the changes made in fccacad :(

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