From f72e29415623fd59a4071d5043b7dd9e44aaa535 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 8 Mar 2013 11:36:57 -0500 Subject: [PATCH] score wildcard matches as half a match so that building=* doesn't get prioritized over more specific one tag presets, like amenity=hospital --- js/id/presets/preset.js | 14 ++++++++++---- test/spec/presets/preset.js | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/js/id/presets/preset.js b/js/id/presets/preset.js index f7cf8ba6c..64f61ab78 100644 --- a/js/id/presets/preset.js +++ b/js/id/presets/preset.js @@ -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) { diff --git a/test/spec/presets/preset.js b/test/spec/presets/preset.js index 0e6b15652..8b7a85761 100644 --- a/test/spec/presets/preset.js +++ b/test/spec/presets/preset.js @@ -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); });