RenderLines = {
return (spi) => {
const sp = Math.round(spi * 10000) / 10000;
const renderedColor = new Map();
const CoordsOfInterest = new Map();
for (const [id, segment] of LineSegments.entries()) {
let linewidth = sp,
spacing = linewidth + sp,
maxline = segment.colors.length;
const LineBuffer = _Imports.Geospatial.turf.buffer(
_Imports.Geospatial.turf.lineString(segment.geometry),
maxline * spacing - ((maxline - 1) * spacing) / 2 + 0.001
);
for (const color of segment.colors) {
const lineoffset =
segment.colors.indexOf(color) * spacing -
((maxline - 1) * spacing) / 2;
const line = _Imports.Geospatial.turf.lineString(segment.geometry, {
stroke: color,
id: `${id}:${color}`
});
const ClippedLine = ClipLine(line, Math.max(0.005, sp * 3));
const offsetClippedLine = _Imports.Geospatial.turf.lineOffset(
ClippedLine,
Math.floor(lineoffset * 10000) / 10000
);
const PointsThatFallInLine =
offsetClippedLine.geometry.coordinates.filter((c) => {
return _Imports.Geospatial.turf.booleanPointInPolygon(
_Imports.Geospatial.turf.point(c),
LineBuffer
);
});
CoordsOfInterest.set(`${id}:${color}:top`, PointsThatFallInLine[0]);
CoordsOfInterest.set(
`${id}:${color}:bottom`,
PointsThatFallInLine[PointsThatFallInLine.length - 1]
);
if (renderedColor.has(color)) {
renderedColor.get(color).push(PointsThatFallInLine);
} else {
renderedColor.set(color, [PointsThatFallInLine]);
}
}
}
for (const connection of LineConnections) {
const coords = [
CoordsOfInterest.get(
`Segment:${connection.from[0]}:${connection.color}:${connection.from[1]}`
),
CoordsOfInterest.get(
`Segment:${connection.to[0]}:${connection.color}:${connection.to[1]}`
)
];
if (!coords.includes(undefined)) {
const line = _Imports.Geospatial.turf.lineString(coords, {
stroke: connection.color,
id: `Connection:${connection.from[0]}:${connection.from[1]}:${connection.to[0]}:${connection.to[1]}:${connection.color}`
});
renderedColor.get(connection.color).push(line.geometry.coordinates);
}
}
const rendered = [];
for (const [color, coords] of renderedColor.entries()) {
rendered.push(
_Imports.Geospatial.turf.multiLineString(coords, {
id: color,
stroke: color
})
);
}
return _Imports.Geospatial.turf.featureCollection(rendered);
};
}