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.
This commit is contained in:
Sameh Khamis committed 2026-11-07 23:47:04 -08:00
1 parent 85d4f4840c
commit 0584707436
2 files changed
+75 -10

No files matched your search

+12 -10
View File
@@ -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);
+63
View File
@@ -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();
}));