mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
score wildcard matches as half a match
so that building=* doesn't get prioritized over more specific one tag presets, like amenity=hospital
This commit is contained in:
+10
-4
@@ -13,12 +13,18 @@ iD.presets.Preset = function(preset, forms) {
|
||||
};
|
||||
|
||||
preset.matchTags = function(entity) {
|
||||
var tags = preset.match.tags;
|
||||
var tags = preset.match.tags,
|
||||
score = 0;
|
||||
for (var t in tags) {
|
||||
if (entity.tags[t] !== tags[t] &&
|
||||
!(tags[t] === '*' && t in entity.tags)) return -1;
|
||||
if (entity.tags[t] === tags[t]) {
|
||||
score ++;
|
||||
} else if (tags[t] === '*' && t in entity.tags) {
|
||||
score += 0.5;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return Object.keys(preset.match.tags).length;
|
||||
return score;
|
||||
};
|
||||
|
||||
preset.removeTags = function(tags, geometry) {
|
||||
|
||||
@@ -103,7 +103,7 @@ describe('iD.presets.Preset', function() {
|
||||
});
|
||||
|
||||
it("counts * as a match for any value", function() {
|
||||
expect(p.building.matchTags(w4)).to.equal(1);
|
||||
expect(p.building.matchTags(w4)).to.equal(0.5);
|
||||
expect(p.building.matchTags(w5)).to.equal(-1);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user