Upgrade shared Cesium adapter to 1.147 with cache contract checks
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nodedc/map-cesium-react",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"description": "Shared credential-free Cesium adapter for NODE.DC Map Page consumers.",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
@@ -21,7 +21,7 @@
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"cesium": "1.143.0"
|
||||
"cesium": "1.147.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type * as Cesium from "cesium";
|
||||
export const MAP_RUNTIME_SCHEMA_VERSION = "missioncore.map-runtime/v1" as const;
|
||||
export const MAP_PAGE_VERSION = "0.1.0" as const;
|
||||
export const CESIUM_RENDERER_VERSION = "1.143.0" as const;
|
||||
export const CESIUM_RENDERER_VERSION = "1.147.0" as const;
|
||||
|
||||
export type MapProviderId = "imagery" | "terrain" | "buildings";
|
||||
export type MapProviderPhase = "idle" | "loading" | "ready" | "disabled" | "error";
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { DefaultProxy, Resource, VERSION } from "cesium";
|
||||
import { CESIUM_RENDERER_VERSION } from "../dist/contracts.js";
|
||||
import { applyCacheIntent, fetchMapRuntimeConfiguration } from "../dist/runtime.js";
|
||||
|
||||
test("installed Cesium and the runtime contract agree", () => {
|
||||
assert.equal(VERSION, CESIUM_RENDERER_VERSION);
|
||||
});
|
||||
|
||||
test("Cesium derived terrain and building resources retain the existing cache route", () => {
|
||||
for (const [root, child] of [
|
||||
["https://assets.ion.cesium.com/1/", "12/124/113.terrain?v=1"],
|
||||
["https://assets.ion.cesium.com/96188/tileset.json", "12/124/113.b3dm"],
|
||||
]) {
|
||||
const resource = new Resource({
|
||||
url: applyCacheIntent(root, { enabled: true, no_overwrite: true }, false),
|
||||
proxy: new DefaultProxy("/api/v1/map/gateway/cache?url="),
|
||||
});
|
||||
const derived = resource.getDerivedResource({ url: child });
|
||||
const proxied = new URL(derived.getUrlComponent(true, true), "http://127.0.0.1:8000");
|
||||
assert.equal(proxied.pathname, "/api/v1/map/gateway/cache");
|
||||
const upstream = new URL(proxied.searchParams.get("url"));
|
||||
assert.equal(upstream.searchParams.get("nodedc_cache_profile"), "live");
|
||||
assert.equal(upstream.searchParams.has("nodedc_cache_refresh"), false);
|
||||
assert.equal(upstream.searchParams.has("access_token"), false);
|
||||
assert.equal(upstream.pathname, new URL(child, root).pathname);
|
||||
}
|
||||
});
|
||||
|
||||
test("a mismatched renderer cannot silently start against another runtime release", async (t) => {
|
||||
const originalWindow = globalThis.window;
|
||||
globalThis.window = { location: { origin: "http://127.0.0.1:8000" } };
|
||||
t.after(() => {
|
||||
if (originalWindow === undefined) delete globalThis.window;
|
||||
else globalThis.window = originalWindow;
|
||||
});
|
||||
const configuration = {
|
||||
schema_version: "missioncore.map-runtime/v1",
|
||||
map_page_version: "0.1.0",
|
||||
renderer: { id: "cesium", version: CESIUM_RENDERER_VERSION },
|
||||
gateway: {
|
||||
configured: true,
|
||||
health_url: "/api/v1/map/gateway/health",
|
||||
asset_endpoint_template: "/api/v1/map/gateway/ion/assets/{asset_id}/endpoint",
|
||||
cache_proxy_prefix: "/api/v1/map/gateway/cache?url=",
|
||||
},
|
||||
assets: { imagery: 2, terrain: 1, buildings: 96188 },
|
||||
};
|
||||
t.mock.method(globalThis, "fetch", async () => Response.json(configuration));
|
||||
assert.equal((await fetchMapRuntimeConfiguration("/api/v1/map/runtime-config", new AbortController().signal)).renderer.version, CESIUM_RENDERER_VERSION);
|
||||
configuration.renderer.version = "1.143.0";
|
||||
await assert.rejects(fetchMapRuntimeConfiguration("/api/v1/map/runtime-config", new AbortController().signal), { code: "map_runtime_contract_mismatch" });
|
||||
});
|
||||
|
||||
test("project focus keeps its range and survives the persisted camera round trip", async () => {
|
||||
const C = await import("cesium");
|
||||
const scene = {
|
||||
drawingBufferWidth: 840, drawingBufferHeight: 461,
|
||||
mapProjection: new C.GeographicProjection(), ellipsoid: C.Ellipsoid.WGS84,
|
||||
mode: C.SceneMode.SCENE3D,
|
||||
screenSpaceCameraController: { minimumZoomDistance: 1, maximumZoomDistance: Infinity },
|
||||
};
|
||||
const camera = new C.Camera(scene);
|
||||
scene.camera = camera;
|
||||
camera.update(C.SceneMode.SCENE3D);
|
||||
for (const [lon, lat, height] of [[3.711, 51.065, 10], [37.58, 55.75, 160], [-97.736, 30.287, 180]]) {
|
||||
const target = C.Cartesian3.fromDegrees(lon, lat, height);
|
||||
camera.flyToBoundingSphere(new C.BoundingSphere(target, 160), {
|
||||
duration: 0, offset: new C.HeadingPitchRange(0, -Math.PI / 4, 600),
|
||||
});
|
||||
assert.ok(Math.abs(C.Cartesian3.distance(camera.positionWC, target) - 600) < 1e-5);
|
||||
const position = C.Cartographic.clone(camera.positionCartographic);
|
||||
const orientation = { heading: camera.heading, pitch: camera.pitch, roll: camera.roll };
|
||||
camera.setView({ destination: C.Cartesian3.fromRadians(position.longitude, position.latitude, position.height), orientation });
|
||||
const toward = C.Cartesian3.normalize(C.Cartesian3.subtract(target, camera.positionWC, new C.Cartesian3()), new C.Cartesian3());
|
||||
assert.ok(C.Cartesian3.dot(camera.directionWC, toward) > 0.999999);
|
||||
assert.ok(Math.abs(C.Cartesian3.distance(camera.positionWC, target) - 600) < 1e-5);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user