mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
render: setBase's settled is stated for overlapping calls: whether, when the call resolves, its base is still the one drawn and has settled; an earlier call resolving while a later style loads, or after it fails, is settled, and one resolving after a later call changed the base is not
This commit is contained in:
1 parent
74e4ebcf65
commit
dbe026b109
5 files changed
+58
-7
No files matched your search
@@ -299,8 +299,9 @@ export function createCesiumGlobe(
|
||||
return {
|
||||
photoreal: photorealStatus,
|
||||
imagery: layers,
|
||||
// A base a later call replaced has not settled; one whose later call
|
||||
// failed is still drawn.
|
||||
// Settled when its base is still the one drawn: a later call changes
|
||||
// the base only once its style loads, and one whose style fails never
|
||||
// does (see the contract's setBase).
|
||||
settled: gen === drawnGen && !disposed && isSettled('base'),
|
||||
};
|
||||
}
|
||||
|
||||
Vendored
+13
-2
@@ -242,8 +242,19 @@ export interface GlobePort {
|
||||
* The last call wins: one a later `setBase` (or the renderer's disposal)
|
||||
* overtakes before its base changes (its vector style still loading)
|
||||
* changes nothing and resolves with `imagery: []`, `settled: false` and the
|
||||
* photoreal status as it stands, never rejecting; one overtaken after it
|
||||
* changed the base resolves with `settled: false`.
|
||||
* photoreal status as it stands, never rejecting.
|
||||
*
|
||||
* `settled` describes the moment the call resolves: true when its base is
|
||||
* still the one drawn (no later call has changed the base since) and has
|
||||
* settled. A later call only changes the base once its style has loaded,
|
||||
* so for a call A overtaken by a call B:
|
||||
* - A resolves before B changes the base (B's style still loading): A's
|
||||
* base is the one drawn, so `settled: true`; B then replaces it and
|
||||
* answers for itself.
|
||||
* - B changes the base before A resolves: `settled: false`.
|
||||
* - B's style fails (B rejects): the base stays A's, so A resolves with
|
||||
* `settled: true` whenever it resolves.
|
||||
* Only the latest call's answer says what is drawn once every call is done.
|
||||
*/
|
||||
setBase(base: BaseSpec): Promise<BaseStatus>;
|
||||
/** `photoreal`: on, off or a new token route. */
|
||||
|
||||
@@ -1598,7 +1598,9 @@ export function createStubRenderer(options = {}) {
|
||||
const layers = (base.imagery ?? []).map((spec) => addImagery(spec));
|
||||
if (base.photoreal !== undefined)
|
||||
await globe.setPhotoreal(base.photoreal);
|
||||
// A base a later call replaced has not settled.
|
||||
// Settled when its base is still the one drawn: a later call changes
|
||||
// the base only once its style loads, and one whose style fails never
|
||||
// does (see the contract's setBase).
|
||||
return {
|
||||
photoreal: photorealStatus,
|
||||
imagery: layers,
|
||||
|
||||
@@ -275,3 +275,38 @@ test('a later setBase whose style fails leaves the earlier one the base, settled
|
||||
globalThis.fetch = original;
|
||||
}
|
||||
});
|
||||
|
||||
test('a setBase that ends while a later one’s style still loads is settled; the later one then replaces it', async () => {
|
||||
const held = [];
|
||||
const original = globalThis.fetch;
|
||||
globalThis.fetch = () =>
|
||||
new Promise((resolve) => {
|
||||
held.push(() =>
|
||||
resolve({
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({ version: 8, sources: {}, layers: [] }),
|
||||
}),
|
||||
);
|
||||
});
|
||||
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' },
|
||||
});
|
||||
const status = await first;
|
||||
assert.equal(status.settled, true, 'its base is still the one drawn');
|
||||
assert.deepEqual(r.globe.imagery.list(), status.imagery);
|
||||
held[0]();
|
||||
const later = await second;
|
||||
assert.equal(later.settled, true);
|
||||
assert.deepEqual(r.globe.imagery.list(), later.imagery);
|
||||
r.destroy();
|
||||
} finally {
|
||||
globalThis.fetch = original;
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user