not baad
This commit is contained in:
parent
4a8aff90b2
commit
6cef9a3abe
11 changed files with 1184 additions and 235 deletions
|
|
@ -1,6 +1,24 @@
|
|||
import { INF, MAP_H, MAP_W } from "./mapUtils.js";
|
||||
|
||||
const ADMIN_ID_KEYS = ["adminId", "municipalityId", "adminNumericId"];
|
||||
const PREFECTURE_NAME_KEYS = ["prefectureName", "prefectureRegionName", "regionName", "name", "labelName"];
|
||||
|
||||
function usableName(value) {
|
||||
const text = value == null ? "" : String(value).trim();
|
||||
if (!text) return "";
|
||||
if (/^県域\d*$/u.test(text)) return "";
|
||||
if (/^Unnamed prefecture$/i.test(text)) return "";
|
||||
if (/^Prefecture\s*-?\d+$/i.test(text)) return "";
|
||||
return text;
|
||||
}
|
||||
|
||||
function firstUsableName(obj, keys = PREFECTURE_NAME_KEYS) {
|
||||
for (const key of keys) {
|
||||
const text = usableName(obj?.[key]);
|
||||
if (text) return text;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function coordIndex(width, height, x, y) {
|
||||
if (x < 0 || y < 0 || x >= width || y >= height) return -1;
|
||||
|
|
@ -190,6 +208,7 @@ export function refreshPrefectureRegionsMetadata({
|
|||
prefectureRegionId,
|
||||
sea,
|
||||
existing = [],
|
||||
adminCenters = [],
|
||||
fields = {},
|
||||
width = MAP_W,
|
||||
height = MAP_H,
|
||||
|
|
@ -219,6 +238,13 @@ export function refreshPrefectureRegionsMetadata({
|
|||
const id = Number.isFinite(region?.prefectureRegionId) ? Math.floor(region.prefectureRegionId) : Number.isFinite(region?.id) ? Math.floor(region.id) : -1;
|
||||
if (id >= 0 && !existingById.has(id)) existingById.set(id, region);
|
||||
}
|
||||
const nameByPref = new Map();
|
||||
for (const center of adminCenters || []) {
|
||||
const id = Number.isFinite(center?.prefectureRegionId) ? Math.floor(center.prefectureRegionId) : -1;
|
||||
if (id < 0 || nameByPref.has(id)) continue;
|
||||
const name = firstUsableName(center, ["prefectureName", "prefectureRegionName", "regionName"]);
|
||||
if (name) nameByPref.set(id, name);
|
||||
}
|
||||
let fallbackRegionsAdded = 0;
|
||||
const prefectureRegions = [];
|
||||
for (const [id, row] of [...byId.entries()].sort((a, b) => a[0] - b[0])) {
|
||||
|
|
@ -226,6 +252,7 @@ export function refreshPrefectureRegionsMetadata({
|
|||
if (!base) fallbackRegionsAdded++;
|
||||
const x = row.bestI >= 0 ? row.bestI % width : Math.round(row.sx / Math.max(1, row.area));
|
||||
const y = row.bestI >= 0 ? Math.floor(row.bestI / width) : Math.round(row.sy / Math.max(1, row.area));
|
||||
const resolvedName = firstUsableName(base) || nameByPref.get(id) || `県域${id + 1}`;
|
||||
prefectureRegions.push({
|
||||
...(base || {}),
|
||||
id,
|
||||
|
|
@ -235,8 +262,11 @@ export function refreshPrefectureRegionsMetadata({
|
|||
y: y - pointOffsetY,
|
||||
area: row.area,
|
||||
kind: base?.kind || (id === 0 ? "Current Prefecture" : "Prefecture"),
|
||||
name: base?.name || `県域${id + 1}`,
|
||||
labelName: base?.labelName || base?.name || `県域${id + 1}`,
|
||||
name: resolvedName,
|
||||
labelName: firstUsableName(base, ["labelName"]) || resolvedName,
|
||||
prefectureName: firstUsableName(base, ["prefectureName"]) || resolvedName,
|
||||
prefectureRegionName: firstUsableName(base, ["prefectureRegionName"]) || resolvedName,
|
||||
regionName: firstUsableName(base, ["regionName"]) || resolvedName,
|
||||
forceLabel: true,
|
||||
labelPriorityBase: base?.labelPriorityBase || 950 + Math.sqrt(row.area),
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue