Files
iD/js/id/presetdata.js
Ansis Brammanis 4c0b03c241 forward on preset ui work
Add maki icons
2013-02-16 18:30:47 -05:00

43 lines
1.1 KiB
JavaScript

iD.presetData = function() {
var presets = {},
data = [];
presets.data = function(_) {
if (!arguments.length) return data;
data = _;
return presets;
};
presets.favs = function() {
return data.filter(function(d) {
return d.favorite;
});
};
presets.match = function(entity) {
var type = entity.type == 'node' ? 'node' : entity.geometry();
return data.filter(function(d) {
return _.contains(d.match.type, type);
});
};
presets.matchTags = function(entity) {
var tags, count, best,
maxcount = 0,
type = entity.type == 'node' ? 'node' : entity.geometry();
for (var i = 0; i < data.length; i++) {
count = 0;
tags = data[i].match.tags;
if (!_.contains(data[i].match.type, type)) continue;
for (var k in tags) {
if (entity.tags[k] == tags[k]) count++;
}
if (count > maxcount) best = data[i], maxcount = count;
}
return best;
};
return presets;
};