mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +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
@@ -364,8 +364,10 @@ What it draws of the style specification:
|
|||||||
The Cesium port loads the style before the base changes (a style that fails
|
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
|
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`; a later call whose style fails leaves the earlier call's
|
`settled: false`; `settled` is whether, when the call resolves, its base is
|
||||||
base drawn, and that call settles), draws it as Web Mercator imagery under the
|
still the one drawn and has settled, so an earlier call that resolves while a
|
||||||
|
later call's style is still loading, or after that style fails, is settled,
|
||||||
|
and one that resolves after a later call changed the base is not), 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, transparent where the style paints no opaque background; a tile
|
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
|
whose request is cancelled, its layer removed, is not painted), and credits each source's attribution as plain text. The stub
|
||||||
|
|||||||
@@ -299,8 +299,9 @@ export function createCesiumGlobe(
|
|||||||
return {
|
return {
|
||||||
photoreal: photorealStatus,
|
photoreal: photorealStatus,
|
||||||
imagery: layers,
|
imagery: layers,
|
||||||
// A base a later call replaced has not settled; one whose later call
|
// Settled when its base is still the one drawn: a later call changes
|
||||||
// failed is still drawn.
|
// 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'),
|
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)
|
* The last call wins: one a later `setBase` (or the renderer's disposal)
|
||||||
* overtakes before its base changes (its vector style still loading)
|
* overtakes before its base changes (its vector style still loading)
|
||||||
* changes nothing and resolves with `imagery: []`, `settled: false` and the
|
* changes nothing and resolves with `imagery: []`, `settled: false` and the
|
||||||
* photoreal status as it stands, never rejecting; one overtaken after it
|
* photoreal status as it stands, never rejecting.
|
||||||
* changed the base resolves with `settled: false`.
|
*
|
||||||
|
* `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>;
|
setBase(base: BaseSpec): Promise<BaseStatus>;
|
||||||
/** `photoreal`: on, off or a new token route. */
|
/** `photoreal`: on, off or a new token route. */
|
||||||
|
|||||||
@@ -1598,7 +1598,9 @@ export function createStubRenderer(options = {}) {
|
|||||||
const layers = (base.imagery ?? []).map((spec) => addImagery(spec));
|
const layers = (base.imagery ?? []).map((spec) => addImagery(spec));
|
||||||
if (base.photoreal !== undefined)
|
if (base.photoreal !== undefined)
|
||||||
await globe.setPhotoreal(base.photoreal);
|
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 {
|
return {
|
||||||
photoreal: photorealStatus,
|
photoreal: photorealStatus,
|
||||||
imagery: layers,
|
imagery: layers,
|
||||||
|
|||||||
@@ -275,3 +275,38 @@ test('a later setBase whose style fails leaves the earlier one the base, settled
|
|||||||
globalThis.fetch = original;
|
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