diff --git a/.travis.yml b/.travis.yml index ceafed9..437ee5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: node_js node_js: - - "6" - "8" - "10" diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..57ab55f --- /dev/null +++ b/AUTHORS @@ -0,0 +1,6 @@ +# This is the list of MapSCII authors for copyright purposes. +# +Michael Straßburger +Christian Paul (https://chrpaul.de) +Jannis R +Alexander Zhukov (https://github.com/ZhukovAlexander) diff --git a/LICENSE b/LICENSE index 2af5e5c..34987f4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ 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 of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index ef7c69c..2ba4ad7 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ If your terminal supports mouse events you can drag the map and use your scroll #### Juggling the vectors and numbers * [`earcut`](https://github.com/mapbox/earcut) for polygon triangulation * [`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 #### 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). ### MapSCII - -#### The MIT License (MIT) - -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. +* [License](./LICENSE) +* [Authors](./AUTHORS) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bab7dee..f8256a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -474,9 +474,9 @@ "dev": true }, "acorn": { - "version": "5.7.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", - "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", + "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==", "dev": true }, "acorn-globals": { @@ -487,14 +487,6 @@ "requires": { "acorn": "^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": { @@ -661,19 +653,6 @@ "babel-preset-jest": "^24.6.0", "chalk": "^2.4.2", "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": { @@ -908,9 +887,9 @@ "dev": true }, "chalk": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", - "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", + "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", @@ -1389,18 +1368,6 @@ "strip-json-comments": "^2.0.1", "table": "^5.2.3", "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": { @@ -1434,14 +1401,6 @@ "acorn": "^6.0.7", "acorn-jsx": "^5.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": { @@ -1766,17 +1725,6 @@ "flatted": "^2.0.0", "rimraf": "2.6.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": { @@ -2414,9 +2362,9 @@ } }, "glob": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", + "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -2562,9 +2510,9 @@ } }, "ieee754": { - "version": "1.1.13", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", - "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.12.tgz", + "integrity": "sha512-GguP+DRY+pJ3soyIiGPTvdiVXjZ+DbXOxGpXn3eMvNW4x4irjqXm4wHKscC+TfxSJ0yw/S1F24tqdMNsMZTiLA==" }, "ignore": { "version": "4.0.6", @@ -2635,23 +2583,6 @@ "through": "^2.3.6" }, "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": { "version": "2.0.0", "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", "source-map-support": "^0.5.6", "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": { @@ -3431,6 +3349,16 @@ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", "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": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", @@ -3469,6 +3397,14 @@ "whatwg-url": "^6.4.1", "ws": "^5.2.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": { @@ -3794,9 +3730,9 @@ } }, "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, "mute-stream": { @@ -4642,9 +4578,9 @@ "dev": true }, "semver": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", + "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", "dev": true }, "set-blocking": { @@ -5168,7 +5104,7 @@ }, "through": { "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=", "dev": true }, diff --git a/package.json b/package.json index df57fa1..ea4cd55 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "mapscii": "./bin/mapscii.sh" }, "engines": { - "node": ">=6.14.0" + "node": ">=8" }, "keywords": [ "map", diff --git a/src/Mapscii.js b/src/Mapscii.js index e9be433..dcdc113 100644 --- a/src/Mapscii.js +++ b/src/Mapscii.js @@ -5,6 +5,7 @@ UI and central command center */ 'use strict'; +const fs = require('fs'); const keypress = require('keypress'); const TermMouse = require('term-mouse'); @@ -83,8 +84,8 @@ class Mapscii { } _initRenderer() { - this.renderer = new Renderer(config.output, this.tileSource); - this.renderer.loadStyleFile(config.styleFile); + const style = JSON.parse(fs.readFileSync(config.styleFile, 'utf8')); + this.renderer = new Renderer(config.output, this.tileSource, style); config.output.on('resize', () => { this._resizeRenderer(); @@ -225,7 +226,7 @@ class Mapscii { draw = false; } - if (draw !== null) { + if (draw) { this._draw(); } } diff --git a/src/Renderer.js b/src/Renderer.js index 47c0125..2747bef 100644 --- a/src/Renderer.js +++ b/src/Renderer.js @@ -16,14 +16,11 @@ const utils = require('./utils'); const config = require('./config'); class Renderer { - constructor(output, tileSource) { + constructor(output, tileSource, style) { this.output = output; this.tileSource = tileSource; this.labelBuffer = new LabelBuffer(); - } - - loadStyleFile(file) { - this.styler = new Styler(file); + this.styler = new Styler(style); this.tileSource.useStyler(this.styler); } diff --git a/src/Styler.js b/src/Styler.js index 3ca4d74..cce1647 100644 --- a/src/Styler.js +++ b/src/Styler.js @@ -10,36 +10,33 @@ */ 'use strict'; -const fs = require('fs'); - class Styler { - constructor(file) { + constructor(style) { this.styleById = {}; this.styleByLayer = {}; var base, name; - const json = JSON.parse(fs.readFileSync(file).toString()); - this.styleName = json.name; - if (json.constants) { - this._replaceConstants(json.constants, json.layers); + this.styleName = style.name; + if (style.constants) { + this._replaceConstants(style.constants, style.layers); } - for (const style of json.layers) { - if (style.ref && this.styleById[style.ref]) { + for (const layer of style.layers) { + if (layer.ref && this.styleById[layer.ref]) { for (const ref of ['type', 'source-layer', 'minzoom', 'maxzoom', 'filter']) { - if (this.styleById[style.ref][ref] && !style[ref]) { - style[ref] = this.styleById[style.ref][ref]; + if (this.styleById[layer.ref][ref] && !layer[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']] ?= [] - if ((base = this.styleByLayer)[name = style['source-layer']] == null) { + if ((base = this.styleByLayer)[name = layer['source-layer']] == null) { base[name] = []; } - this.styleByLayer[style['source-layer']].push(style); - this.styleById[style.id] = style; + this.styleByLayer[layer['source-layer']].push(layer); + this.styleById[layer.id] = layer; } } diff --git a/src/TileSource.js b/src/TileSource.js index 2ae3f63..117a1e6 100644 --- a/src/TileSource.js +++ b/src/TileSource.js @@ -16,10 +16,10 @@ const config = require('./config'); // https://github.com/mapbox/node-mbtiles has native build dependencies (sqlite3) // To maximize MapSCII’s compatibility, MBTiles support must be manually added via -// $> npm install -g mbtiles +// $> npm install -g @mapbox/mbtiles let MBTiles = null; try { - MBTiles = require('mbtiles'); + MBTiles = require('@mapbox/mbtiles'); } catch (err) {void 0;} const modes = { @@ -49,7 +49,7 @@ class TileSource { } else if (this.source.endsWith('.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; @@ -168,7 +168,8 @@ class TileSource { fs.mkdirSync(path); return true; } catch (error) { - return error.code === 'EEXIST'; + if (error.code === 'EEXIST') return true; + throw error; } } } diff --git a/src/TileSource.spec.js b/src/TileSource.spec.js new file mode 100644 index 0000000..77d2022 --- /dev/null +++ b/src/TileSource.spec.js @@ -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; + }); + }); +});