Cesium vectorBase: test that removing the layer aborts its paints

Cesium cancels none of an imagery layer's requests itself; the port's
layer cancels its requests in flight as it is removed, which is what the
provider's cancelled check sees. A test now goes through that path.
This commit is contained in:
Sameh Khamis committed 2026-11-11 20:06:05 -08:00
1 parent 7f500a551c
commit 143f4df049
2 files changed
+41 -2

No files matched your search

+3 -2
View File
@@ -35,8 +35,9 @@ export function vectorBaseProvider(style) {
proxy: undefined,
getTileCredits: () => undefined,
pickFeatures: () => undefined,
// A tile whose request was cancelled (its layer removed) is not
// painted once its source tiles arrive.
// A tile whose request was cancelled is not painted once its source
// tiles arrive. Cesium cancels none of an imagery layer's requests
// itself; the port's layer does as it is removed (`imagery.js`).
requestImage: (x, y, level, request) =>
paintVectorTile(style, level, x, y, {
size: VECTOR_TILE_PX,
+38
View File
@@ -45,3 +45,41 @@ test('a source’s attribution is credited as plain text', () => {
test('a Cesium globe claims vectorBase', () => {
assert.ok(cesiumCapabilities({}).includes('vectorBase'));
});
test('removing a vector base layer cancels the Cesium requests it painted for, aborting the paint', async () => {
const { createCesiumImagery } = await import('./imagery.js');
const scene = { imageryLayers: new Cesium.ImageryLayerCollection() };
const imagery = createCesiumImagery(scene, {
capabilities: new Set(),
requestRender: () => {},
report: (error) => {
throw error;
},
objects: () => null,
});
// A style whose one source tile never arrives: the paint waits on it.
const style = {
layers: [{ type: 'fill', source: 'base', minzoom: 0, maxzoom: 24 }],
sources: {
base: {
tiles: ['https://t.invalid/{z}/{x}/{y}'],
minzoom: 0,
maxzoom: 14,
scheme: 'xyz',
},
},
tiles: new Map(),
};
let release;
style.tiles.set('https://t.invalid/0/0/0', new Promise((r) => (release = r)));
const layer = imagery.add({ kind: 'vectorStyle', style }, undefined, {
base: true,
});
const provider = scene.imageryLayers.get(0).imageryProvider;
const request = new Cesium.Request();
const painted = provider.requestImage(0, 0, 0, request);
layer.remove();
assert.equal(request.cancelled, true, 'the layer cancels its requests');
release(null);
await assert.rejects(painted, (error) => error.name === 'AbortError');
});