|
1 | 1 | const _ = require('lodash')
|
2 | 2 | const path = require('path')
|
3 | 3 | const Stream = require('stream')
|
4 |
| -const feature = require('../../../whosonfirst/feature') |
5 | 4 | const stream = {
|
6 | 5 | json: require('../../../stream/json'),
|
7 | 6 | shell: require('../../../stream/shell'),
|
@@ -33,18 +32,30 @@ module.exports = {
|
33 | 32 | default: 'versatiles/versatiles-tippecanoe',
|
34 | 33 | describe: 'docker image to use'
|
35 | 34 | })
|
| 35 | + yargs.option('layer-selectors', { |
| 36 | + type: 'string', |
| 37 | + default: 'properties.wof:placetype|properties.src:alt_label', |
| 38 | + describe: 'lodash selectors to pick layer name (pipe separated, first matching used)' |
| 39 | + }) |
36 | 40 | },
|
37 | 41 | handler: (argv) => {
|
| 42 | + // layers are dynamically selected based on the first matching lodash selector |
| 43 | + const layerSelectors = _.get(argv, 'layer-selectors').split('|').map(p => p.trim()) |
| 44 | + const pickLayer = (feat) => { |
| 45 | + for (const selector of layerSelectors) { |
| 46 | + const found = _.get(feat, selector) |
| 47 | + if (_.isString(found)) return found.trim() |
| 48 | + } |
| 49 | + } |
| 50 | + |
38 | 51 | const tap = new Stream.PassThrough()
|
39 | 52 | process.stdin.once('data', () => { // avoid empty stdin
|
40 | 53 | tap.pipe(argv.docker ? docker(argv) : local(argv)).pipe(process.stdout)
|
41 | 54 | })
|
42 | 55 | .pipe(stream.json.parse())
|
43 | 56 | .pipe(stream.miss.through.obj((feat, enc, next) => {
|
44 | 57 | // add tippecanoe config
|
45 |
| - let layer = feature.getPlacetype(feat) |
46 |
| - if (feature.isAltGeometry(feat)) { layer = `alt-${feature.getAltLabel(feat)}` } |
47 |
| - _.set(feat, 'tippecanoe.layer', layer) |
| 58 | + _.set(feat, 'tippecanoe.layer', pickLayer(feat) || 'unknown') |
48 | 59 | next(null, feat)
|
49 | 60 | }))
|
50 | 61 | .pipe(stream.json.stringify('', '\n', '')) // add a newline between features
|
|
0 commit comments