mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
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:
@@ -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
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user