fix: burg groups - apply default new groups on load if source has default groups

This commit is contained in:
Azgaar 2025-06-02 02:05:35 +02:00
parent f03cade309
commit bb1e913929

View file

@ -975,43 +975,50 @@ export function resolveVersionConflicts(mapVersion) {
if (isOlderThan("1.109.0")) {
// v1.109.0 added customizable burg groups and icons
burgIcons.selectAll("circle, use").each(function () {
const group = this.parentNode.id;
const id = this.id.replace(/^burg/, "");
const burg = pack.burgs[id];
if (burg) burg.group = group;
});
options.burgs = {groups: []};
burgIcons.selectAll("g").each(function (_el, index) {
const name = this.id;
const isDefault = name === "towns";
options.burgs.groups.push({name, active: true, order: index + 1, isDefault, preview: "watabou-city"});
const size = Number(this.getAttribute("size") || 2) * 2;
this.removeAttribute("size");
this.setAttribute("font-size", size);
this.setAttribute("stroke-width", 1);
});
if (!options.burgs.groups.length) {
// default groups were 'cities' and 'towns'
const iconGroups = burgIcons.selectAll("g");
const citiesGroup = burgIcons.select("#cities");
const townsGroup = burgIcons.select("#towns");
if (!iconGroups.size() || (iconGroups.size() === 2 && citiesGroup.size() && townsGroup.size())) {
// it looks the loaded map has old default groups
options.burgs.groups = Burgs.getDefaultGroups();
} else {
burgIcons.selectAll("circle, use").each(function () {
const group = this.parentNode.id;
const id = this.id.replace(/^burg/, "");
const burg = pack.burgs[id];
if (group && burg) burg.group = group;
});
burgIcons.selectAll("g").each(function (_el, index) {
const name = this.id;
const isDefault = name === "towns";
options.burgs.groups.push({name, active: true, order: index + 1, isDefault, preview: "watabou-city"});
const size = Number(this.getAttribute("size") || 2) * 2;
this.removeAttribute("size");
this.setAttribute("font-size", size);
this.setAttribute("stroke-width", 1);
});
if (options.burgs.groups.filter(g => g.isDefault).length === 0) {
options.burgs.groups[0].isDefault = true;
}
anchors.selectAll("g").each(function () {
const size = Number(this.getAttribute("size") || 1);
this.removeAttribute("size");
this.setAttribute("font-size", size);
});
}
if (options.burgs.groups.filter(g => g.isDefault).length === 0) {
options.burgs.groups[0].isDefault = true;
}
anchors.selectAll("g").each(function () {
const size = Number(this.getAttribute("size") || 1);
this.removeAttribute("size");
this.setAttribute("font-size", size);
});
pack.burgs.forEach(burg => {
if (!burg.i || burg.removed) return;
const validBurgs = pack.burgs.filter(b => b.i && !b.removed);
const populations = validBurgs.map(b => b.population).sort((a, b) => a - b);
validBurgs.forEach(burg => {
if (!burg.group) Burgs.defineGroup(burg, populations);
if (burg.MFCG) {
burg.link = getBurgLink(burg);