mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
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:
1 parent
09d1133d90
commit
750dab0123
3 files changed
+42
-5
No files matched your search
@@ -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
|
the overtaken call changes nothing, resolving with `imagery: []` and
|
||||||
`settled: false`), draws it as Web Mercator imagery under the
|
`settled: false`), draws it as Web Mercator imagery under the
|
||||||
base's other imagery (`src/render/cesium/vectorBase.js`, 256 px tiles to
|
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
|
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.
|
style and a tile from data URLs and reads the drawn fill.
|
||||||
|
|
||||||
|
|||||||
@@ -28,13 +28,36 @@ export function vectorBaseProvider(style) {
|
|||||||
rectangle: tilingScheme.rectangle,
|
rectangle: tilingScheme.rectangle,
|
||||||
credit: undefined,
|
credit: undefined,
|
||||||
errorEvent: new Cesium.Event(),
|
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,
|
tileDiscardPolicy: undefined,
|
||||||
proxy: undefined,
|
proxy: undefined,
|
||||||
getTileCredits: () => undefined,
|
getTileCredits: () => undefined,
|
||||||
pickFeatures: () => undefined,
|
pickFeatures: () => undefined,
|
||||||
requestImage: (x, y, level) =>
|
// A tile whose request was cancelled (its layer removed) is not
|
||||||
paintVectorTile(style, level, x, y, { size: VECTOR_TILE_PX }),
|
// 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');
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,23 @@ test('the vector base is Web Mercator imagery painted from its style', () => {
|
|||||||
});
|
});
|
||||||
assert.ok(provider.tilingScheme instanceof Cesium.WebMercatorTilingScheme);
|
assert.ok(provider.tilingScheme instanceof Cesium.WebMercatorTilingScheme);
|
||||||
assert.equal(provider.tileWidth, VECTOR_TILE_PX);
|
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');
|
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', () => {
|
test('a source’s attribution is credited as plain text', () => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
attributionText(
|
attributionText(
|
||||||
|
|||||||
Reference in new issue
Block a user