mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(render): a setBase whose style fails no longer unsettles the earlier call whose base is still drawn: settled follows the call that last changed the base, in the stub and the Cesium port
This commit is contained in:
1 parent
2a1e2d9c0b
commit
a6d5590430
4 files changed
+34
-4
No files matched your search
@@ -364,7 +364,8 @@ What it draws of the style specification:
|
||||
The Cesium port loads the style before the base changes (a style that fails
|
||||
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
|
||||
`settled: false`; a later call whose style fails leaves the earlier call's
|
||||
base drawn, and that call settles), draws it as Web Mercator imagery under the
|
||||
base's other imagery (`src/render/cesium/vectorBase.js`, 256 px tiles to
|
||||
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
|
||||
|
||||
@@ -136,6 +136,8 @@ export function createCesiumGlobe(
|
||||
let photorealGen = 0;
|
||||
let terrainGen = 0;
|
||||
let baseGen = 0;
|
||||
/** The `setBase` call whose base is drawn now (a failed one changes none). */
|
||||
let drawnGen = 0;
|
||||
/** Aborts the style load of the `setBase` in flight, if any. */
|
||||
let baseLoad = null;
|
||||
let baseCredit = null;
|
||||
@@ -273,6 +275,7 @@ export function createCesiumGlobe(
|
||||
}
|
||||
if (!current()) return superseded();
|
||||
}
|
||||
drawnGen = gen;
|
||||
for (const handle of imagery.list()) handle.remove();
|
||||
baseCredit?.();
|
||||
baseCredit = base.credit && credits ? credits.addStatic(base.credit) : null;
|
||||
@@ -296,8 +299,9 @@ export function createCesiumGlobe(
|
||||
return {
|
||||
photoreal: photorealStatus,
|
||||
imagery: layers,
|
||||
// A base a later call replaced has not settled.
|
||||
settled: current() && isSettled('base'),
|
||||
// A base a later call replaced has not settled; one whose later call
|
||||
// failed is still drawn.
|
||||
settled: gen === drawnGen && !disposed && isSettled('base'),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1555,6 +1555,8 @@ export function createStubRenderer(options = {}) {
|
||||
let terrainKey = 'null';
|
||||
// The last `setBase` wins; its style load in flight, if any.
|
||||
let baseGen = 0;
|
||||
/** The `setBase` call whose base is drawn now (a failed one changes none). */
|
||||
let drawnGen = 0;
|
||||
let baseLoad = null;
|
||||
const globe = {
|
||||
async setBase(base) {
|
||||
@@ -1589,6 +1591,7 @@ export function createStubRenderer(options = {}) {
|
||||
}
|
||||
if (!current()) return superseded();
|
||||
}
|
||||
drawnGen = gen;
|
||||
for (const layer of imageryLayers.slice()) layer.remove();
|
||||
// The imagery is added before anything is awaited, so a later call,
|
||||
// which removes it, always finds it.
|
||||
@@ -1599,7 +1602,7 @@ export function createStubRenderer(options = {}) {
|
||||
return {
|
||||
photoreal: photorealStatus,
|
||||
imagery: layers,
|
||||
settled: current(),
|
||||
settled: gen === drawnGen && !destroyed,
|
||||
};
|
||||
},
|
||||
async setPhotoreal(spec) {
|
||||
|
||||
@@ -253,3 +253,25 @@ test('two setBase calls, neither awaited, leave the later one’s imagery alone'
|
||||
assert.equal((await first).settled, false, 'the overtaken one');
|
||||
r.destroy();
|
||||
});
|
||||
|
||||
test('a later setBase whose style fails leaves the earlier one the base, settled', async () => {
|
||||
const original = globalThis.fetch;
|
||||
globalThis.fetch = async () => ({ ok: false, status: 500 });
|
||||
try {
|
||||
const r = createStubRenderer();
|
||||
const first = r.globe.setBase({
|
||||
photoreal: null,
|
||||
imagery: [{ kind: 'xyz', url: 'https://a.invalid/{z}/{x}/{y}.png' }],
|
||||
});
|
||||
const second = r.globe.setBase({
|
||||
vector: { styleUrl: 'https://s.invalid/x' },
|
||||
});
|
||||
await assert.rejects(second);
|
||||
const status = await first;
|
||||
assert.deepEqual(r.globe.imagery.list(), status.imagery);
|
||||
assert.equal(status.settled, true, 'its base is the one drawn');
|
||||
r.destroy();
|
||||
} finally {
|
||||
globalThis.fetch = original;
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user