Add tag deprecation action and data, not yet integrated.

This commit is contained in:
Tom MacWright
2013-02-04 16:02:34 -05:00
parent ad5c819f49
commit 3449a680a7
6 changed files with 197 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
iD.data = {};
+112
View File
@@ -0,0 +1,112 @@
// from http://wiki.openstreetmap.org/wiki/Deprecated_features
// TODO: deal with deprecated 'class' tag
// does not deal with landuse=wood because of indecision
// we will not care about http://taginfo.openstreetmap.org/tags/bicycle_parking=sheffield
iD.data.deprecated = [
{
old: { barrier: 'wire_fence' },
replace: {
barrier: 'fence',
fence_type: 'chain'
}
},
{
old: { barrier: 'wood_fence' },
replace: {
barrier: 'fence',
fence_type: 'wood'
}
},
{
old: { highway: 'ford' },
replace: {
ford: 'yes'
}
},
{
old: { highway: 'ford' },
replace: {
ford: 'yes'
}
},
{
old: { highway: 'ford' },
replace: {
ford: 'yes'
}
},
{
old: { highway: 'stile' },
replace: {
barrier: 'stile'
}
},
{
old: { highway: 'incline' },
replace: {
highway: 'road',
incline: 'up'
}
},
{
old: { highway: 'incline_steep' },
replace: {
highway: 'road',
incline: 'up'
}
},
{
old: { highway: 'unsurfaced' },
replace: {
highway: 'road',
incline: 'unpaved'
}
},
{
old: { highway: 'unsurfaced' },
replace: {
highway: 'road',
incline: 'unpaved'
}
},
{
old: { landuse: 'wood' },
replace: {
highway: 'road',
incline: 'unpaved'
}
},
{
old: { natural: 'marsh' },
replace: {
natural: 'wetland',
wetland: 'marsh'
}
},
{
old: { shop: 'organic' },
replace: {
shop: 'supermarket',
organic: 'only'
}
},
{
old: { power_source: '*' },
replace: {
'generator:source': '$1'
}
},
{
old: { power_rating: '*' },
replace: {
'generator:output': '$1'
}
},
{
old: { bicycle_parking: 'organic' },
replace: {
shop: 'supermarket',
organic: 'only'
}
}
];
+3
View File
@@ -134,6 +134,9 @@
<script src='locale/locale.js'></script>
<script src='locale/en.js'></script>
<script src='data/data.js'></script>
<script src='data/deprecated.js'></script>
</head>
<body>
<div id="iD"></div><script>
+36
View File
@@ -0,0 +1,36 @@
iD.actions.DeprecateTags = function(entityId) {
return function(graph) {
var entity = graph.entity(entityId),
newtags = _.clone(entity.tags),
change = false,
rule;
// This handles deprecated tags with a single condition
for (var i = 0; i < iD.data.deprecated.length; i++) {
rule = iD.data.deprecated[i];
var match = _.pairs(rule.old)[0],
replacements = _.pairs(rule.replace);
if (entity.tags[match[0]] && match[1] === '*') {
var value = entity.tags[match[0]];
if (!newtags[replacements[0][0]]) {
newtags[replacements[0][0]] = value;
}
delete newtags[match[0]];
change = true;
} else if (entity.tags[match[0]] === match[1]) {
newtags = _.assign({}, rule.replace, _.omit(newtags, match[0]));
change = true;
}
}
if (change) {
return graph.replace(entity.update({tags: newtags}));
} else {
return graph;
}
};
};
+5
View File
@@ -84,6 +84,7 @@
<script src='../js/id/actions/move_way.js'></script>
<script src='../js/id/actions/noop.js'></script>
<script src='../js/id/actions/reverse.js'></script>
<script src='../js/id/actions/deprecate_tags.js'></script>
<script src='../js/id/actions/split.js'></script>
<script src='../js/id/behavior.js'></script>
@@ -130,6 +131,9 @@
<script src='../locale/locale.js'></script>
<script src='../locale/en.js'></script>
<script src='../data/data.js'></script>
<script src='../data/deprecated.js'></script>
<script>
iD.debug = true;
mocha.setup({
@@ -158,6 +162,7 @@
<script src="spec/actions/noop.js"></script>
<script src="spec/actions/reverse.js"></script>
<script src="spec/actions/split.js"></script>
<script src="spec/actions/deprecate_tags.js"></script>
<script src="spec/geo/extent.js"></script>
+40
View File
@@ -0,0 +1,40 @@
describe('iD.actions.DeprecateTags', function () {
it('deprecates tags', function () {
var entity = iD.Entity({ tags: { barrier: 'wire_fence' } }),
graph = iD.actions.DeprecateTags(entity.id)(iD.Graph([entity])),
undeprecated = {
barrier: 'fence',
fence_type: 'chain'
};
expect(graph.entity(entity.id).tags).to.eql(undeprecated);
});
it('does not overwrite explicit tags', function () {
var entity = iD.Entity({ tags: { barrier: 'wire_fence', fence_type: 'foo' } }),
graph = iD.actions.DeprecateTags(entity.id)(iD.Graph([entity])),
undeprecated = {
barrier: 'fence',
fence_type: 'foo'
};
expect(graph.entity(entity.id).tags).to.eql(undeprecated);
});
it('leaves other tags alone', function () {
var entity = iD.Entity({ tags: { highway: 'ford', name: 'Foo' } }),
graph = iD.actions.DeprecateTags(entity.id)(iD.Graph([entity])),
undeprecated = {
ford: 'yes',
name: 'Foo'
};
expect(graph.entity(entity.id).tags).to.eql(undeprecated);
});
it('replaces keys', function () {
var entity = iD.Entity({ tags: { power_rating: '1 billion volts' } }),
graph = iD.actions.DeprecateTags(entity.id)(iD.Graph([entity])),
undeprecated = {
'generator:output': '1 billion volts'
};
expect(graph.entity(entity.id).tags).to.eql(undeprecated);
});
});