RenderLines = {
return (spi) => {
const sp = Math.max(0.00005, Math.round(spi * 10000) / 10000);
const renderedColor = new Map();
const CoordsOfInterest = new Map();
function FindPointsInLine(in_geom, line_buffer) {
return in_geom.reduce(
(acc, cur, idx) => {
const last = acc[acc.length - 1],
next = in_geom[idx + 1];
if (next !== undefined) {
const isTheSame = CompareCoords(last, next);
if (isTheSame) {
return acc;
} else {
acc.push(cur);
return acc;
}
} else {
acc.push(cur);
return acc;
}
},
[in_geom[0]]
);
}
for (const [id, segment] of LineSegments.entries()) {
let linewidth = sp,
spacing = linewidth + sp,
maxline = segment.colors.length;
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 = false
? FindPointsInLine(offsetClippedLine.geometry.coordinates)
: offsetClippedLine.geometry.coordinates;
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(
FindPointsInLine(coords)
);
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);
};
}