-
Notifications
You must be signed in to change notification settings - Fork 2
/
innerlines.js
35 lines (29 loc) · 1.34 KB
/
innerlines.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { meshArcs } from 'topojson-client'
import { reconstructTopojson } from './helpers/reconstructTopojson.js'
import { addLastLayerName, getLayerName } from './helpers/layers.js'
/**
* Keep share arcs of adjacent Polygon|MultiPolygon
* A group by a property can be applied at the same time.
* Return a MultiLineString
*
* @param {TopoJSON} topo - A valid topojson object
* @param {Object} options - optional parameters
* @param {Boolean} options.chain - intern option to know if function is called in chained mode
* @param {String|Number} options.layer - a single target layer (name or index)
* @param {String} options.groupby - groupby by a data property before
* @param {String} options.name - name of the new layer
* @param {Boolean} options.addLayer - true add a layer to existing ones
* @returns {TopoJSON}
*/
export function innerlines (topo, options = {}) {
let {chain, layer, groupby, addLayer, name} = options
layer = getLayerName(topo, layer, {chain})
name = name ?? "innerlines"
const geometries = groupby
? meshArcs(topo, topo.objects[layer], (a, b) => a.properties[groupby] !== b.properties[groupby])
: meshArcs(topo, topo.objects[layer], (a, b) => a !== b)
const output = reconstructTopojson(topo, geometries, {name, addLayer})
// Update topojson.lastLayer property
addLastLayerName(output, name)
return output
}