Procházet zdrojové kódy

feat(cockpit): 按相机距离对图标/徽章做深度排序(近者在上)

投影层返回图标到相机的距离(projectPivot / projectMarkerEntity),overlay 用 depthZIndex 对数刻度换算 1..900 的深度等级:图标 z=2×depth、标签 z=2×depth+1 交错(标签略高于自身图标、低于更近的图标)。聚合徽章不再写死最高层,改用组内最近成员的距离参与同一套画家算法;移除独立标签层,标签与图标同宿主按深度比较。
ChenJZ před 2 dny
rodič
revize
84f4357d8b

+ 16 - 0
src/modules/cockpit/domain/pointAggregation.js

@@ -75,6 +75,22 @@ export function labelOccludedByAggregates(pos, centers, clearance = AGGREGATE_BA
     })
 }
 
+/**
+ * 深度排序的 z-index(近者在上,远者在下)。
+ *
+ * 地图是 3D 的,但 DOM overlay 是 2D;用「图标到相机的距离」做画家算法:
+ * 距离越小 z 越大。对数刻度覆盖 1km–5×10⁷m,避免近距离挤在一起、远距离全塌成一层。
+ * 返回值 1..900,渲染层再按「图标 = 2z、标签 = 2z+1」交错,标签略高于自身图标、
+ * 低于更近的图标 —— 这样聚合徽章也不再是绝对最高层。
+ */
+export function depthZIndex(distance, { min = 1, max = 900 } = {}) {
+    const d = Number.isFinite(distance) && distance > 0 ? distance : 1e8
+    const lo = Math.log10(1000)
+    const hi = Math.log10(5e7)
+    const t = Math.min(1, Math.max(0, (Math.log10(d) - lo) / (hi - lo)))
+    return Math.round(max - (max - min) * t)
+}
+
 /** 类型字的行业色语义:沿用管线行业色单源(燃气红 / 供水蓝 / 排水绿 / 窨井紫)。 */
 export function typeCharOf(industry) {
     return TYPE_CHAR[industry] || '设'

+ 9 - 2
src/modules/cockpit/services/cesiumEngine.js

@@ -2523,7 +2523,13 @@ function projectMarkerEntity(viewer, entity, groundOf) {
     const offset = read(entity.billboard.pixelOffset, ZERO_PIXEL_OFFSET)
     const scale = read(entity.billboard.scale, 1)
     const iconSize = Math.max(read(entity.billboard.width, 18), read(entity.billboard.height, 18)) * scale
-    return { x: at.x + rect.left + offset.x, y: at.y + rect.top + offset.y, iconSize }
+    // 深度排序(2026-11-24):projectDeviceMarkers / projectOverlapSymbols 的行都带距离。
+    return {
+        x: at.x + rect.left + offset.x,
+        y: at.y + rect.top + offset.y,
+        iconSize,
+        distance: Math.hypot(toward.x, toward.y, toward.z),
+    }
 }
 export function hasPointMarker(viewer, kind, code) {
     if (!viewer || !code) return false
@@ -2680,7 +2686,8 @@ export function createCameraEngine(viewer) {
             // 每次 getBoundingClientRect 都是一次强制同步布局 —— 几百个标记就是几百次回流。
             // 复用 projectMarkerEntity 那条路径的缓存(同样的 120ms 保鲜,只有 resize 才会变)。
             const rect = canvasRectCached(viewer)
-            return { x: at.x + rect.left, y: at.y + rect.top }
+            // 深度排序(2026-11-24):DOM overlay 用「图标到相机的距离」做画家算法。
+            return { x: at.x + rect.left, y: at.y + rect.top, distance: Cartesian3.distance(world, camera.positionWC) }
         },
 
         /**

+ 2 - 1
src/modules/cockpit/services/mapService.js

@@ -1363,7 +1363,8 @@ async function bootEngine(record) {
                         if (!at) return null
                         // projectPivot 回**窗口坐标**;overlay 宿主 inset:0 铺在 host 内,
                         // 节点坐标原点 = host 左上角 → 减 host 的窗口原点(每帧只读一次布局)。
-                        return { x: at.x - hostRect.left, y: at.y - hostRect.top }
+                        // distance 供 overlay 做深度排序(近者在上)。
+                        return { x: at.x - hostRect.left, y: at.y - hostRect.top, distance: at.distance }
                     },
                 }
             })

+ 52 - 19
src/modules/cockpit/services/markerOverlay.js

@@ -49,7 +49,7 @@ import {
 // 票 83:几何读数(本体宽 / 绘制宽 / pad)与计划读数同一出口,走查不读 DOM 内部结构。
 import { markerGeometryDataset } from '../domain/markerPlan.js'
 // 本票:未关联设备的屏幕拥挤聚合(纯 domain;本层只负责投影/渲染/点击)。
-import { AGGREGATE_BADGE, AGGREGATE_KIND, aggregateBadge, canZoomAggregate, groupUnassociatedByScreen, labelOccludedByAggregates, planMemberList } from '../domain/pointAggregation.js'
+import { AGGREGATE_BADGE, AGGREGATE_KIND, aggregateBadge, canZoomAggregate, depthZIndex, groupUnassociatedByScreen, labelOccludedByAggregates, planMemberList } from '../domain/pointAggregation.js'
 
 /**
  * 类名单源:注入的特效 CSS(下方模板串)与 DOM 构建(buildNode/mount)共用同一组常量。
@@ -59,8 +59,6 @@ import { AGGREGATE_BADGE, AGGREGATE_KIND, aggregateBadge, canZoomAggregate, grou
 const OVERLAY_HOST_CLASS = 'marker-overlay-host'
 const NODE_CLASS = 'marker-overlay-node'
 const LABEL_CLASS = 'marker-overlay-label'
-/** 标签独立图层(2026-10-28):标签要盖在所有图标之上,必须脱离节点自身的层叠上下文。 */
-const LABEL_LAYER_CLASS = 'marker-overlay-labels'
 /** 标签的零尺寸锚点(随节点位移;真正的标签盒子在它内部)。 */
 const LABEL_WRAP_CLASS = 'marker-overlay-label-wrap'
 const FX_CLASS = 'marker-overlay-fx'
@@ -682,19 +680,11 @@ export function mountMarkerOverlay(mapHost, { onPick, onHover, onAggregateZoom }
             'z-index:1',
         ].join(';')
         hostNode.style.display = ''
-        // 票 70(2026-10-28 维护者报「多点位时标签被坐标点图标遮挡」):
-        // 标签必须**独立成层**,不能留在节点内部 —— 节点带 `transform`(定位用)因而自成层叠上下文,
-        // 其子元素无论 z-index 多高都出不了这个上下文,于是后画的节点会盖住先画节点的标签。
-        // 这一层铺满宿主、`pointer-events:none`,层级高于所有节点(含 `--center` 的 3)。
-        labelLayer = document.createElement('div')
-        labelLayer.className = LABEL_LAYER_CLASS
-        labelLayer.style.cssText = [
-            'position:absolute', 'inset:0',
-            'pointer-events:none',
-            'z-index:6',
-        ].join(';')
-        // 标签层是宿主的子节点、**先挂**(节点后追加不影响 —— 层级由 z-index 决定)。
-        hostNode.appendChild(labelLayer)
+        // 深度排序(2026-11-24):标签不再单独成层,而是与图标一起挂在宿主下,
+        // 按「图标 = 2z、标签 = 2z+1」交错 —— 标签略高于自身图标,但低于更近的图标。
+        // 这样聚合徽章不再是绝对最高层,遮挡关系由「图标到相机的距离」决定。
+        // 标签不进节点内部:节点带 transform 会自成层叠上下文,子标签无法与其它节点比较层级。
+        labelLayer = hostNode
         // 票 76(C4 parity 现场把手):DOM 单层比 billboard 双层暗(镂空孔/边缘不再叠亮层)。
         // `?pinBrightness=1.2` 只做整体亮度补偿(不碰色相/饱和度);定档后写成默认常量并撤掉把手。
         try {
@@ -950,8 +940,8 @@ function buildUnassociatedAggregateNode(key, badge, tones) {
     root.dataset.markerOverlayKind = AGGREGATE_KIND
     root.dataset.markerOverlayCode = key
     root.dataset.markerOverlayAggregate = 'yes'
-    // z-index 7 > 标签层 6:聚合徽章永远压在单体名称标签之上(「聚合优先」)。
-    root.style.cssText = 'position:absolute;left:0;top:0;z-index:7;width:' + size + 'px;height:' + size + 'px;pointer-events:auto;cursor:pointer;transform-origin:50% 50%;'
+    // 层级不再写死:由 renderAggregates 按「组内最近成员的相机距离」动态给 z-index。
+    root.style.cssText = 'position:absolute;left:0;top:0;width:' + size + 'px;height:' + size + 'px;pointer-events:auto;cursor:pointer;transform-origin:50% 50%;'
     root.style.setProperty('--marker-tone', toneHex)
     root.title = badge.tooltip || badge.label
 
@@ -1070,6 +1060,13 @@ function renderAggregates(groups, tones) {
             aggregatePool.set(key, record)
             hostNode.appendChild(record.root)
         }
+        // 深度排序:聚合徽章参与同一套画家算法,不再绝对置顶(近的图标可压住远的徽章)。
+        const groupDistance = group.members.reduce((min, member) => {
+            const value = member.screen && Number.isFinite(member.screen.distance) ? member.screen.distance : 1e8
+            return Math.min(min, value)
+        }, Infinity)
+        const badgeZ = String(depthZIndex(groupDistance) * 2)
+        if (record.root.style.zIndex !== badgeZ) record.root.style.zIndex = badgeZ
         const transform = 'translate(' + group.screen.x + 'px, ' + group.screen.y + 'px) translate(-50%, -50%)'
         if (record.root.style.transform !== transform) record.root.style.transform = transform
         if (record.root.style.display !== 'block') record.root.style.display = 'block'
@@ -1294,6 +1291,14 @@ export function syncMarkerOverlay({ markers, devices, aggregates, facilities, se
             if (record.fxHost.style.transform !== fxTransform) record.fxHost.style.transform = fxTransform
         }
         if (record.root.style.display !== 'block') record.root.style.display = 'block'
+        // 深度排序:图标 = 2z,标签 = 2z+1(标签略高于自身图标,低于更近的图标)。
+        const markerDepth = depthZIndex(windowPos.distance)
+        const markerZ = String(markerDepth * 2)
+        if (record.root.style.zIndex !== markerZ) record.root.style.zIndex = markerZ
+        if (record.labelWrap) {
+            const markerLabelZ = String(markerDepth * 2 + 1)
+            if (record.labelWrap.style.zIndex !== markerLabelZ) record.labelWrap.style.zIndex = markerLabelZ
+        }
         // 标签(2026-10-28):点位与未关联设备**始终显示**(截断),hover 才展开全名;
         // 若它是当前选中对象(独立设备被选中)则由下面的 `--active` 正규负责发光,标签仍在。
         placeLabel(record, windowPos.x, windowPos.y)
@@ -1386,6 +1391,13 @@ export function syncMarkerOverlay({ markers, devices, aggregates, facilities, se
         //   · ④ 设备被选择的中心设备:隐藏(与 ② 聚合被选择态同性质)。
         //   · 非聚合设备点(k=1 关联设备):**始终显示** —— 聚合规则不得外溢到它们。
         const devicePos = { x: device.x - hostOffset.x, y: device.y - hostOffset.y }
+        const deviceDepth = depthZIndex(device.distance)
+        const deviceZ = String(deviceDepth * 2)
+        if (record.root.style.zIndex !== deviceZ) record.root.style.zIndex = deviceZ
+        if (record.labelWrap) {
+            const deviceLabelZ = String(deviceDepth * 2 + 1)
+            if (record.labelWrap.style.zIndex !== deviceLabelZ) record.labelWrap.style.zIndex = deviceLabelZ
+        }
         placeLabel(record, devicePos.x, devicePos.y)
         const isHovered = hoveredLabelKey === key
         const deviceLabel = deviceLabelState(device, isHovered)
@@ -1445,7 +1457,14 @@ export function syncMarkerOverlay({ markers, devices, aggregates, facilities, se
         record.root.classList.toggle(`${NODE_CLASS}--active`, active)
         // 票 76(四态):① 的 hover 预览与 ② 的固定态都隐藏聚合标签(让出设备环);
         // ③④ 中心已是设备点 → 整枚聚合节点让位(标签随之隐藏)。
-        // 2026-10-28:标签在**独立图层**,显隐由 `applyLabelState` 统一驱动(不再内联查 DOM 子元素)。
+        // 2026-11-24:标签与图标同宿主、按相机距离交错层级。
+        const aggDepth = depthZIndex(row.distance)
+        const aggZ = String(aggDepth * 2)
+        if (record.root.style.zIndex !== aggZ) record.root.style.zIndex = aggZ
+        if (record.labelWrap) {
+            const aggLabelZ = String(aggDepth * 2 + 1)
+            if (record.labelWrap.style.zIndex !== aggLabelZ) record.labelWrap.style.zIndex = aggLabelZ
+        }
         placeLabel(record, row.x - hostOffset.x, row.y - hostOffset.y)
         const aggregateLabel = aggregateLabelState(row)
         applyLabelState(record, aggregateLabel.visible, aggregateLabel.expanded)
@@ -1500,6 +1519,13 @@ export function syncMarkerOverlay({ markers, devices, aggregates, facilities, se
         const transform = `translate(${windowPos.x}px, ${windowPos.y}px)`
         if (record.root.style.transform !== transform) record.root.style.transform = transform
         if (record.root.style.display !== 'block') record.root.style.display = 'block'
+        const facilityDepth = depthZIndex(windowPos.distance)
+        const facilityZ = String(facilityDepth * 2)
+        if (record.root.style.zIndex !== facilityZ) record.root.style.zIndex = facilityZ
+        if (record.labelWrap) {
+            const facilityLabelZ = String(facilityDepth * 2 + 1)
+            if (record.labelWrap.style.zIndex !== facilityLabelZ) record.labelWrap.style.zIndex = facilityLabelZ
+        }
         placeLabel(record, windowPos.x, windowPos.y)
         const facilityHovered = hoveredLabelKey === key
         const facilityLabel = markerLabelState(facilityHovered)
@@ -1546,6 +1572,13 @@ export function syncMarkerOverlay({ markers, devices, aggregates, facilities, se
         const transform = `translate(${windowPos.x}px, ${windowPos.y}px)`
         if (record.root.style.transform !== transform) record.root.style.transform = transform
         if (record.root.style.display !== 'block') record.root.style.display = 'block'
+        const componentDepth = depthZIndex(windowPos.distance)
+        const componentZ = String(componentDepth * 2)
+        if (record.root.style.zIndex !== componentZ) record.root.style.zIndex = componentZ
+        if (record.labelWrap) {
+            const componentLabelZ = String(componentDepth * 2 + 1)
+            if (record.labelWrap.style.zIndex !== componentLabelZ) record.labelWrap.style.zIndex = componentLabelZ
+        }
         placeLabel(record, windowPos.x, windowPos.y)
         const componentHovered = hoveredLabelKey === key
         const componentLabel = markerLabelState(componentHovered)