-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlinks.js
43 lines (38 loc) · 1.22 KB
/
links.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
36
37
38
39
40
41
42
43
import { figuration } from "./helpers/figuration.js";
import { centroid } from "./helpers/centroid.js";
import { geoimport } from "./helpers/geoimport.js";
export function links(options = {}) {
let geojson = geoimport(options.geojson);
let geojson_id = options.geojson_id;
let data = options.data;
let data_i = options.data_i != undefined ? options.data_i : "i";
let data_j = options.data_j != undefined ? options.data_j : "j";
let planar = options.planar ? true : false;
let dots;
if (figuration(geojson) == "p") {
dots = geojson.features;
} else {
dots = centroid(geojson, { planar: planar }).features;
}
const coordsbyid = new Map(
dots.map((d) => [d.properties[geojson_id], d.geometry.coordinates])
);
// PUISQUE 2 POINTS UFFISENT, FAIRE SANS TURF.JS
let features = [];
data.forEach((d) => {
if (
coordsbyid.get(d[data_i]) != undefined &&
coordsbyid.get(d[data_j]) != undefined
) {
features.push({
type: "Feature",
properties: d,
geometry: {
type: "LineString",
coordinates: [coordsbyid.get(d[data_i]), coordsbyid.get(d[data_j])],
},
});
}
});
return { type: "FeatureCollection", features: features };
}