feat: edit routes - main

This commit is contained in:
Azgaar 2024-05-04 12:04:45 +02:00
parent d6c01c8995
commit 68b4cfd370
9 changed files with 401 additions and 357 deletions

View file

@ -465,16 +465,11 @@ function saveGeoJSON_Cells() {
}
function saveGeoJSON_Routes() {
const json = {type: "FeatureCollection", features: []};
routes.selectAll("g > path").each(function () {
const coordinates = getRoutePoints(this);
const id = this.id;
const type = this.parentElement.id;
const feature = {type: "Feature", geometry: {type: "LineString", coordinates}, properties: {id, type}};
json.features.push(feature);
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 json = {type: "FeatureCollection", features};
const fileName = getFileName("Routes") + ".geojson";
downloadFile(JSON.stringify(json), fileName, "application/json");
@ -519,17 +514,6 @@ function getCellCoordinates(vertices) {
return [coordinates.concat([coordinates[0]])];
}
function getRoutePoints(node) {
let points = [];
const l = node.getTotalLength();
const increment = l / Math.ceil(l / 2);
for (let i = 0; i <= l; i += increment) {
const p = node.getPointAtLength(i);
points.push(getCoordinates(p.x, p.y, 4));
}
return points;
}
function getRiverPoints(node) {
let points = [];
const l = node.getTotalLength() / 2; // half-length