mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-11 13:46:10 +00:00
43 lines
1.1 KiB
JavaScript
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;
|
|
};
|