From f95e7db8c99d4032891358cf906c0aadf256cd9f Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Fri, 12 Mar 2021 12:04:52 -0500 Subject: [PATCH] Create the categories like the presets The lack of locationSet was causing them to not show up, which indirectly broke the tutorial at the step where user needs to pick the road category. --- modules/presets/category.js | 4 ++-- modules/presets/index.js | 16 +++++++++++----- test/spec/presets/category.js | 6 +++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/modules/presets/category.js b/modules/presets/category.js index 1a99faaa9..5a9ee0945 100644 --- a/modules/presets/category.js +++ b/modules/presets/category.js @@ -6,7 +6,7 @@ import { presetCollection } from './collection'; // `presetCategory` builds a `presetCollection` of member presets, // decorated with some extra methods for searching and matching geometry // -export function presetCategory(categoryID, category, all) { +export function presetCategory(categoryID, category, allPresets) { let _this = Object.assign({}, category); // shallow copy let _searchName; // cache let _searchNameStripped; // cache @@ -14,7 +14,7 @@ export function presetCategory(categoryID, category, all) { _this.id = categoryID; _this.members = presetCollection( - category.members.map(presetID => all.item(presetID)).filter(Boolean) + (category.members || []).map(presetID => allPresets[presetID]).filter(Boolean) ); _this.geometry = _this.members.collection diff --git a/modules/presets/index.js b/modules/presets/index.js index cbbf2d74d..a2d0e3662 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -136,15 +136,21 @@ export function presetIndex() { }); } - // Need to rebuild _this.collection before loading categories - _this.collection = Object.values(_presets).concat(Object.values(_categories)); - // Merge Categories if (d.categories) { Object.keys(d.categories).forEach(categoryID => { - const c = d.categories[categoryID]; + let c = d.categories[categoryID]; + if (c) { // add or replace - _categories[categoryID] = presetCategory(categoryID, c, _this); + c = presetCategory(categoryID, c, _presets); + if (c.locationSet) { + newLocationSets.push(c); + } else { + c.locationSet = { include: ['Q2'] }; // default worldwide + c.locationSetID = '+[Q2]'; + } + _categories[categoryID] = c; + } else { // remove delete _categories[categoryID]; } diff --git a/test/spec/presets/category.js b/test/spec/presets/category.js index aea5ca898..7cd4fc130 100644 --- a/test/spec/presets/category.js +++ b/test/spec/presets/category.js @@ -9,17 +9,17 @@ describe('iD.presetCategory', function() { var residential = iD.presetPreset('highway/residential', { tags: { highway: 'residential' }, geometry: ['line'] } ); - var all = iD.presetCollection([residential]); + var allPresets = { 'highway/residential': residential }; it('maps members names to preset instances', function() { - var c = iD.presetCategory('road', category, all); + var c = iD.presetCategory('road', category, allPresets); expect(c.members.collection[0]).to.eql(residential); }); describe('#matchGeometry', function() { it('matches the type of an entity', function() { - var c = iD.presetCategory('road', category, all); + var c = iD.presetCategory('road', category, allPresets); expect(c.matchGeometry('line')).to.eql(true); expect(c.matchGeometry('point')).to.eql(false); });