Skip to content

Commit

Permalink
Allow fallback presets (area, line, point) to appear in the recent list
Browse files Browse the repository at this point in the history
(closes #4612)
  • Loading branch information
bhousel committed Jan 2, 2018
1 parent 1658ada commit 8928e95
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions modules/presets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export function presetIndex() {
// a presetCollection with methods for
// loading new data and returning defaults

var all = presetCollection([]),
defaults = { area: all, line: all, point: all, vertex: all, relation: all },
fields = {},
universal = [],
recent = presetCollection([]);
var all = presetCollection([]);
var _defaults = { area: all, line: all, point: all, vertex: all, relation: all };
var _fields = {};
var _universal = [];
var _recent = presetCollection([]);

// Index of presets by (geometry, tag key).
var index = {
var _index = {
point: {},
vertex: {},
line: {},
Expand All @@ -43,9 +43,9 @@ export function presetIndex() {
geometry = 'point';
}

var geometryMatches = index[geometry],
best = -1,
match;
var geometryMatches = _index[geometry];
var best = -1;
var match;

for (var k in entity.tags) {
// If any part of an address is present,
Expand Down Expand Up @@ -86,9 +86,9 @@ export function presetIndex() {
// (see `Way#isArea()`). In other words, the keys of L form the whitelist,
// and the subkeys form the blacklist.
all.areaKeys = function() {
var areaKeys = {},
ignore = ['barrier', 'highway', 'footway', 'railway', 'type'], // probably a line..
presets = _reject(all.collection, 'suggestion');
var areaKeys = {};
var ignore = ['barrier', 'highway', 'footway', 'railway', 'type']; // probably a line..
var presets = _reject(all.collection, 'suggestion');

// whitelist
presets.forEach(function(d) {
Expand Down Expand Up @@ -123,21 +123,23 @@ export function presetIndex() {
var d = data.presets;

all.collection = [];
recent.collection = [];
fields = {};
universal = [];
index = { point: {}, vertex: {}, line: {}, area: {}, relation: {} };
_recent.collection = [];
_fields = {};
_universal = [];
_index = { point: {}, vertex: {}, line: {}, area: {}, relation: {} };

if (d.fields) {
_forEach(d.fields, function(d, id) {
fields[id] = presetField(id, d);
if (d.universal) universal.push(fields[id]);
_fields[id] = presetField(id, d);
if (d.universal) {
_universal.push(_fields[id]);
}
});
}

if (d.presets) {
_forEach(d.presets, function(d, id) {
all.collection.push(presetPreset(id, d, fields));
all.collection.push(presetPreset(id, d, _fields));
});
}

Expand All @@ -149,7 +151,7 @@ export function presetIndex() {

if (d.defaults) {
var getItem = _bind(all.item, all);
defaults = {
_defaults = {
area: presetCollection(d.defaults.area.map(getItem)),
line: presetCollection(d.defaults.line.map(getItem)),
point: presetCollection(d.defaults.point.map(getItem)),
Expand All @@ -159,11 +161,11 @@ export function presetIndex() {
}

for (var i = 0; i < all.collection.length; i++) {
var preset = all.collection[i],
geometry = preset.geometry;
var preset = all.collection[i];
var geometry = preset.geometry;

for (var j = 0; j < geometry.length; j++) {
var g = index[geometry[j]];
var g = _index[geometry[j]];
for (var k in preset.tags) {
(g[k] = g[k] || []).push(preset);
}
Expand All @@ -174,23 +176,21 @@ export function presetIndex() {
};

all.field = function(id) {
return fields[id];
return _fields[id];
};

all.universal = function() {
return universal;
return _universal;
};

all.defaults = function(geometry, n) {
var rec = recent.matchGeometry(geometry).collection.slice(0, 4),
def = _uniq(rec.concat(defaults[geometry].collection)).slice(0, n - 1);
var rec = _recent.matchGeometry(geometry).collection.slice(0, 4);
var def = _uniq(rec.concat(_defaults[geometry].collection)).slice(0, n - 1);
return presetCollection(_uniq(rec.concat(def).concat(all.item(geometry))));
};

all.choose = function(preset) {
if (!preset.isFallback()) {
recent = presetCollection(_uniq([preset].concat(recent.collection)));
}
_recent = presetCollection(_uniq([preset].concat(_recent.collection)));
return all;
};

Expand Down

0 comments on commit 8928e95

Please sign in to comment.