mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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:
1 parent
85d4f4840c
commit
0584707436
2 files changed
+75
-10
No files matched your search
+12
-10
@@ -2228,7 +2228,8 @@ export function createCesiumDraw({
|
|||||||
extrudedHeight,
|
extrudedHeight,
|
||||||
perPositionHeight: g.perPositionHeight,
|
perPositionHeight: g.perPositionHeight,
|
||||||
}),
|
}),
|
||||||
ring: outer,
|
// Its holes are outlined too, as the entities' polygons outline them.
|
||||||
|
rings: [outer, ...holes],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'ellipse': {
|
case 'ellipse': {
|
||||||
@@ -2662,15 +2663,16 @@ export function createCesiumDraw({
|
|||||||
asynchronous: false,
|
asynchronous: false,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} else if (item.outline && shape.ring)
|
} else if (item.outline && shape.rings)
|
||||||
outlines.add({
|
for (const ring of shape.rings)
|
||||||
positions: [...shape.ring, shape.ring[0]],
|
outlines.add({
|
||||||
width: item.outlineWidth ?? 1,
|
positions: [...ring, ring[0]],
|
||||||
material: Cesium.Material.fromType('Color', {
|
width: item.outlineWidth ?? 1,
|
||||||
color: toColor(item.outline),
|
material: Cesium.Material.fromType('Color', {
|
||||||
}),
|
color: toColor(item.outline),
|
||||||
id,
|
}),
|
||||||
});
|
id,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
host.add(outlines);
|
host.add(outlines);
|
||||||
const ground = groundFills(record, clamped);
|
const ground = groundFills(record, clamped);
|
||||||
|
|||||||
@@ -4774,3 +4774,66 @@ test('a model past its pixel cap is scaled down each frame; fades and culls too'
|
|||||||
restore();
|
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();
|
||||||
|
}));
|
||||||
Reference in new issue
Block a user