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.
This commit is contained in:
Bryan Housel
2021-03-12 12:04:52 -05:00
parent d282140999
commit f95e7db8c9
3 changed files with 16 additions and 10 deletions
+2 -2
View File
@@ -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
+11 -5
View File
@@ -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];
}
+3 -3
View File
@@ -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);
});