Skip to content

Commit 1388c40

Browse files
committed
feat(feature): tippecanoe: configurable layer selectors
1 parent 9acd68c commit 1388c40

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

bin/cmd/feature/tippecanoe.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const _ = require('lodash')
22
const path = require('path')
33
const Stream = require('stream')
4-
const feature = require('../../../whosonfirst/feature')
54
const stream = {
65
json: require('../../../stream/json'),
76
shell: require('../../../stream/shell'),
@@ -33,18 +32,30 @@ module.exports = {
3332
default: 'versatiles/versatiles-tippecanoe',
3433
describe: 'docker image to use'
3534
})
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+
})
3640
},
3741
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+
3851
const tap = new Stream.PassThrough()
3952
process.stdin.once('data', () => { // avoid empty stdin
4053
tap.pipe(argv.docker ? docker(argv) : local(argv)).pipe(process.stdout)
4154
})
4255
.pipe(stream.json.parse())
4356
.pipe(stream.miss.through.obj((feat, enc, next) => {
4457
// 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')
4859
next(null, feat)
4960
}))
5061
.pipe(stream.json.stringify('', '\n', '')) // add a newline between features

0 commit comments

Comments
 (0)