Split "other" preset into geometry specific fallbacks

This way the name and icon can be geometry-specific.
This commit is contained in:
John Firebaugh
2013-05-24 11:14:45 -07:00
parent ab10f8ac38
commit 5868875833
15 changed files with 144 additions and 77 deletions
+15 -6
View File
@@ -370,6 +370,9 @@ en:
amenity/waste_basket:
name: Waste Basket
terms: "rubbish bin,litter bin,trash can,garbage can"
area:
name: Area
terms: ""
barrier:
name: Barrier
terms: ""
@@ -670,6 +673,9 @@ en:
leisure/swimming_pool:
name: Swimming Pool
terms: ""
line:
name: Line
terms: ""
man_made:
name: Man Made
terms: ""
@@ -763,12 +769,6 @@ en:
office:
name: Office
terms: ""
other:
name: Other
terms: ""
other_area:
name: Other
terms: ""
place:
name: Place
terms: ""
@@ -793,6 +793,9 @@ en:
place/village:
name: Village
terms: ""
point:
name: Point
terms: ""
power:
name: Power
terms: ""
@@ -847,6 +850,9 @@ en:
railway/tram:
name: Tram
terms: streetcar
relation:
name: Relation
terms: ""
shop:
name: Shop
terms: ""
@@ -1096,6 +1102,9 @@ en:
type/route/tram:
name: Tram Route
terms: ""
vertex:
name: Other
terms: ""
waterway:
name: Waterway
terms: ""
+4 -4
View File
@@ -8,7 +8,7 @@
"amenity/place_of_worship",
"amenity/cafe",
"amenity/restaurant",
"other_area"
"area"
],
"line": [
"category-road",
@@ -16,7 +16,7 @@
"category-path",
"category-water",
"power/line",
"other"
"line"
],
"point": [
"leisure/park",
@@ -27,7 +27,7 @@
"amenity/bar",
"amenity/bank",
"shop/supermarket",
"other"
"point"
],
"vertex": [
"highway/crossing",
@@ -36,6 +36,6 @@
"highway/turning_circle",
"highway/mini_roundabout",
"highway/motorway_junction",
"other"
"vertex"
]
}
+36 -22
View File
@@ -1035,6 +1035,13 @@
],
"name": "Waste Basket"
},
"area": {
"name": "Area",
"tags": {},
"geometry": [
"area"
]
},
"barrier": {
"geometry": [
"point",
@@ -2511,6 +2518,13 @@
"icon": "swimming",
"name": "Swimming Pool"
},
"line": {
"name": "Line",
"tags": {},
"geometry": [
"line"
]
},
"man_made": {
"fields": [
"man_made"
@@ -2920,28 +2934,6 @@
"terms": [],
"name": "Office"
},
"other": {
"name": "Other",
"tags": {},
"geometry": [
"point",
"vertex",
"line",
"area",
"relation"
],
"fields": []
},
"other_area": {
"name": "Other",
"tags": {
"area": "yes"
},
"geometry": [
"area"
],
"fields": []
},
"place": {
"fields": [
"place"
@@ -3041,6 +3033,13 @@
},
"name": "Village"
},
"point": {
"name": "Point",
"tags": {},
"geometry": [
"point"
]
},
"power": {
"geometry": [
"point",
@@ -3274,6 +3273,14 @@
],
"name": "Tram"
},
"relation": {
"name": "Relation",
"icon": "relation",
"tags": {},
"geometry": [
"relation"
]
},
"shop": {
"icon": "shop",
"fields": [
@@ -4620,6 +4627,13 @@
"name": "Tram Route",
"icon": "route-tram"
},
"vertex": {
"name": "Other",
"tags": {},
"geometry": [
"vertex"
]
},
"waterway": {
"fields": [
"waterway"
+5
View File
@@ -0,0 +1,5 @@
{
"name": "Area",
"tags": {},
"geometry": ["area"]
}
+5
View File
@@ -0,0 +1,5 @@
{
"name": "Line",
"tags": {},
"geometry": ["line"]
}
-6
View File
@@ -1,6 +0,0 @@
{
"name": "Other",
"tags": {},
"geometry": ["point", "vertex", "line", "area", "relation"],
"fields": []
}
-8
View File
@@ -1,8 +0,0 @@
{
"name": "Other",
"tags": {
"area": "yes"
},
"geometry": ["area"],
"fields": []
}
+5
View File
@@ -0,0 +1,5 @@
{
"name": "Point",
"tags": {},
"geometry": ["point"]
}
+6
View File
@@ -0,0 +1,6 @@
{
"name": "Relation",
"icon": "relation",
"tags": {},
"geometry": ["relation"]
}
+5
View File
@@ -0,0 +1,5 @@
{
"name": "Other",
"tags": {},
"geometry": ["vertex"]
}
+20 -8
View File
@@ -871,6 +871,10 @@
"name": "Waste Basket",
"terms": "rubbish bin,litter bin,trash can,garbage can"
},
"area": {
"name": "Area",
"terms": ""
},
"barrier": {
"name": "Barrier",
"terms": ""
@@ -1271,6 +1275,10 @@
"name": "Swimming Pool",
"terms": ""
},
"line": {
"name": "Line",
"terms": ""
},
"man_made": {
"name": "Man Made",
"terms": ""
@@ -1395,14 +1403,6 @@
"name": "Office",
"terms": ""
},
"other": {
"name": "Other",
"terms": ""
},
"other_area": {
"name": "Other",
"terms": ""
},
"place": {
"name": "Place",
"terms": ""
@@ -1435,6 +1435,10 @@
"name": "Village",
"terms": ""
},
"point": {
"name": "Point",
"terms": ""
},
"power": {
"name": "Power",
"terms": ""
@@ -1507,6 +1511,10 @@
"name": "Tram",
"terms": "streetcar"
},
"relation": {
"name": "Relation",
"terms": ""
},
"shop": {
"name": "Shop",
"terms": ""
@@ -1839,6 +1847,10 @@
"name": "Tram Route",
"terms": ""
},
"vertex": {
"name": "Other",
"terms": ""
},
"waterway": {
"name": "Waterway",
"terms": ""
+13 -9
View File
@@ -5,11 +5,10 @@ iD.presets = function() {
var all = iD.presets.Collection([]),
defaults = { area: all, line: all, point: all, vertex: all },
fallbacks = {},
fields = {},
universal = [],
recent = iD.presets.Collection([]),
other,
other_area;
recent = iD.presets.Collection([]);
// Index of presets by (geometry, tag key).
var index = {
@@ -24,7 +23,7 @@ iD.presets = function() {
var geometry = entity.geometry(resolver),
geometryMatches = index[geometry],
best = -1,
match = geometry === 'area' ? other_area : other;
match;
for (var k in entity.tags) {
var keyMatches = geometryMatches[k];
@@ -39,7 +38,7 @@ iD.presets = function() {
}
}
return match;
return match || fallbacks[geometry];
};
all.load = function(d) {
@@ -73,8 +72,13 @@ iD.presets = function() {
};
}
other = all.item('other');
other_area = all.item('other_area');
fallbacks = {
point: all.item('point'),
vertex: all.item('vertex'),
line: all.item('line'),
area: all.item('area'),
relation: all.item('relation')
};
for (var i = 0; i < all.collection.length; i++) {
var preset = all.collection[i],
@@ -102,11 +106,11 @@ iD.presets = function() {
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);
return iD.presets.Collection(_.unique(rec.concat(def).concat(geometry === 'area' ? other_area : other)));
return iD.presets.Collection(_.unique(rec.concat(def).concat(fallbacks[geometry])));
};
all.choose = function(preset) {
if (preset !== other && preset !== other_area) {
if (!preset.isFallback()) {
recent = iD.presets.Collection(_.unique([preset].concat(recent.collection)));
}
return all;
+4
View File
@@ -45,6 +45,10 @@ iD.presets.Preset = function(id, preset, fields) {
return preset.t('terms', {'default': ''}).split(',');
};
preset.isFallback = function() {
return Object.keys(preset.tags).length === 0;
};
preset.reference = function() {
var reference = {key: Object.keys(preset.tags)[0]};
+12 -6
View File
@@ -1,8 +1,12 @@
describe("iD.presets", function() {
var p = {
other: {
point: {
tags: {},
geometry: ['point', 'vertex', 'line', 'area']
geometry: ['point']
},
line: {
tags: {},
geometry: ['line']
},
residential: {
tags: {
@@ -29,10 +33,12 @@ describe("iD.presets", function() {
expect(c.match(way, graph).id).to.eql('residential');
});
it("returns an other preset when no tags match", function() {
var way = iD.Way({tags: {foo: 'bar'}}),
graph = iD.Graph([way]);
expect(c.match(way, graph).id).to.eql('other');
it("returns the appropriate fallback preset when no tags match", function() {
var point = iD.Node(),
line = iD.Way({tags: {foo: 'bar'}}),
graph = iD.Graph([point, line]);
expect(c.match(point, graph).id).to.eql('point');
expect(c.match(line, graph).id).to.eql('line');
});
});
});
+14 -8
View File
@@ -34,7 +34,7 @@ describe('iD.presets.Preset', function() {
it("has optional fields", function() {
expect(p.other.fields).to.eql([]);
expect(p.point.fields).to.eql([]);
});
describe('#matchGeometry', function() {
@@ -46,17 +46,17 @@ describe('iD.presets.Preset', function() {
});
it("returns true if it does match", function() {
expect(p.other.matchGeometry('point')).to.equal(true);
expect(p.point.matchGeometry('point')).to.equal(true);
});
});
describe('#matchScore', function() {
it("returns -1 if preset does not match tags", function() {
it("returns -1 if preset does not match tags", function() {
expect(p['highway/residential'].matchScore(w1)).to.equal(-1);
});
it("returns 0 for other preset (no match tags)", function() {
expect(p.other.matchScore(w1)).to.equal(0);
it("returns 0 for fallback presets", function() {
expect(p.point.matchScore(w1)).to.equal(0);
});
it("returns the number of matched tags", function() {
@@ -68,11 +68,19 @@ describe('iD.presets.Preset', function() {
expect(p.building.matchScore(w4)).to.equal(0.5);
expect(p.building.matchScore(w5)).to.equal(-1);
});
});
describe("isFallback", function() {
it("returns true if preset has no tags", function() {
expect(iD.presets.Preset("area", {name: "Area", tags: {}}).isFallback()).to.equal(true);
});
it("returns false if preset has no tags", function() {
expect(p.building.isFallback()).to.equal(false);
});
});
describe('#applyTags', function() {
it("adds match tags", function() {
expect(p['highway/residential'].applyTags({}, 'area')).to.eql({ highway: 'residential' });
});
@@ -88,7 +96,6 @@ describe('iD.presets.Preset', function() {
});
describe('#removeTags', function() {
it('removes match tags', function() {
expect(p['highway/residential'].removeTags({ highway: 'residential' }, 'area')).to.eql({});
});
@@ -98,5 +105,4 @@ describe('iD.presets.Preset', function() {
expect(p['amenity/cafe'].removeTags({ amenity: 'cafe', building: 'yep'}, 'area')).to.eql({ building: 'yep'});
});
});
});