From 9c97711a9991d9e11469cc29c0be2ab25d5108a7 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Fri, 16 Aug 2024 13:15:00 +0200 Subject: [PATCH] fix: routes id after removing all --- index.html | 8 ++++---- modules/routes-generator.js | 7 ++++++- modules/ui/routes-creator.js | 2 +- modules/ui/routes-editor.js | 2 +- modules/ui/routes-overview.js | 4 ++-- versioning.js | 2 +- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index 6453976a..a1e0dbf9 100644 --- a/index.html +++ b/index.html @@ -8190,7 +8190,7 @@ - + @@ -8219,8 +8219,8 @@ - - + + @@ -8235,7 +8235,7 @@ - + diff --git a/modules/routes-generator.js b/modules/routes-generator.js index 376e9d03..3a79e69a 100644 --- a/modules/routes-generator.js +++ b/modules/routes-generator.js @@ -434,7 +434,7 @@ window.Routes = (function () { const points = getPoints("trails", pathCells, pointsArray); const feature = cells.f[cellId]; - const routeId = Math.max(...routes.map(route => route.i)) + 1; + const routeId = getNextId(); const newRoute = {i: routeId, group: "trails", feature, points}; routes.push(newRoute); @@ -706,6 +706,10 @@ window.Routes = (function () { return path.getTotalLength(); } + function getNextId() { + return pack.routes.length ? Math.max(...pack.routes.map(r => r.i)) + 1 : 0; + } + function remove(route) { const routes = pack.cells.routes; @@ -738,6 +742,7 @@ window.Routes = (function () { generateName, getPath, getLength, + getNextId, remove }; })(); diff --git a/modules/ui/routes-creator.js b/modules/ui/routes-creator.js index cd9d853f..3e2d6620 100644 --- a/modules/ui/routes-creator.js +++ b/modules/ui/routes-creator.js @@ -97,7 +97,7 @@ function createRoute(defaultGroup) { const points = createRoute.points; if (points.length < 2) return tip("Add at least 2 points", false, "error"); - const routeId = Math.max(...pack.routes.map(route => route.i)) + 1; + const routeId = Routes.getNextId(); const group = byId("routeCreatorGroupSelect").value; const feature = pack.cells.f[points[0][2]]; const route = {points, group, feature, i: routeId}; diff --git a/modules/ui/routes-editor.js b/modules/ui/routes-editor.js index 3a137623..82f13e44 100644 --- a/modules/ui/routes-editor.js +++ b/modules/ui/routes-editor.js @@ -194,7 +194,7 @@ function editRoute(id) { // create new route const newRoute = { - i: Math.max(...pack.routes.map(route => route.i)) + 1, + i: Routes.getNextId(), group: route.group, feature: route.feature, name: route.name, diff --git a/modules/ui/routes-overview.js b/modules/ui/routes-overview.js index d9817dc3..3a8cc5fa 100644 --- a/modules/ui/routes-overview.js +++ b/modules/ui/routes-overview.js @@ -58,7 +58,7 @@ function overviewRoutes() { // update footer routesFooterNumber.innerHTML = pack.routes.length; - const averageLength = rn(d3.mean(pack.routes.map(r => r.length))); + const averageLength = rn(d3.mean(pack.routes.map(r => r.length)) || 0); routesFooterLength.innerHTML = averageLength * distanceScale + " " + distanceUnitInput.value; // add listeners @@ -175,8 +175,8 @@ function overviewRoutes() { pack.routes = []; routes.selectAll("path").remove(); + routesOverviewAddLines(); $(this).dialog("close"); - $("#routesOverview").dialog("close"); }, Cancel: function () { $(this).dialog("close"); diff --git a/versioning.js b/versioning.js index 4bee932e..30c5eedb 100644 --- a/versioning.js +++ b/versioning.js @@ -1,7 +1,7 @@ "use strict"; // version and caching control -const version = "1.99.01"; // generator version, update each time +const version = "1.99.02"; // generator version, update each time { document.title += " v" + version;