Format the files this branch wrote or broke with Prettier

This commit is contained in:
German Khokhlov committed 2026-11-03 23:02:04 +04:00
1 parent 227e3c2051
commit 8d7f055572
90 files changed
+1408 -640

No files matched your search

+22 -5
View File
@@ -30,7 +30,10 @@ export function createCameraFraming({ state }) {
const scene = state.viewer?.scene;
const carto = Cesium.Cartographic.fromDegrees(lon, lat);
const engine = state.viewer?.engine;
let height = engine ? engine.surface.sampleHeight(carto) ?? engine.surface.terrainHeight(carto) : sampledSurfaceHeight(scene, carto);
let height = engine
? (engine.surface.sampleHeight(carto) ??
engine.surface.terrainHeight(carto))
: sampledSurfaceHeight(scene, carto);
if (height === null) height = scene?.globe?.getHeight?.(carto);
if (!plausibleSurfaceHeight(height)) height = fallback;
return plausibleSurfaceHeight(height) ? height : 0;
@@ -55,10 +58,24 @@ export function createCameraFraming({ state }) {
if (flight === current) flight = null;
};
if (state.viewer.engine) {
state.viewer.engine.camera.flyToSphere({
center:Cesium.Cartesian3.fromDegrees(position.lon,position.lat,ground+2),radius:4
}, {heading:Cesium.Math.toRadians(bearing || 0),pitch:Cesium.Math.toRadians(-32),range:140,duration:1.6,
complete:release,cancel:release});
state.viewer.engine.camera.flyToSphere(
{
center: Cesium.Cartesian3.fromDegrees(
position.lon,
position.lat,
ground + 2,
),
radius: 4,
},
{
heading: Cesium.Math.toRadians(bearing || 0),
pitch: Cesium.Math.toRadians(-32),
range: 140,
duration: 1.6,
complete: release,
cancel: release,
},
);
return;
}
state.viewer.camera.flyToBoundingSphere(
+4 -1
View File
@@ -11,7 +11,10 @@ export function createCredits() {
function show(viewer, def) {
if (shown.has(def.id)) return;
if (viewer?.engine) {
shown.set(def.id, viewer.engine.credits.addStatic(def.credit.html, { onScreen: true }));
shown.set(
def.id,
viewer.engine.credits.addStatic(def.credit.html, { onScreen: true }),
);
return;
}
if (!viewer?.creditDisplay) return;
+3 -1
View File
@@ -32,7 +32,9 @@ export function createGroundClick({ state, openNearest, isAvailable }) {
)
.map((entry) => entry.def.id);
if (!providerIds.length) return false;
const position = state.viewer.engine ? state.viewer.engine.picker.pickGlobe(screenPosition) : scenePick.pickGroundPosition(state.viewer, screenPosition);
const position = state.viewer.engine
? state.viewer.engine.picker.pickGlobe(screenPosition)
: scenePick.pickGroundPosition(state.viewer, screenPosition);
const carto = position && geo.cartographic.fromCartesian(position);
if (!carto) return false;
return openNearest(
+34 -22
View File
@@ -195,7 +195,8 @@ export function createStreetLevelLayer({
cancelGroundRetry();
const ready = state.enabled && groundClickHeightOk(state.viewer);
if (
state.enabled && state.viewer &&
state.enabled &&
state.viewer &&
!ready &&
groundRetries < GROUND_RETRY_LIMIT &&
groundUnderCamera(state.viewer) === null
@@ -266,12 +267,15 @@ export function createStreetLevelLayer({
/** Ground under the screen centre; null for sky, undefined when it cannot aim. */
function screenCentreGround() {
const canvas = state.viewer?.engine?.host.canvas ?? state.viewer?.scene?.canvas;
const canvas =
state.viewer?.engine?.host.canvas ?? state.viewer?.scene?.canvas;
const pick = state.services.scenePick?.pickGroundPosition;
if (!pick || !canvas?.clientWidth || !canvas?.clientHeight)
return undefined;
const center = { x:canvas.clientWidth/2, y:canvas.clientHeight/2 };
const position = state.viewer.engine ? state.viewer.engine.picker.pickGlobe(center) : pick(state.viewer,center);
const center = { x: canvas.clientWidth / 2, y: canvas.clientHeight / 2 };
const position = state.viewer.engine
? state.viewer.engine.picker.pickGlobe(center)
: pick(state.viewer, center);
const carto = position && geo.cartographic.fromCartesian(position);
return carto
? {
@@ -485,10 +489,13 @@ export function createStreetLevelLayer({
},
init(viewer, options) {
this.attachRenderer(viewer,options);
this.attachRenderer(viewer, options);
for (const entry of state.providers.values()) checkStatus(entry);
},
attachRenderer(viewer, {engine = null, waitForCameraRestore = false} = {}) {
attachRenderer(
viewer,
{ engine = null, waitForCameraRestore = false } = {},
) {
const map = viewer ?? services.nativeRenderer?.(engine);
state.viewer = map;
waitingForView = waitForCameraRestore;
@@ -497,45 +504,50 @@ export function createStreetLevelLayer({
parts.marker.setVisible(state.enabled);
for (const entry of state.providers.values()) {
entry.instance.init(map);
if(state.enabled && entry.on){
if (state.enabled && entry.on) {
entry.instance.activate(map);
entry.instance.repaintMap?.();
if(providerAvailable(entry)) parts.credits.show(map,entry.def);
if (providerAvailable(entry)) parts.credits.show(map, entry.def);
}
}
if (state.enabled) {
parts.selection.install(map);
watchCamera(map);
parts.marker.set(state.street.position,state.street.bearing,state.providers.get(state.street.providerId)?.def.marker);
parts.marker.set(
state.street.position,
state.street.bearing,
state.providers.get(state.street.providerId)?.def.marker,
);
remeasureGround();
}
},
resumeViewport() {
if (!waitingForView) return;
waitingForView=false;
if(state.enabled && state.viewer) {
for(const entry of activeEntries())entry.instance.refreshCoverage?.();
waitingForView = false;
if (state.enabled && state.viewer) {
for (const entry of activeEntries()) entry.instance.refreshCoverage?.();
remeasureGround();
}
},
detachRenderer() {
const map=state.viewer;
if(!map)return;
waitingForView=true;
removeCameraListener?.();removeCameraListener=null;
const map = state.viewer;
if (!map) return;
waitingForView = true;
removeCameraListener?.();
removeCameraListener = null;
cancelGroundRetry();
parts.framing.cancel();
parts.selection.uninstall();
for(const entry of state.providers.values()){
if(entry.instance.detachMap)entry.instance.detachMap();
else if(entry.on)entry.instance.deactivate();
for (const entry of state.providers.values()) {
if (entry.instance.detachMap) entry.instance.detachMap();
else if (entry.on) entry.instance.deactivate();
}
parts.marker.destroy(map);
parts.credits.hideAll(map);
unsubscribeMapStack?.();
unsubscribeMapStack=null;
mapStack=null;
state.viewer=null;
unsubscribeMapStack = null;
mapStack = null;
state.viewer = null;
},
enable(viewer) {
state.enabled = true;
+25 -7
View File
@@ -246,8 +246,13 @@ export function createLineCoverage({
const sequence = entry.sequenceList.find(({ id }) => id === sequenceId);
if (sequence && passes(sequence, current)) parts.push(...sequence.parts);
}
if(state.viewer?.engine){
state.coverage.highlight=state.viewer.lines([{id:sequenceId,parts}],colors.selected,tuning.lineWidthPx+1,pickPrefix);
if (state.viewer?.engine) {
state.coverage.highlight = state.viewer.lines(
[{ id: sequenceId, parts }],
colors.selected,
tuning.lineWidthPx + 1,
pickPrefix,
);
requestRender();
return;
}
@@ -270,8 +275,13 @@ export function createLineCoverage({
// Lookup, picking and counts follow what is drawn, not the whole tile.
const sequences = drawnSequences(entry);
entry.sequences = new Map(sequences.map((s) => [s.id, s]));
if(state.viewer?.engine){
const group = state.viewer.lines(sequences,colors.coverage,tuning.lineWidthPx,pickPrefix);
if (state.viewer?.engine) {
const group = state.viewer.lines(
sequences,
colors.coverage,
tuning.lineWidthPx,
pickPrefix,
);
entry.primitives = group ? [group] : [];
return;
}
@@ -409,7 +419,9 @@ export function createLineCoverage({
*/
function wantedTiles(viewer) {
const ground = groundUnderCamera(viewer);
const cameraHeight = viewer.engine?.camera.pose().cartographic.height ?? viewer.camera?.positionCartographic?.height;
const cameraHeight =
viewer.engine?.camera.pose().cartographic.height ??
viewer.camera?.positionCartographic?.height;
const height = Number.isFinite(cameraHeight)
? cameraHeight - (ground ?? 0)
: null;
@@ -438,7 +450,13 @@ export function createLineCoverage({
/** Recompute the tile set for the current camera and reconcile primitives. */
function refresh() {
const viewer = state.viewer;
if (!viewer || state.context.waitingForView?.() || !state.context.isActive() || state.coverage.blocked) return;
if (
!viewer ||
state.context.waitingForView?.() ||
!state.context.isActive() ||
state.coverage.blocked
)
return;
const { zoom, tiles, hint } = wantedTiles(viewer);
if (hint) {
state.coverage.hint = hint;
@@ -550,7 +568,7 @@ export function createLineCoverage({
releaseGraphics() {
detach();
highlight(null);
for(const entry of state.coverage.tiles.values()) detachPrimitive(entry);
for (const entry of state.coverage.tiles.values()) detachPrimitive(entry);
},
refresh,
clear,
@@ -256,7 +256,9 @@ export function createPanoramaxProvider({
* from high up the click may land tens of metres off the line.
*/
function lineClickRadius() {
const height = state.viewer?.engine?.camera.pose().cartographic.height ?? state.viewer?.camera?.positionCartographic?.height;
const height =
state.viewer?.engine?.camera.pose().cartographic.height ??
state.viewer?.camera?.positionCartographic?.height;
if (!Number.isFinite(height)) return NEAREST_RADIUS_M;
return Math.min(
LINE_CLICK_RADIUS_MAX_M,
+19 -18
View File
@@ -10,11 +10,13 @@ export function createSelection({ state, parts }) {
const viewer = state.viewer;
if (!viewer || !state.enabled) return;
if (input?.isPointerFree && !input.isPointerFree()) return;
const picked = viewer.engine ? click.picked : viewer.scene.pick(
click.position,
CLICK_PICK_WINDOW_PX,
CLICK_PICK_WINDOW_PX,
);
const picked = viewer.engine
? click.picked
: viewer.scene.pick(
click.position,
CLICK_PICK_WINDOW_PX,
CLICK_PICK_WINDOW_PX,
);
const id = picking?.resolvePickId
? picking.resolvePickId(picked)
: picked?.id;
@@ -33,10 +35,9 @@ export function createSelection({ state, parts }) {
/** Lon/lat of the ground under a screen point, or null (sky, no picker). */
function groundPointAt(viewer, screenPosition) {
const position = viewer.engine ? viewer.engine.picker.pickGlobe(screenPosition) : state.services.scenePick?.pickGroundPosition?.(
viewer,
screenPosition,
);
const position = viewer.engine
? viewer.engine.picker.pickGlobe(screenPosition)
: state.services.scenePick?.pickGroundPosition?.(viewer, screenPosition);
const carto = position && Cesium.Cartographic.fromCartesian(position);
return carto
? {
@@ -69,16 +70,16 @@ export function createSelection({ state, parts }) {
function install(viewer) {
if (state.clickHandler) return;
if (viewer.engine) {
const remove = viewer.engine.input.on('click',onClick,{pick:true});
state.clickHandler = { isDestroyed:()=>false,destroy:remove };
const remove = viewer.engine.input.on('click', onClick, { pick: true });
state.clickHandler = { isDestroyed: () => false, destroy: remove };
} else {
state.clickHandler = new Cesium.ScreenSpaceEventHandler(
viewer.scene.canvas,
);
state.clickHandler.setInputAction(
onClick,
Cesium.ScreenSpaceEventType.LEFT_CLICK,
);
state.clickHandler = new Cesium.ScreenSpaceEventHandler(
viewer.scene.canvas,
);
state.clickHandler.setInputAction(
onClick,
Cesium.ScreenSpaceEventType.LEFT_CLICK,
);
}
document.addEventListener('keydown', onKeyDown);
picking?.registerPickOwner?.(STREET_LEVEL_LAYER_ID, parts.router.ownsPick);
+2 -1
View File
@@ -142,7 +142,8 @@ export function createSequenceCones({
* reloads a selected one (a provider that loads part of a sequence moved on).
*/
async function select(sequenceId, { force = false } = {}) {
if (!sequenceId || (!state.viewer && !state.context.waitingForView?.())) return;
if (!sequenceId || (!state.viewer && !state.context.waitingForView?.()))
return;
// Already on screen, or already on its way.
if (
!force &&
+22 -5
View File
@@ -2,7 +2,8 @@ import * as Cesium from 'cesium';
import { wrapLon } from './tileMath.js';
export const cameraLocation = (view) =>
view?.engine?.camera.pose().cartographic ?? view?.camera?.positionCartographic;
view?.engine?.camera.pose().cartographic ??
view?.camera?.positionCartographic;
const canvasOf = (view) => view?.engine?.host.canvas ?? view?.scene?.canvas;
/** Equirectangular metres between {lon, lat} points, the short way round ±180°; street scale. */
export function metresBetween(a, b) {
@@ -70,7 +71,9 @@ function raisedEllipsoid(ellipsoid, height) {
function groundHit(camera, point, ellipsoid, maxRange, engine) {
let cartesian = null;
try {
cartesian = engine ? engine.picker.pickGlobe(point) : camera.pickEllipsoid(point, ellipsoid);
cartesian = engine
? engine.picker.pickGlobe(point)
: camera.pickEllipsoid(point, ellipsoid);
} catch {
cartesian = null;
}
@@ -78,10 +81,18 @@ function groundHit(camera, point, ellipsoid, maxRange, engine) {
if (
Number.isFinite(maxRange) &&
(engine?.camera.livePosition || camera.positionWC) &&
Cesium.Cartesian3.distance(cartesian, engine?.camera.livePosition ?? camera.positionWC) > maxRange
Cesium.Cartesian3.distance(
cartesian,
engine?.camera.livePosition ?? camera.positionWC,
) > maxRange
)
return null;
return Cesium.Cartographic.fromCartesian(cartesian, engine ? Cesium.Ellipsoid.WGS84 : ellipsoid) || null;
return (
Cesium.Cartographic.fromCartesian(
cartesian,
engine ? Cesium.Ellipsoid.WGS84 : ellipsoid,
) || null
);
}
/** Camera height (m) above the ground under it. */
@@ -120,7 +131,13 @@ export function visibleBbox(
for (let j = 0; j <= BBOX_GRID; j++) {
point.x = (width * i) / BBOX_GRID;
point.y = (height * j) / BBOX_GRID;
const carto = groundHit(camera, point, ellipsoid, maxRange, viewer.engine);
const carto = groundHit(
camera,
point,
ellipsoid,
maxRange,
viewer.engine,
);
if (carto) hits.push(carto);
}
}