Merge branch 'master' into upgrade-dependencies

This commit is contained in:
Christian Paul 2019-06-16 22:18:01 -07:00
commit 421d71255f
11 changed files with 84 additions and 142 deletions

View File

@ -1,5 +1,4 @@
language: node_js language: node_js
node_js: node_js:
- "6"
- "8" - "8"
- "10" - "10"

6
AUTHORS Normal file
View File

@ -0,0 +1,6 @@
# This is the list of MapSCII authors for copyright purposes.
#
Michael Straßburger
Christian Paul (https://chrpaul.de)
Jannis R <mail@jannisr.de>
Alexander Zhukov (https://github.com/ZhukovAlexander)

View File

@ -1,6 +1,7 @@
MIT License MIT License
Copyright (c) 2016 Michael Straßburger Copyright (c) 2017 Michael Straßburger
Copyright (c) 2019 The MapSCII authors
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -78,7 +78,7 @@ If your terminal supports mouse events you can drag the map and use your scroll
#### Juggling the vectors and numbers #### Juggling the vectors and numbers
* [`earcut`](https://github.com/mapbox/earcut) for polygon triangulation * [`earcut`](https://github.com/mapbox/earcut) for polygon triangulation
* [`rbush`](https://github.com/mourner/rbush) for 2D spatial indexing of geo and label data * [`rbush`](https://github.com/mourner/rbush) for 2D spatial indexing of geo and label data
* [`breseham`](https://github.com/madbence/node-bresenham) for line point calculations * [`bresenham`](https://github.com/madbence/node-bresenham) for line point calculations
* [`simplify-js`](https://github.com/mourner/simplify-js) for polyline simplifications * [`simplify-js`](https://github.com/mourner/simplify-js) for polyline simplifications
#### Handling the flow #### Handling the flow
@ -132,13 +132,5 @@ You are free to copy, distribute, transmit and adapt our data, as long as you cr
The cartography in our map tiles, and our documentation, are licenced under the [Creative Commons Attribution-ShareAlike 2.0](http://creativecommons.org/licenses/by-sa/2.0/) licence (CC BY-SA). The cartography in our map tiles, and our documentation, are licenced under the [Creative Commons Attribution-ShareAlike 2.0](http://creativecommons.org/licenses/by-sa/2.0/) licence (CC BY-SA).
### MapSCII ### MapSCII
* [License](./LICENSE)
#### The MIT License (MIT) * [Authors](./AUTHORS)
Copyright (c) 2017 Michael Straßburger
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

138
package-lock.json generated
View File

@ -474,9 +474,9 @@
"dev": true "dev": true
}, },
"acorn": { "acorn": {
"version": "5.7.3", "version": "6.1.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz",
"integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==",
"dev": true "dev": true
}, },
"acorn-globals": { "acorn-globals": {
@ -487,14 +487,6 @@
"requires": { "requires": {
"acorn": "^6.0.1", "acorn": "^6.0.1",
"acorn-walk": "^6.0.1" "acorn-walk": "^6.0.1"
},
"dependencies": {
"acorn": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz",
"integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==",
"dev": true
}
} }
}, },
"acorn-jsx": { "acorn-jsx": {
@ -661,19 +653,6 @@
"babel-preset-jest": "^24.6.0", "babel-preset-jest": "^24.6.0",
"chalk": "^2.4.2", "chalk": "^2.4.2",
"slash": "^2.0.0" "slash": "^2.0.0"
},
"dependencies": {
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
}
} }
}, },
"babel-plugin-istanbul": { "babel-plugin-istanbul": {
@ -908,9 +887,9 @@
"dev": true "dev": true
}, },
"chalk": { "chalk": {
"version": "2.4.1", "version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"ansi-styles": "^3.2.1", "ansi-styles": "^3.2.1",
@ -1389,18 +1368,6 @@
"strip-json-comments": "^2.0.1", "strip-json-comments": "^2.0.1",
"table": "^5.2.3", "table": "^5.2.3",
"text-table": "^0.2.0" "text-table": "^0.2.0"
},
"dependencies": {
"js-yaml": {
"version": "3.13.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
"dev": true,
"requires": {
"argparse": "^1.0.7",
"esprima": "^4.0.0"
}
}
} }
}, },
"eslint-scope": { "eslint-scope": {
@ -1434,14 +1401,6 @@
"acorn": "^6.0.7", "acorn": "^6.0.7",
"acorn-jsx": "^5.0.0", "acorn-jsx": "^5.0.0",
"eslint-visitor-keys": "^1.0.0" "eslint-visitor-keys": "^1.0.0"
},
"dependencies": {
"acorn": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz",
"integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==",
"dev": true
}
} }
}, },
"esprima": { "esprima": {
@ -1766,17 +1725,6 @@
"flatted": "^2.0.0", "flatted": "^2.0.0",
"rimraf": "2.6.3", "rimraf": "2.6.3",
"write": "1.0.3" "write": "1.0.3"
},
"dependencies": {
"rimraf": {
"version": "2.6.3",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz",
"integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==",
"dev": true,
"requires": {
"glob": "^7.1.3"
}
}
} }
}, },
"flatted": { "flatted": {
@ -2414,9 +2362,9 @@
} }
}, },
"glob": { "glob": {
"version": "7.1.3", "version": "7.1.4",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz",
"integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==",
"dev": true, "dev": true,
"requires": { "requires": {
"fs.realpath": "^1.0.0", "fs.realpath": "^1.0.0",
@ -2562,9 +2510,9 @@
} }
}, },
"ieee754": { "ieee754": {
"version": "1.1.13", "version": "1.1.12",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.12.tgz",
"integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" "integrity": "sha512-GguP+DRY+pJ3soyIiGPTvdiVXjZ+DbXOxGpXn3eMvNW4x4irjqXm4wHKscC+TfxSJ0yw/S1F24tqdMNsMZTiLA=="
}, },
"ignore": { "ignore": {
"version": "4.0.6", "version": "4.0.6",
@ -2635,23 +2583,6 @@
"through": "^2.3.6" "through": "^2.3.6"
}, },
"dependencies": { "dependencies": {
"ansi-escapes": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz",
"integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==",
"dev": true
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"is-fullwidth-code-point": { "is-fullwidth-code-point": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
@ -3283,19 +3214,6 @@
"jest-worker": "^24.6.0", "jest-worker": "^24.6.0",
"source-map-support": "^0.5.6", "source-map-support": "^0.5.6",
"throat": "^4.0.0" "throat": "^4.0.0"
},
"dependencies": {
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
}
} }
}, },
"jest-runtime": { "jest-runtime": {
@ -3431,6 +3349,16 @@
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"dev": true "dev": true
}, },
"js-yaml": {
"version": "3.13.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
"dev": true,
"requires": {
"argparse": "^1.0.7",
"esprima": "^4.0.0"
}
},
"jsbn": { "jsbn": {
"version": "0.1.1", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
@ -3469,6 +3397,14 @@
"whatwg-url": "^6.4.1", "whatwg-url": "^6.4.1",
"ws": "^5.2.0", "ws": "^5.2.0",
"xml-name-validator": "^3.0.0" "xml-name-validator": "^3.0.0"
},
"dependencies": {
"acorn": {
"version": "5.7.3",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz",
"integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==",
"dev": true
}
} }
}, },
"jsesc": { "jsesc": {
@ -3794,9 +3730,9 @@
} }
}, },
"ms": { "ms": {
"version": "2.1.1", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true "dev": true
}, },
"mute-stream": { "mute-stream": {
@ -4642,9 +4578,9 @@
"dev": true "dev": true
}, },
"semver": { "semver": {
"version": "5.6.0", "version": "5.7.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz",
"integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==",
"dev": true "dev": true
}, },
"set-blocking": { "set-blocking": {
@ -5168,7 +5104,7 @@
}, },
"through": { "through": {
"version": "2.3.8", "version": "2.3.8",
"resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
"dev": true "dev": true
}, },

View File

@ -15,7 +15,7 @@
"mapscii": "./bin/mapscii.sh" "mapscii": "./bin/mapscii.sh"
}, },
"engines": { "engines": {
"node": ">=6.14.0" "node": ">=8"
}, },
"keywords": [ "keywords": [
"map", "map",

View File

@ -5,6 +5,7 @@
UI and central command center UI and central command center
*/ */
'use strict'; 'use strict';
const fs = require('fs');
const keypress = require('keypress'); const keypress = require('keypress');
const TermMouse = require('term-mouse'); const TermMouse = require('term-mouse');
@ -83,8 +84,8 @@ class Mapscii {
} }
_initRenderer() { _initRenderer() {
this.renderer = new Renderer(config.output, this.tileSource); const style = JSON.parse(fs.readFileSync(config.styleFile, 'utf8'));
this.renderer.loadStyleFile(config.styleFile); this.renderer = new Renderer(config.output, this.tileSource, style);
config.output.on('resize', () => { config.output.on('resize', () => {
this._resizeRenderer(); this._resizeRenderer();
@ -225,7 +226,7 @@ class Mapscii {
draw = false; draw = false;
} }
if (draw !== null) { if (draw) {
this._draw(); this._draw();
} }
} }

View File

@ -16,14 +16,11 @@ const utils = require('./utils');
const config = require('./config'); const config = require('./config');
class Renderer { class Renderer {
constructor(output, tileSource) { constructor(output, tileSource, style) {
this.output = output; this.output = output;
this.tileSource = tileSource; this.tileSource = tileSource;
this.labelBuffer = new LabelBuffer(); this.labelBuffer = new LabelBuffer();
} this.styler = new Styler(style);
loadStyleFile(file) {
this.styler = new Styler(file);
this.tileSource.useStyler(this.styler); this.tileSource.useStyler(this.styler);
} }

View File

@ -10,36 +10,33 @@
*/ */
'use strict'; 'use strict';
const fs = require('fs');
class Styler { class Styler {
constructor(file) { constructor(style) {
this.styleById = {}; this.styleById = {};
this.styleByLayer = {}; this.styleByLayer = {};
var base, name; var base, name;
const json = JSON.parse(fs.readFileSync(file).toString()); this.styleName = style.name;
this.styleName = json.name; if (style.constants) {
if (json.constants) { this._replaceConstants(style.constants, style.layers);
this._replaceConstants(json.constants, json.layers);
} }
for (const style of json.layers) { for (const layer of style.layers) {
if (style.ref && this.styleById[style.ref]) { if (layer.ref && this.styleById[layer.ref]) {
for (const ref of ['type', 'source-layer', 'minzoom', 'maxzoom', 'filter']) { for (const ref of ['type', 'source-layer', 'minzoom', 'maxzoom', 'filter']) {
if (this.styleById[style.ref][ref] && !style[ref]) { if (this.styleById[layer.ref][ref] && !layer[ref]) {
style[ref] = this.styleById[style.ref][ref]; layer[ref] = this.styleById[layer.ref][ref];
} }
} }
} }
style.appliesTo = this._compileFilter(style.filter); layer.appliesTo = this._compileFilter(layer.filter);
//TODO Better translation of: @styleByLayer[style['source-layer']] ?= [] //TODO Better translation of: @styleByLayer[style['source-layer']] ?= []
if ((base = this.styleByLayer)[name = style['source-layer']] == null) { if ((base = this.styleByLayer)[name = layer['source-layer']] == null) {
base[name] = []; base[name] = [];
} }
this.styleByLayer[style['source-layer']].push(style); this.styleByLayer[layer['source-layer']].push(layer);
this.styleById[style.id] = style; this.styleById[layer.id] = layer;
} }
} }

View File

@ -16,10 +16,10 @@ const config = require('./config');
// https://github.com/mapbox/node-mbtiles has native build dependencies (sqlite3) // https://github.com/mapbox/node-mbtiles has native build dependencies (sqlite3)
// To maximize MapSCIIs compatibility, MBTiles support must be manually added via // To maximize MapSCIIs compatibility, MBTiles support must be manually added via
// $> npm install -g mbtiles // $> npm install -g @mapbox/mbtiles
let MBTiles = null; let MBTiles = null;
try { try {
MBTiles = require('mbtiles'); MBTiles = require('@mapbox/mbtiles');
} catch (err) {void 0;} } catch (err) {void 0;}
const modes = { const modes = {
@ -49,7 +49,7 @@ class TileSource {
} else if (this.source.endsWith('.mbtiles')) { } else if (this.source.endsWith('.mbtiles')) {
if (!MBTiles) { if (!MBTiles) {
throw new Error('MBTiles support must be installed with following command: \'npm install -g mbtiles\''); throw new Error('MBTiles support must be installed with following command: \'npm install -g @mapbox/mbtiles\'');
} }
this.mode = modes.MBTiles; this.mode = modes.MBTiles;
@ -168,7 +168,8 @@ class TileSource {
fs.mkdirSync(path); fs.mkdirSync(path);
return true; return true;
} catch (error) { } catch (error) {
return error.code === 'EEXIST'; if (error.code === 'EEXIST') return true;
throw error;
} }
} }
} }

12
src/TileSource.spec.js Normal file
View File

@ -0,0 +1,12 @@
'use strict';
const TileSource = require('./TileSource');
describe('TileSource', () => {
describe('with a HTTP source', () => {
test('sets the mode to 3', async () => {
const tileSource = new TileSource();
await tileSource.init('http://mapscii.me/');
tileSource.mode = 3;
});
});
});