From 147af196268ad8c8498d36959bbc7e859db76310 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 5 Feb 2020 12:21:33 -0500 Subject: [PATCH] Seed presetIndex collection with fallback presets - amazingly, this passes all tests, but iD ends up pretty non-functional --- modules/presets/index.js | 64 ++++++++++++++++++++------------------- test/spec/spec_helpers.js | 32 +++++--------------- 2 files changed, 40 insertions(+), 56 deletions(-) diff --git a/modules/presets/index.js b/modules/presets/index.js index 519439f06..f8a0ed6b8 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -1,7 +1,6 @@ import { dispatch as d3_dispatch } from 'd3-dispatch'; -import { json as d3_json } from 'd3-fetch'; +// import { json as d3_json } from 'd3-fetch'; -import { data } from '../../data/index'; import { osmNodeGeometriesForTags } from '../osm/tags'; import { presetCategory } from './category'; import { presetCollection } from './collection'; @@ -24,13 +23,21 @@ export function presetIndex(context) { const MAXRECENTS = 30; let _presetData; - let _this = presetCollection([]); // collection of all presets + // seed the preset lists with geometry fallbacks + const POINT = presetPreset('point', { name: 'Point', tags: {}, geometry: ['point'], matchScore: 0.1 } ); + const VERTEX = presetPreset('vertex', { name: 'Point', tags: {}, geometry: ['vertex'], matchScore: 0.1 } ); + const LINE = presetPreset('line', { name: 'Line', tags: {}, geometry: ['line'], matchScore: 0.1 } ); + const AREA = presetPreset('area', { name: 'Area', tags: { area: 'yes' }, geometry: ['area'], matchScore: 0.1 } ); + const RELATION = presetPreset('relation', { name: 'Relation', tags: {}, geometry: ['relation'], matchScore: 0.1 } ); + const FALLBACKS = [POINT, VERTEX, LINE, AREA, RELATION]; + + let _this = presetCollection(FALLBACKS); let _defaults = { - point: presetCollection([]), - vertex: presetCollection([]), - line: presetCollection([]), - area: presetCollection([]), - relation: presetCollection([]) + point: presetCollection([POINT]), + vertex: presetCollection([VERTEX]), + line: presetCollection([LINE]), + area: presetCollection([AREA]), + relation: presetCollection([RELATION]) }; let _fields = {}; @@ -39,7 +46,7 @@ export function presetIndex(context) { // let _addablePresetIDs; // presets that the user can add // Index of presets by (geometry, tag key). - let _index = { point: {}, vertex: {}, line: {}, area: {}, relation: {} }; + let _geometryIndex = { point: {}, vertex: {}, line: {}, area: {}, relation: {} }; function ensurePresetData() { @@ -66,11 +73,6 @@ export function presetIndex(context) { // _this.init = (addablePresetIDs) => { _this.init = () => { // _addablePresetIDs = addablePresetIDs; - _this.collection = []; - _recents = null; - _fields = {}; - _universal = []; - _index = { point: {}, vertex: {}, line: {}, area: {}, relation: {} }; // let addable = true; // if (addablePresetIDs) { @@ -83,23 +85,23 @@ export function presetIndex(context) { }; - _this.reset = () => { - _defaults = { - point: presetCollection([]), - vertex: presetCollection([]), - line: presetCollection([]), - area: presetCollection([]), - relation: presetCollection([]) - }; + // _this.reset = () => { + // _defaults = { + // point: presetCollection([]), + // vertex: presetCollection([]), + // line: presetCollection([]), + // area: presetCollection([]), + // relation: presetCollection([]) + // }; - _this.collection = []; - _recents = null; - _fields = {}; - _universal = []; - _index = { point: {}, vertex: {}, line: {}, area: {}, relation: {} }; + // _this.collection = []; + // _recents = null; + // _fields = {}; + // _universal = []; + // _geometryIndex = { point: {}, vertex: {}, line: {}, area: {}, relation: {} }; - return _this; - }; + // return _this; + // }; // _this.fromExternal = (external, done) => { @@ -176,7 +178,7 @@ export function presetIndex(context) { const geometry = preset.geometry; for (let j = 0; j < geometry.length; j++) { - let g = _index[geometry[j]]; + let g = _geometryIndex[geometry[j]]; for (let k in preset.tags) { (g[k] = g[k] || []).push(preset); } @@ -199,7 +201,7 @@ export function presetIndex(context) { _this.matchTags = (tags, geometry) => { - const geometryMatches = _index[geometry]; + const geometryMatches = _geometryIndex[geometry]; let address; let best = -1; let match; diff --git a/test/spec/spec_helpers.js b/test/spec/spec_helpers.js index c658c21e2..7ca995b75 100644 --- a/test/spec/spec_helpers.js +++ b/test/spec/spec_helpers.js @@ -2,37 +2,19 @@ /* eslint no-extend-native:off */ iD.debug = true; -// disable things that use the network -iD.data.imagery = []; +// Disable things that use the network for (var k in iD.services) { delete iD.services[k]; } -// run with a minimal set of presets for speed -// iD.data.presets = { -// presets: { -// area: { name: 'Area', tags: {}, geometry: ['area'] }, -// line: { name: 'Line', tags: {}, geometry: ['line'] }, -// point: { name: 'Point', tags: {}, geometry: ['point'] }, -// vertex: { name: 'Vertex', tags: {}, geometry: ['vertex'] }, -// relation: { name: 'Relation', tags: {}, geometry: ['relation'] }, -// // for tests related to areaKeys: -// building: { name: 'Building', tags: { building: 'yes' }, geometry: ['point', 'area'] }, -// man_made: { name: 'Man Made', tags: { man_made: '*' }, geometry: ['vertex', 'point', 'line', 'area'] } -// } -// }; +// Run without data for speed (tests which need data can set it up themselves) +// Initializing `coreContext` initializes `_background`, which tries loading: +iD.data.imagery = []; +// Initializing `coreContext` initializes `_presets`, which tries loading: iD.data.preset_categories = {}; iD.data.preset_defaults = {}; iD.data.preset_fields = {}; -iD.data.preset_presets = { - area: { name: 'Area', tags: {}, geometry: ['area'] }, - line: { name: 'Line', tags: {}, geometry: ['line'] }, - point: { name: 'Point', tags: {}, geometry: ['point'] }, - vertex: { name: 'Vertex', tags: {}, geometry: ['vertex'] }, - relation: { name: 'Relation', tags: {}, geometry: ['relation'] } -}; - - -// creating `coreContext` creates validators and some of the validators try loading these +iD.data.preset_presets = {}; +// Initializing `coreContext` initializes `_validator`, which tries loading: iD.data.deprecated = []; iD.data.nsi_brands = []; iD.data.nsi_filters = { discardNames: [] };