Keep Contacts, active layer intents and mapped sites across globe switches

This commit is contained in:
German Khokhlov committed 2026-11-03 03:05:47 +04:00
1 parent 81bcae907f
commit 87bbe14748
35 files changed
+465 -118

No files matched your search

+3 -3
View File
@@ -49,7 +49,7 @@ export function createControls({ state: layerState, services, parts, source }) {
statsRefreshInterval: 1000,
visitNamedMarkers(visitor) {
parts.namedMarkers.visit(visitor);
parts.namedMarkers?.visit(visitor);
},
/** Request a one-shot Google Maps Places search around the current map view. */
@@ -153,7 +153,7 @@ export function createControls({ state: layerState, services, parts, source }) {
position: geo.cartesian3.fromDegrees(
record.longitude,
record.latitude,
parts.rendering.installationSurfaceHeightM(record),
parts.model.installationSurfaceHeightM(record),
),
distanceM,
});
@@ -184,7 +184,7 @@ export function createControls({ state: layerState, services, parts, source }) {
center: geo.cartesian3.fromDegrees(
record.longitude,
record.latitude,
parts.rendering.installationSurfaceHeightM(record),
parts.model.installationSurfaceHeightM(record),
),
radius: 18000,
};
+1 -1
View File
@@ -21,7 +21,7 @@ test('focus frames a selected installation through the globe engine camera', ()
services: {},
parts: {
selection: { selectRecord: (id) => id === record.id },
rendering: { installationSurfaceHeightM: () => 126 },
model: { installationSurfaceHeightM: () => 126 },
},
source: {},
}).methods;
+36 -13
View File
@@ -28,6 +28,9 @@ export function createInstallationsLayer({
let renderer = null;
const lifecycle = {
init(viewer, options = {}) {
if (viewer || options.engine) return lifecycle.attachRenderer(viewer, options);
},
attachRenderer(viewer, options = {}) {
if (renderer)
throw new Error('Installations layer is already initialized');
const engine = options.engine ?? null;
@@ -35,27 +38,47 @@ export function createInstallationsLayer({
if (!renderer?.lifecycle?.methods)
throw new Error('Installation renderer is unavailable');
Object.assign(parts, renderer);
return renderer.lifecycle.methods.init(viewer, options);
const ready = renderer.lifecycle.methods.init(viewer, options);
if (state.enabled) {
renderer.lifecycle.methods.enable();
renderer.rendering.renderRecords({ claimSelection: Boolean(state.selectedId) });
}
return ready;
},
enable(...args) {
state.enabled = true;
return renderer?.lifecycle?.methods.enable(...args);
},
disable(...args) {
return renderer?.lifecycle?.methods.disable(...args);
if (renderer) return renderer.lifecycle.methods.disable(...args);
state.enabled = false;
state.abort?.abort();
state.abort = null;
state.loading = false;
state.selectedId = null;
state.contextAnchor = null;
state.contextPosition = null;
state.cameraLoadKey = null;
state.cameraLoadOwner = null;
state.coverage = { kind: 'viewport' };
clearTimeout(state.timer);
parts.viewport.clearUnavailableRetry();
services.context.clearSelectedEntityContextForLayer('military-installations');
parts.ingestion.setInstallationStatus('idle');
},
detachRenderer(viewer) {
renderer?.lifecycle.methods.detach(viewer);
renderer = null;
for (const key of ['rendering', 'namedMarkers', 'selection', 'lifecycle'])
delete parts[key];
},
destroy(...args) {
try {
return renderer?.lifecycle?.methods.destroy(...args);
} finally {
renderer = null;
for (const key of [
'rendering',
'namedMarkers',
'selection',
'lifecycle',
])
delete parts[key];
if (renderer) renderer.lifecycle.methods.destroy(...args);
else {
lifecycle.disable();
source.destroy?.();
}
renderer = null;
},
};
return Object.assign(
+3 -4
View File
@@ -73,8 +73,7 @@ export function createIngestion({
}
async function loadInstallations() {
if (!layerState.enabled || (!layerState.viewer && !layerState.engine))
return;
if (!layerState.enabled) return;
const { box, coverage } = parts.viewport.loadArea(layerState.viewer);
// Guidance, not a fault: the layer chose not to query because the view is
// unbounded (a global view, or Cockpit looking at the horizon). Keep it out
@@ -261,8 +260,8 @@ export function createIngestion({
? msg('Too many mapped sites in view to list them all')
: placesError,
);
parts.rendering.renderRecords();
parts.rendering.warmInstallationFloors(
parts.rendering?.renderRecords();
parts.rendering?.warmInstallationFloors(
layerState.records.filter((r) => !r.pointOnly),
);
};
+2 -2
View File
@@ -44,11 +44,11 @@ export function createModel({ state: layerState, services, parts, source }) {
}
function installationSurfaceHeightM(record) {
const floor = services.ground?.cachedGroundFloor?.(
const floor = services?.ground?.cachedGroundFloor?.(
record?.latitude,
record?.longitude,
);
return services.ground?.floorAltitudeM?.(null, floor) ?? 0;
return services?.ground?.floorAltitudeM?.(null, floor) ?? 0;
}
/**
@@ -55,10 +55,11 @@ test('Contacts camera motion reprojects and declutters existing labels without s
h.setX(600); h.lifecycle.enable();
assert.equal(h.labels.length, 2);
assert.equal(h.publications(), 5);
const oldScene = h.state.viewer.scene;
h.lifecycle.destroy(h.state.viewer);
assert.equal(h.camera.changed.numberOfListeners, 0);
assert.equal(h.camera.moveEnd.numberOfListeners, 0);
assert.equal(h.state.viewer.scene.preRender.numberOfListeners, 0);
assert.equal(oldScene.preRender.numberOfListeners, 0);
});
test('wide named markers retain primitives until close polygons publish with the same identity', async (t) => {
@@ -92,11 +92,19 @@ export function createLifecycle({
destroy(viewer) {
source.destroy?.();
this.disable();
layerState.contextAnchor = null;
layerState.contextPosition = null;
layerState.coverage = { kind: 'viewport' };
this.detach(viewer);
},
detach(viewer) {
services.credits?.hideOsmCredit?.(viewer, LAYER_ID);
services.credits?.hideGooglePlacesCredit?.(viewer, LAYER_ID);
unregisterPickOwner(LAYER_ID);
releaseCameraSensitivity(viewer?.camera, LAYER_ID);
layerState.surfaceChangedRemove?.();
layerState.surfaceChangedRemove = null;
layerState.moveEndRemove?.();
layerState.changedRemove?.();
layerState.moveEndRemove = layerState.changedRemove = null;
parts.selection.destroy?.();
layerState.clickHandler?.destroy();
layerState.clickHandler = null;
@@ -105,6 +113,7 @@ export function createLifecycle({
if (layerState.dataSource && viewer)
viewer.dataSources.remove(layerState.dataSource, true);
layerState.dataSource = null;
layerState.viewer = null;
layerState.engine = null;
},
};
@@ -353,8 +353,9 @@ export function createRendering({
)
.map((record) => ({ lat: record.latitude, lon: record.longitude }));
if (!cold.length) return;
const owner = layerState.dataSource;
warmFireAnchorFloors(cold).then(() => {
if (!layerState.enabled || !layerState.dataSource) return;
if (!layerState.enabled || !owner || layerState.dataSource !== owner) return;
if (
!cold.some((point) => cachedGroundFloor(point.lat, point.lon) != null)
)
+7 -1
View File
@@ -608,7 +608,7 @@ export function createInstallationsNavaraRenderer(
services.picking.registerPickOwner(LAYER_ID, (id) =>
layerState.recordById.has(id),
);
renderRecords();
renderRecords({ claimSelection: Boolean(layerState.selectedId) });
},
disable() {
visible = false;
@@ -640,6 +640,12 @@ export function createInstallationsNavaraRenderer(
destroy() {
source.destroy?.();
this.disable();
this.detach();
},
detach() {
services.credits?.hideOsmCredit?.(engine, LAYER_ID);
syncPlacesCredit([]);
services.picking.unregisterPickOwner(LAYER_ID);
layerState.moveEndRemove?.();
layerState.changedRemove?.();
layerState.moveEndRemove = layerState.changedRemove = null;
+3 -1
View File
@@ -19,7 +19,9 @@ export function createViewport({ state: layerState, services, parts, source }) {
return { box: bounds, coverage: { kind: 'subject', radiusM } };
}
}
return { box: viewportBox(viewer), coverage: { kind: 'viewport' } };
if (viewer || layerState.engine)
layerState.lastViewBox = viewportBox(viewer);
return { box: layerState.lastViewBox ?? null, coverage: { kind: 'viewport' } };
}
function viewportBox(viewer) {