From fb8b969c3f55c164c14dcd3fb4fb76a437a86d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ky=E2=84=93e=20Hensel?= Date: Wed, 15 Jan 2025 21:35:18 +1100 Subject: [PATCH] fix non-integer `layer` tag causing invisible features (#9933) --- modules/svg/lines.js | 2 +- test/spec/svg/lines.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/svg/lines.js b/modules/svg/lines.js index e960087f2..42e3a80cd 100644 --- a/modules/svg/lines.js +++ b/modules/svg/lines.js @@ -247,7 +247,7 @@ export function svgLines(projection, context) { } ways = ways.filter(getPath); - var pathdata = utilArrayGroupBy(ways, function(way) { return way.layer(); }); + const pathdata = utilArrayGroupBy(ways, (way) => Math.trunc(way.layer())); Object.keys(pathdata).forEach(function(k) { var v = pathdata[k]; diff --git a/test/spec/svg/lines.js b/test/spec/svg/lines.js index 9cff4aa5f..5c11342c1 100644 --- a/test/spec/svg/lines.js +++ b/test/spec/svg/lines.js @@ -111,6 +111,20 @@ describe('iD.svgLines', function () { }); }); + it('rounds layers down to the nearest whole number for rendering', () => { + const graph = iD.coreGraph([ + iD.osmNode({id: 'a', loc: [0, 0]}), + iD.osmNode({id: 'b', loc: [1, 1]}), + iD.osmWay({id: 'w1', tags: {highway: 'residential', layer: '-2.5'}, nodes: ['a', 'b']}), + ]); + surface.call(iD.svgLines(projection, context), graph, [graph.entity('w1')], none); + + const layerGroup = surface.select('path.w1').nodes()[0].parentNode.parentNode; + + // the feature with layer=-2.5 was rendered in layer -2 + expect(layerGroup.className.baseVal).to.eql('layergroup layer-2'); + }); + describe('oneway-markers', function() { it('has marker layer for oneway ways', function() { // use 1e-2 to make sure segments are long enough to get