From 0584707436550ce7d6a9fc4df3744acf9aa0ebd0 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 7 Nov 2026 22:28:25 -0800 Subject: [PATCH] Outline a raised polygon's holes as well as its outer ring The Cesium draw port drew an unclamped polygon's outline as one closed polyline around its outer ring. Each ring now gets its own, with the same width, colour and pick id, as the entity polygons the GeoJSON loader made outlined their holes. The local GeoJSON layers and submarine cables draw their raised polygons this way. --- src/render/cesium/draw.js | 22 ++++++------ src/render/cesium/draw.test.mjs | 63 +++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 10 deletions(-) diff --git a/src/render/cesium/draw.js b/src/render/cesium/draw.js index 53fb008dd..2a23938f2 100644 --- a/src/render/cesium/draw.js +++ b/src/render/cesium/draw.js @@ -2228,7 +2228,8 @@ export function createCesiumDraw({ extrudedHeight, perPositionHeight: g.perPositionHeight, }), - ring: outer, + // Its holes are outlined too, as the entities' polygons outline them. + rings: [outer, ...holes], }; } case 'ellipse': { @@ -2662,15 +2663,16 @@ export function createCesiumDraw({ asynchronous: false, }), ); - } else if (item.outline && shape.ring) - outlines.add({ - positions: [...shape.ring, shape.ring[0]], - width: item.outlineWidth ?? 1, - material: Cesium.Material.fromType('Color', { - color: toColor(item.outline), - }), - id, - }); + } else if (item.outline && shape.rings) + for (const ring of shape.rings) + outlines.add({ + positions: [...ring, ring[0]], + width: item.outlineWidth ?? 1, + material: Cesium.Material.fromType('Color', { + color: toColor(item.outline), + }), + id, + }); } host.add(outlines); const ground = groundFills(record, clamped); diff --git a/src/render/cesium/draw.test.mjs b/src/render/cesium/draw.test.mjs index 6f6919fcd..d547928e1 100644 --- a/src/render/cesium/draw.test.mjs +++ b/src/render/cesium/draw.test.mjs @@ -4774,3 +4774,66 @@ test('a model past its pixel cap is scaled down each frame; fades and culls too' restore(); } }); + +test('a raised polygon outlines its holes as well as its outer ring', () => + withImageClasses(() => { + const { scene, draw } = drawOver(); + const set = draw.shapes({ id: 'raised-holes' }); + const at = ([lon, lat]) => ({ lon, lat, height: 100 }); + const outer = [ + [0, 0], + [0.01, 0], + [0.01, 0.01], + [0, 0.01], + ].map(at); + // A triangle, so its line has a length of its own. + const hole = [ + [0.004, 0.004], + [0.006, 0.004], + [0.005, 0.006], + ].map(at); + set.set([ + { + id: 'p', + geometry: { + kind: 'polygon', + rings: [outer, hole], + perPositionHeight: true, + }, + fill: [0, 0.5, 1, 0.3], + outline: [0, 0.5, 1, 1], + outlineWidth: 1, + height: 'absolute', + }, + ]); + const host = scene.added[0]; + let outlines = null; + for (let i = 0; i < host.length; i++) + if (host.get(i) instanceof Cesium.PolylineCollection) + outlines = host.get(i); + assert.ok(outlines, 'outlined'); + assert.equal(outlines.length, 2, 'the outer ring and the hole'); + for (const [i, ring] of [outer, hole].entries()) { + const line = outlines.get(i); + assert.equal(line.positions.length, ring.length + 1, 'closed'); + const start = Cesium.Cartesian3.fromDegrees( + ring[0].lon, + ring[0].lat, + ring[0].height, + ); + assert.ok( + Cesium.Cartesian3.equalsEpsilon(line.positions[0], start, 0, 1e-6), + `line ${i} runs along its ring`, + ); + assert.equal(line.width, 1); + assert.ok( + Cesium.Color.equals( + line.material.uniforms.color, + new Cesium.Color(0, 0.5, 1, 1), + ), + ); + assert.equal(line.id.set, 'raised-holes'); + assert.equal(line.id.id, 'p', 'picks as the polygon'); + } + set.dispose(); + }));