aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/park-editor.mjs
diff options
context:
space:
mode:
authorYasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>2026-10-29 14:44:18 +0900
committerYasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>2026-10-29 14:44:18 +0900
commit1495a79dd29e0d4c370086aec9dfb146c7f24bc3 (patch)
tree0f6231a105be157dda754b9e2f57b2019298dc9e /scripts/park-editor.mjs
parented970d8dd6dbbaded7f1f45963ef54049f3571b9 (diff)
park-editor: 列の追加と文字化け項目の表示
スイング遊具にロッキンパッピー等を含め、シェルター列を2行に、緯度・経度を最小幅にした。草地広場・多目的広場の列を追加。文字化けした項目名をバナー表示し、古い画面からの保存で新項目・新レコードが消えないようマージする。
Diffstat (limited to 'scripts/park-editor.mjs')
-rw-r--r--scripts/park-editor.mjs44
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/park-editor.mjs b/scripts/park-editor.mjs
index e3bae45..48b9f17 100644
--- a/scripts/park-editor.mjs
+++ b/scripts/park-editor.mjs
@@ -83,6 +83,42 @@ function findCorruptions(value, path, out) {
return out;
}
+function recordKey(obj) {
+ const src = obj && obj.properties ? obj.properties : obj;
+ if (!src) return null;
+ for (const key of ["公園名", "name", "名称", "our_name"]) {
+ const value = src[key];
+ if (typeof value === "string" && value) return value;
+ }
+ return null;
+}
+
+// ブラウザが古いデータを持っていても、後から足した項目やレコードを消さないようにする。
+// 画面になくて編集できないキーは、ディスク側の値を残す。
+function mergeMissing(postedList, currentList) {
+ const map = new Map();
+ for (const rec of currentList) {
+ const key = recordKey(rec);
+ if (key) map.set(key, rec);
+ }
+ const postedKeys = new Set();
+ for (const rec of postedList) {
+ const key = recordKey(rec);
+ if (!key) continue;
+ postedKeys.add(key);
+ const current = map.get(key);
+ if (!current) continue;
+ const dst = rec.properties || rec;
+ const src = current.properties || current;
+ for (const [field, value] of Object.entries(src)) {
+ if (!(field in dst)) dst[field] = value;
+ }
+ }
+ for (const [key, rec] of map) {
+ if (!postedKeys.has(key)) postedList.push(rec);
+ }
+}
+
const server = createServer(async (req, res) => {
try {
const url = (req.url || "").split("?")[0];
@@ -132,6 +168,14 @@ const server = createServer(async (req, res) => {
throw new Error("データが配列ではありません");
}
+ // 古い画面からの保存で、新しい項目・レコードが消えないようにマージする
+ const current = JSON.parse(await readFile(target.dataset.path, "utf-8"));
+ if (target.id === "nearbyParks") {
+ mergeMissing(data.features, current.features || []);
+ } else {
+ mergeMissing(data, current);
+ }
+
const text = target.dataset.pretty
? `${JSON.stringify(data, null, 2)}\n`
: `${JSON.stringify(data)}\n`;