Refactor route merging logic for improved performance

This commit is contained in:
Azgaar 2024-05-23 03:33:54 +02:00
parent 29e7ab0953
commit 4e79e020e8
4 changed files with 91 additions and 57 deletions

View file

@ -465,9 +465,20 @@ function saveGeoJSON_Cells() {
}
function saveGeoJSON_Routes() {
const features = pack.routes.map(({id, points, cells, group}) => {
const coordinates = points || getRoutePoints(cells, group);
return {type: "Feature", geometry: {type: "LineString", coordinates}, properties: {id, group}};
const {cells, burgs} = pack;
let points = cells.p.map(([x, y], cellId) => {
const burgId = cells.burg[cellId];
if (burgId) return [burgs[burgId].x, burgs[burgId].y];
return [x, y];
});
const features = pack.routes.map(route => {
const coordinates = route.points || getRoutePoints(route, points);
return {
type: "Feature",
geometry: {type: "LineString", coordinates},
properties: {id: route.id, group: route.group}
};
});
const json = {type: "FeatureCollection", features};