mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-12 16:52:50 +00:00
preserve step_count/… while joining ways (#10926)
* preserve the sum of certain tags (`step_count`, `parking:*:capacity`) during _join_ operation * preserve total value of `parking:*:capacity` tags during _split_ operation by distributing it proportionally to the resulting ways * the abstract osm entity now accepts a list of tags to override during the merging, but otherwise is agnostic about how tags can be merged: the concrete merging resolution might depend on the concrete action that was performed
This commit is contained in:
@@ -598,6 +598,19 @@ describe('iD.actionJoin', function () {
|
||||
expect(graph.entity('-').tags).to.eql({ natural: 'cliff' });
|
||||
});
|
||||
|
||||
it('merges the number of steps', function () {
|
||||
let graph = iD.coreGraph([
|
||||
iD.osmNode({ id: 'a', loc: [0, 0] }),
|
||||
iD.osmNode({ id: 'b', loc: [1, 0] }),
|
||||
iD.osmNode({ id: 'c', loc: [4, 0] }),
|
||||
iD.osmWay({ id: '-', nodes: ['a', 'b'], tags: { highway: 'steps', step_count: '12' } }),
|
||||
iD.osmWay({ id: '=', nodes: ['b', 'c'], tags: { highway: 'steps', step_count: '30' } })
|
||||
]);
|
||||
graph = iD.actionJoin(['-', '='])(graph);
|
||||
// step count should be merged
|
||||
expect(graph.entity('-').tags.step_count).to.equal('42');
|
||||
});
|
||||
|
||||
|
||||
it('merges relations', function () {
|
||||
var graph = iD.coreGraph([
|
||||
|
||||
@@ -531,6 +531,40 @@ describe('iD.actionSplit', function () {
|
||||
expect(g1.entity('-').nodes).to.eql(['b', 'c', 'd', 'a']);
|
||||
expect(g1.entity('=').nodes).to.eql(['a', 'b']);
|
||||
});
|
||||
|
||||
it('distributes the number of steps proportionally', () => {
|
||||
const tags = { highway: 'steps', step_count: '40' };
|
||||
let graph = iD.coreGraph([
|
||||
iD.osmNode({ id: 'a', loc: [0, 0] }),
|
||||
iD.osmNode({ id: 'b', loc: [1, 0] }),
|
||||
iD.osmNode({ id: 'c', loc: [4, 0] }),
|
||||
iD.osmWay({ id: '-', nodes: ['a', 'b', 'c'], tags: tags })
|
||||
]);
|
||||
|
||||
graph = iD.actionSplit('b', ['='])(graph);
|
||||
|
||||
// step count should be distributed according the the resulting ways'
|
||||
// segment lengths
|
||||
expect(graph.entity('=').tags.step_count).to.equal('10');
|
||||
expect(graph.entity('-').tags.step_count).to.equal('30');
|
||||
});
|
||||
|
||||
it('preserves the total number of steps', () => {
|
||||
const tags = { highway: 'steps', step_count: '42' };
|
||||
let graph = iD.coreGraph([
|
||||
iD.osmNode({ id: 'a', loc: [0, 0] }),
|
||||
iD.osmNode({ id: 'b', loc: [1, 0] }),
|
||||
iD.osmNode({ id: 'c', loc: [4, 0] }),
|
||||
iD.osmWay({ id: '-', nodes: ['a', 'b', 'c'], tags: tags })
|
||||
]);
|
||||
|
||||
graph = iD.actionSplit('b', ['='])(graph);
|
||||
|
||||
// the sum of the resulting step count should be preserved
|
||||
// even when the intermediate values are rounded
|
||||
expect(+graph.entity('=').tags.step_count +
|
||||
+graph.entity('-').tags.step_count).to.equal(42);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -168,6 +168,15 @@ describe('iD.osmEntity', function () {
|
||||
expect(a.mergeTags(b.tags).tags).to.eql({a: 'a;b'});
|
||||
expect(b.mergeTags(a.tags).tags).to.eql({a: 'b;a'});
|
||||
});
|
||||
|
||||
it('accepts override tags', function () {
|
||||
const a = iD.osmEntity({tags: {a: 'a', c: '1'}});
|
||||
const b = iD.osmEntity({tags: {b: 'b', c: '2'}});
|
||||
|
||||
const merged = a.mergeTags(b.tags, { c: '3' });
|
||||
|
||||
expect(merged.tags.c).to.eql('3');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#osmId', function () {
|
||||
|
||||
Reference in New Issue
Block a user