RenderLines = {
const LineOffset = _Imports.Geospatial.turf.lineOffset;
const LineString = _Imports.Geospatial.turf.lineString;
const MultiLineString = _Imports.Geospatial.turf.multiLineString;
const _ClipLine = ClipLine;
const zero = _Imports.Geospatial.turf.point([0, 0]);
return function RenderLines(RequestedSpacing) {
const spacing = Math.max(0.00005, Math.min(0.3, RequestedSpacing));
const RenderedColourLine = new Map();
const ColourSegmentsEndpoints = new Map();
for (const [segment_id, segment] of LineSegments.entries()) {
const shouldReverseColor =
_Imports.Geospatial.turf.distance(zero, segment.geometry[0]) >
_Imports.Geospatial.turf.distance(
zero,
segment.geometry[segment.geometry.length - 1]
);
const sortedcolors = segment.colors.sort();
const colors = shouldReverseColor
? sortedcolors.toReversed()
: sortedcolors;
const linespace = spacing * 2;
const totallines = segment.colors.length;
const line = LineString(segment.geometry);
const line_clipped = _ClipLine(line, Math.max(0.005, spacing * 5));
for (let i = 0; i < totallines; i++) {
const color = colors[i];
const lineoffset = i * linespace - ((totallines - 1) * linespace) / 2;
const line_clipped_offset = LineOffset(
line_clipped,
parseFloat(lineoffset.toFixed(5))
);
const line_processed = line_clipped_offset.geometry.coordinates;
ColourSegmentsEndpoints.set(
`${segment_id}:${color}:top`,
line_processed[0]
);
ColourSegmentsEndpoints.set(
`${segment_id}:${color}:bottom`,
line_processed[line_processed.length - 1]
);
if (RenderedColourLine.has(color)) {
RenderedColourLine.get(color).push(line_processed);
} else {
RenderedColourLine.set(color, [line_processed]);
}
}
}
for (const connection of LineConnections) {
const coords = [
ColourSegmentsEndpoints.get(
`Segment:${connection.from[0]}:${connection.color}:${connection.from[1]}`
),
ColourSegmentsEndpoints.get(
`Segment:${connection.to[0]}:${connection.color}:${connection.to[1]}`
)
];
const finalCoords = coords.filter((c) => {
return c !== undefined && c.length > 1;
});
RenderedColourLine.get(connection.color).push(finalCoords);
}
const rendered = [];
for (const [color, coords] of RenderedColourLine.entries()) {
rendered.push(
MultiLineString(coords, {
id: color,
stroke: color
})
);
}
return _Imports.Geospatial.turf.featureCollection(rendered);
};
}