Cesium vectorBase: transparent where the style paints no background; cancelled tiles not painted

The provider said it had no alpha channel, so a style with no or a
translucent background drew black there. And its requestImage ignored the
Cesium request, so tiles of a removed layer were still painted once their
source tiles arrived; a cancelled request now aborts the paint.
This commit is contained in:
Sameh Khamis committed 2026-11-11 19:28:13 -08:00
1 parent 09d1133d90
commit 750dab0123
3 files changed
+42 -5

No files matched your search

+2 -1
View File
@@ -352,7 +352,8 @@ leaves the base as it was; a later `setBase`, or disposal, aborts the load and
the overtaken call changes nothing, resolving with `imagery: []` and
`settled: false`), draws it as Web Mercator imagery under the
base's other imagery (`src/render/cesium/vectorBase.js`, 256 px tiles to
level 20), and credits each source's attribution as plain text. The stub
level 20, transparent where the style paints no opaque background; a tile
whose request is cancelled, its layer removed, is not painted), and credits each source's attribution as plain text. The stub
loads the style and paints nothing. The check `globe.base.vector` serves a
style and a tile from data URLs and reads the drawn fill.
+26 -3
View File
@@ -28,13 +28,36 @@ export function vectorBaseProvider(style) {
rectangle: tilingScheme.rectangle,
credit: undefined,
errorEvent: new Cesium.Event(),
hasAlphaChannel: false,
// Where the style paints no opaque background the base below (or the
// globe's own colour) shows through, never black.
hasAlphaChannel: true,
tileDiscardPolicy: undefined,
proxy: undefined,
getTileCredits: () => undefined,
pickFeatures: () => undefined,
requestImage: (x, y, level) =>
paintVectorTile(style, level, x, y, { size: VECTOR_TILE_PX }),
// A tile whose request was cancelled (its layer removed) is not
// painted once its source tiles arrive.
requestImage: (x, y, level, request) =>
paintVectorTile(style, level, x, y, {
size: VECTOR_TILE_PX,
signal: cancelledBy(request),
}),
};
}
/**
* An `AbortSignal`-like view of a Cesium request: aborted once the request
* is cancelled. Undefined without a request.
*/
export function cancelledBy(request) {
if (!request) return undefined;
return {
get aborted() {
return request.cancelled === true;
},
get reason() {
return new DOMException('The tile request was cancelled', 'AbortError');
},
};
}
+14 -1
View File
@@ -16,10 +16,23 @@ test('the vector base is Web Mercator imagery painted from its style', () => {
});
assert.ok(provider.tilingScheme instanceof Cesium.WebMercatorTilingScheme);
assert.equal(provider.tileWidth, VECTOR_TILE_PX);
assert.equal(provider.hasAlphaChannel, false);
// A style with no (or a translucent) background is transparent there.
assert.equal(provider.hasAlphaChannel, true);
assert.equal(typeof provider.requestImage, 'function');
});
test('a tile whose Cesium request was cancelled is not painted', async () => {
const provider = vectorBaseProvider({
layers: [],
sources: {},
tiles: new Map(),
});
await assert.rejects(
provider.requestImage(0, 0, 0, { cancelled: true }),
(error) => error.name === 'AbortError',
);
});
test('a source’s attribution is credited as plain text', () => {
assert.equal(
attributionText(