|
|
@@ -1,25 +1,31 @@
|
|
|
/**
|
|
|
- * 未关联设备的屏幕拥挤聚合(本票:未关联设备聚合与成员选择)。
|
|
|
+ * 屏幕拥挤聚合:未关联设备(03)与监测点(04)共用一套分组/成员表/缩放接缝。
|
|
|
*
|
|
|
- * 纯函数、不 import Vue/Cesium/DOM:输入是**已经投影到窗口坐标**的未关联设备行
|
|
|
+ * 纯函数、不 import Vue/Cesium/DOM:输入是**已经投影到窗口坐标**的对象行
|
|
|
* (服务层/overlay 每帧用同一枚 projectToWindow 投影),输出是稳定的聚合组与成员表。
|
|
|
*
|
|
|
* 第一性原理:
|
|
|
* · 聚合只表达**显示拥挤**,不改变成员的真实坐标、身份、状态或统计口径;
|
|
|
- * · 只聚合同一类对象(未关联设备),不跨类合并;
|
|
|
- * · 组身份 = 成员编码集合(排序后拼接),成员不变则 groupKey 稳定,相机微移不抖;
|
|
|
+ * · 三类对象各有独立命名空间,本文件只聚设备与监测点,绝不跨类合并;
|
|
|
+ * · 组身份 = 类别命名空间 + 成员编码集合(排序后拼接),成员不变 groupKey 稳定;
|
|
|
+ * · 状态优先级按类别原生词表:设备五态(报警>工单>预警)与点位六态(报警>预警>工单)
|
|
|
+ * 不共用一张表;
|
|
|
* · 选中成员从聚合中移出(由调用方传 selectedCode),单独显示并保留详情/状态。
|
|
|
*
|
|
|
- * 屏幕距离用网格划分 + 并查集,平均 O(n),避免两两比较(密集点位下 O(n^2) 会拖慢每帧)。
|
|
|
+ * 屏幕距离用「排序 + 有界贪心聚类」,避免两两比较(密集点位下 O(n^2) 会拖慢每帧)。
|
|
|
*/
|
|
|
// 未关联设备的“原生状态”是设备五态(不是点位六态):色/词/优先级都走设备表,
|
|
|
// 否则工单处置与预警的先后会被点位表带反(设备规则:报警 > 工单处置 > 预警)。
|
|
|
import { deviceVisualForStatus } from './deviceStatus.js'
|
|
|
import { industryLabel } from './filterOptions.js'
|
|
|
+import { ringEffectFor } from './markerMetrics.js'
|
|
|
import { PIPE_PALETTE } from './pipeVisual.js'
|
|
|
+import { visualForStatus } from './pointStatus.js'
|
|
|
|
|
|
/** 聚合符号的 kind(只用于显示/拾取身份,不是业务对象,也不是设备编码)。 */
|
|
|
export const AGGREGATE_KIND = 'unassociated-equipment-aggregate'
|
|
|
+/** 监测点聚合符号的 kind:与设备聚合**独立命名空间**,同位置也不跨类合并。 */
|
|
|
+export const POINT_AGGREGATE_KIND = 'monitoring-point-aggregate'
|
|
|
|
|
|
/** 默认屏幕合并阈值(px):小于该距离视为拥挤。 */
|
|
|
export const DEFAULT_MIN_SEPARATION_PX = 22
|
|
|
@@ -99,8 +105,8 @@ export function depthZIndex(distance, { min = 1, max = 900 } = {}) {
|
|
|
}
|
|
|
|
|
|
/** 类型字的行业色语义:沿用管线行业色单源(燃气红 / 供水蓝 / 排水绿 / 窨井紫)。 */
|
|
|
-export function typeCharOf(industry) {
|
|
|
- return TYPE_CHAR[industry] || '设'
|
|
|
+export function typeCharOf(industry, fallback = '设') {
|
|
|
+ return TYPE_CHAR[industry] || fallback
|
|
|
}
|
|
|
|
|
|
export function typeColorOf(industry) {
|
|
|
@@ -108,13 +114,54 @@ export function typeColorOf(industry) {
|
|
|
return (PIPE_PALETTE[industry] || PIPE_PALETTE.UNKNOWN).color
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 聚合类别档案:把「哪些对象、什么状态词表、什么类别文案」收成一份参数。
|
|
|
+ *
|
|
|
+ * 03 的设备聚合与 04 的监测点聚合共用同一套分组/成员表/缩放接缝,但**状态语义不同**:
|
|
|
+ * 设备走设备五态(报警>工单>预警),监测点走后端点位六态(报警>预警>工单>正常>离线>无设备)。
|
|
|
+ * 两者不共享状态优先级、不跨类合并;这里只参数化,不把两套词表揉成一张。
|
|
|
+ */
|
|
|
+const CATEGORY_PROFILE = {
|
|
|
+ 'unassociated-equipment': {
|
|
|
+ key: 'unassociated-equipment',
|
|
|
+ memberKind: 'unassociated-equipment',
|
|
|
+ aggregateKind: AGGREGATE_KIND,
|
|
|
+ category: '独立设备',
|
|
|
+ noun: '台独立设备',
|
|
|
+ fallbackTypeChar: '设',
|
|
|
+ fallbackTypeLabel: '设备',
|
|
|
+ toneFallback: 'point-unassociated',
|
|
|
+ visualOf: deviceVisualForStatus,
|
|
|
+ effectOf: (status) => deviceVisualForStatus(status).effect || '',
|
|
|
+ },
|
|
|
+ 'monitoring-point': {
|
|
|
+ key: 'monitoring-point',
|
|
|
+ memberKind: 'monitoring-point',
|
|
|
+ aggregateKind: POINT_AGGREGATE_KIND,
|
|
|
+ category: '监测点',
|
|
|
+ noun: '个监测点',
|
|
|
+ fallbackTypeChar: '点',
|
|
|
+ fallbackTypeLabel: '点位',
|
|
|
+ toneFallback: 'point-unknown',
|
|
|
+ visualOf: visualForStatus,
|
|
|
+ // 点位状态表只给优先级/色/形状/文案;动效键仍取 markerMetrics 的同一张 RING_EFFECT 表,
|
|
|
+ // 于是徽章特效与单体点位特效同源(ALARM pulse / WARNING blink / WORK_ORDER spin)。
|
|
|
+ effectOf: (status) => {
|
|
|
+ const ring = ringEffectFor(status)
|
|
|
+ return ring ? ring.effect : ''
|
|
|
+ },
|
|
|
+ },
|
|
|
+}
|
|
|
+
|
|
|
+const EQUIPMENT_PROFILE = CATEGORY_PROFILE['unassociated-equipment']
|
|
|
+
|
|
|
const EARTH_LAT_METERS = 110540
|
|
|
const EARTH_LON_METERS = 111320
|
|
|
const DEG = Math.PI / 180
|
|
|
|
|
|
-function isCandidate(item) {
|
|
|
+function isCandidate(item, profile) {
|
|
|
return Boolean(item)
|
|
|
- && item.kind === 'unassociated-equipment'
|
|
|
+ && item.kind === profile.memberKind
|
|
|
&& Number.isFinite(item.longitude)
|
|
|
&& Number.isFinite(item.latitude)
|
|
|
&& item.screen
|
|
|
@@ -122,31 +169,35 @@ function isCandidate(item) {
|
|
|
&& Number.isFinite(item.screen.y)
|
|
|
}
|
|
|
|
|
|
-/** 未关联设备的状态优先级:设备五态(报警 > 工单处置 > 预警 > 正常 > 离线 > 未发布)。 */
|
|
|
-export function statusPriority(status) {
|
|
|
- const visual = deviceVisualForStatus(status || '')
|
|
|
+/**
|
|
|
+ * 状态优先级(缺省按未关联设备的五态;监测点调用方传点位档案)。
|
|
|
+ * 设备:报警 > 工单处置 > 预警 > 正常 > 离线 > 未发布;
|
|
|
+ * 点位:报警 > 预警 > 工单处置 > 正常 > 离线 > 无设备 > 未发布。
|
|
|
+ */
|
|
|
+export function statusPriority(status, profile = EQUIPMENT_PROFILE) {
|
|
|
+ const visual = profile.visualOf(status || '')
|
|
|
return Number.isFinite(visual.priority) ? visual.priority : 999
|
|
|
}
|
|
|
|
|
|
-function statusSummaryOf(members) {
|
|
|
+function statusSummaryOf(members, profile) {
|
|
|
const counts = {}
|
|
|
for (const member of members) {
|
|
|
const key = member.status || 'UNKNOWN'
|
|
|
counts[key] = (counts[key] || 0) + 1
|
|
|
}
|
|
|
const statuses = Object.keys(counts).map((status) => {
|
|
|
- const visual = deviceVisualForStatus(status)
|
|
|
+ const visual = profile.visualOf(status)
|
|
|
return {
|
|
|
status,
|
|
|
count: counts[status],
|
|
|
priority: Number.isFinite(visual.priority) ? visual.priority : 999,
|
|
|
tone: visual.tone,
|
|
|
label: visual.label,
|
|
|
- effect: visual.effect || '',
|
|
|
+ effect: profile.effectOf(status),
|
|
|
}
|
|
|
}).sort((a, b) => a.priority - b.priority || String(a.status).localeCompare(String(b.status)))
|
|
|
const primary = statuses[0] || null
|
|
|
- // 「异常」= 设备表里带动效的三态(报警/工单处置/预警);角标取最高优先级异常,其余用 +N 种状态。
|
|
|
+ // 「异常」= 该类别词表里带动效的状态(设备三态 / 点位三态);角标取最高优先级异常,其余 +N 种。
|
|
|
const abnormal = statuses.filter((item) => item.effect !== '')
|
|
|
return {
|
|
|
counts,
|
|
|
@@ -188,7 +239,7 @@ export function worldSpanMeters(bounds) {
|
|
|
return Math.max(latM, lonM)
|
|
|
}
|
|
|
|
|
|
-function buildGroup(rawMembers) {
|
|
|
+function buildGroup(rawMembers, profile) {
|
|
|
const members = rawMembers.slice().sort((a, b) => String(a.code).localeCompare(String(b.code)))
|
|
|
const screen = {
|
|
|
x: members.reduce((sum, item) => sum + item.screen.x, 0) / members.length,
|
|
|
@@ -208,10 +259,20 @@ function buildGroup(rawMembers) {
|
|
|
.map(([key, count]) => ({ key, count, label: industryLabel(key) || (key || '未标注') }))
|
|
|
.sort((a, b) => b.count - a.count || a.key.localeCompare(b.key))
|
|
|
const mixedIndustry = industrySummary.length > 1
|
|
|
+ const statusSummary = statusSummaryOf(members, profile)
|
|
|
return {
|
|
|
- kind: AGGREGATE_KIND,
|
|
|
- // 组身份 = 成员编码集合(成员不变则稳定,相机微移不抖)。
|
|
|
- groupKey: AGGREGATE_KIND + '|' + codes.join(','),
|
|
|
+ kind: profile.aggregateKind,
|
|
|
+ // 组身份 = 类别命名空间 + 成员编码集合(成员不变则稳定,相机微移不抖)。
|
|
|
+ groupKey: profile.aggregateKind + '|' + codes.join(','),
|
|
|
+ statusProfile: profile.key,
|
|
|
+ memberKind: profile.memberKind,
|
|
|
+ category: profile.category,
|
|
|
+ noun: profile.noun,
|
|
|
+ toneFallback: profile.toneFallback,
|
|
|
+ fallbackTypeChar: profile.fallbackTypeChar,
|
|
|
+ fallbackTypeLabel: profile.fallbackTypeLabel,
|
|
|
+ // 成员表排序用的状态优先级表(点位与设备各一张,不跨类借用)。
|
|
|
+ statusPriorities: Object.fromEntries(statusSummary.statuses.map((item) => [item.status, item.priority])),
|
|
|
count: members.length,
|
|
|
members,
|
|
|
screen,
|
|
|
@@ -223,16 +284,15 @@ function buildGroup(rawMembers) {
|
|
|
boundsScreen: screenBox,
|
|
|
boundsWorld,
|
|
|
spreadPx: Math.hypot(screenBox.maxX - screenBox.minX, screenBox.maxY - screenBox.minY),
|
|
|
- statusSummary: statusSummaryOf(members),
|
|
|
+ statusSummary,
|
|
|
industrySummary,
|
|
|
mixedIndustry,
|
|
|
primaryIndustry: industrySummary.length ? industrySummary[0].key : '',
|
|
|
- typeLabel: mixedIndustry ? '混合' : (industrySummary.length ? industrySummary[0].label : '设备'),
|
|
|
- // 徽章中央大字:混合=混、同质=行业短字(燃/水/排/井),认不出=设。
|
|
|
- typeChar: mixedIndustry ? '混' : typeCharOf(industrySummary.length ? industrySummary[0].key : ''),
|
|
|
+ typeLabel: mixedIndustry ? '混合' : (industrySummary.length ? industrySummary[0].label : profile.fallbackTypeLabel),
|
|
|
+ // 徽章中央大字:混合=混、同质=行业短字(燃/水/排/井),认不出=类别兜底(设备「设」/点位「点」)。
|
|
|
+ typeChar: mixedIndustry ? '混' : typeCharOf(industrySummary.length ? industrySummary[0].key : '', profile.fallbackTypeChar),
|
|
|
// 类型色语义:同质用行业色;混合用中性色(避免冒充某一行业)。
|
|
|
typeColor: mixedIndustry ? PIPE_PALETTE.UNKNOWN.color : typeColorOf(industrySummary.length ? industrySummary[0].key : ''),
|
|
|
- category: '独立设备',
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -247,8 +307,9 @@ function buildGroup(rawMembers) {
|
|
|
* @param {string} [options.selectedCode] 已选成员编码:从聚合中移出,单独显示
|
|
|
* @returns {{groups: Array, selected: object|null}} 组内 count>1 才应显示为聚合徽章
|
|
|
*/
|
|
|
-export function groupUnassociatedByScreen(items, { minSeparationPx = DEFAULT_MIN_SEPARATION_PX, maxSpreadPx = DEFAULT_MAX_SPREAD_PX, releaseBufferPx = DEFAULT_RELEASE_BUFFER_PX, previousGroups = [], selectedCode = '' } = {}) {
|
|
|
- const list = (Array.isArray(items) ? items : []).filter(isCandidate)
|
|
|
+function groupByScreen(items, categoryKey, { minSeparationPx = DEFAULT_MIN_SEPARATION_PX, maxSpreadPx = DEFAULT_MAX_SPREAD_PX, releaseBufferPx = DEFAULT_RELEASE_BUFFER_PX, previousGroups = [], selectedCode = '' } = {}) {
|
|
|
+ const profile = CATEGORY_PROFILE[categoryKey] || EQUIPMENT_PROFILE
|
|
|
+ const list = (Array.isArray(items) ? items : []).filter((item) => isCandidate(item, profile))
|
|
|
const selected = typeof selectedCode === 'string' ? selectedCode : ''
|
|
|
const pool = list.filter((item) => String(item.code || '') !== selected)
|
|
|
const selectedRow = selected ? (list.find((item) => String(item.code) === selected) || null) : null
|
|
|
@@ -308,11 +369,24 @@ export function groupUnassociatedByScreen(items, { minSeparationPx = DEFAULT_MIN
|
|
|
target.members.push(item)
|
|
|
target.box = mergeBox(target.box, item.screen.x, item.screen.y)
|
|
|
}
|
|
|
- const groups = clusters.map((cluster) => buildGroup(cluster.members))
|
|
|
+ const groups = clusters.map((cluster) => buildGroup(cluster.members, profile))
|
|
|
.sort((a, b) => a.groupKey.localeCompare(b.groupKey))
|
|
|
return { groups, selected: selectedRow }
|
|
|
}
|
|
|
|
|
|
+/** 未关联设备的屏幕聚合(03 的稳定入口)。 */
|
|
|
+export function groupUnassociatedByScreen(items, options = {}) {
|
|
|
+ return groupByScreen(items, 'unassociated-equipment', options)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 监测点的屏幕聚合(04):与设备**独立命名空间**,同位置也不跨类合并;
|
|
|
+ * 状态改用点位自身权威六态(含 EMPTY「无设备」),不借用设备五态。
|
|
|
+ */
|
|
|
+export function groupMonitoringPointsByScreen(items, options = {}) {
|
|
|
+ return groupByScreen(items, 'monitoring-point', options)
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* 聚合徽章的可显示描述(规格 69–72)。
|
|
|
*
|
|
|
@@ -332,14 +406,15 @@ export function aggregateBadge(group) {
|
|
|
? abnormal.label + ' ' + abnormal.count
|
|
|
: (primary ? primary.label + ' ' + primary.count : '无')
|
|
|
return {
|
|
|
- kind: AGGREGATE_KIND,
|
|
|
+ kind: group.kind || AGGREGATE_KIND,
|
|
|
code: group.groupKey,
|
|
|
groupKey: group.groupKey,
|
|
|
count: group.count,
|
|
|
category: group.category || '独立设备',
|
|
|
- label: group.count + ' 台独立设备',
|
|
|
+ noun: group.noun || '台独立设备',
|
|
|
+ label: group.count + ' ' + (group.noun || '台独立设备'),
|
|
|
// 圆形徽章的描边/角标色:取本组最高优先级状态(异常优先),与成员状态词表同源。
|
|
|
- tone: abnormal ? abnormal.tone : (primary ? primary.tone : 'point-unassociated'),
|
|
|
+ tone: abnormal ? abnormal.tone : (primary ? primary.tone : (group.toneFallback || 'point-unassociated')),
|
|
|
primaryStatus: primary ? primary.status : '',
|
|
|
primaryLabel: primary ? primary.label : '',
|
|
|
// 角标:最高优先级异常及数量;otherAbnormalCount = 其余异常**状态种数**(+N 种)。
|
|
|
@@ -350,14 +425,14 @@ export function aggregateBadge(group) {
|
|
|
effect: abnormal ? abnormal.effect : '',
|
|
|
// 类型:同质给具体行业(图案),混合给通用(typeLabel=混合、industryKey 为空)。
|
|
|
mixedIndustry: Boolean(group.mixedIndustry),
|
|
|
- typeLabel: group.typeLabel || (group.mixedIndustry ? '混合' : '设备'),
|
|
|
- typeChar: group.typeChar || (group.mixedIndustry ? '混' : '设'),
|
|
|
+ typeLabel: group.typeLabel || (group.mixedIndustry ? '混合' : (group.fallbackTypeLabel || '设备')),
|
|
|
+ typeChar: group.typeChar || (group.mixedIndustry ? '混' : (group.fallbackTypeChar || '设')),
|
|
|
typeColor: group.typeColor || PIPE_PALETTE.UNKNOWN.color,
|
|
|
industryKey: group.mixedIndustry ? '' : (group.primaryIndustry || ''),
|
|
|
types: group.industrySummary || [],
|
|
|
statuses,
|
|
|
tooltip: [
|
|
|
- group.count + ' 台独立设备',
|
|
|
+ group.count + ' ' + (group.noun || '台独立设备'),
|
|
|
'类型:' + (typeText || '未标注'),
|
|
|
'状态:' + (statusText || '状态未发布'),
|
|
|
'最高优先级:' + highestText,
|
|
|
@@ -371,7 +446,7 @@ export function canZoomAggregate(group, { minSpreadPx = DEFAULT_MIN_SPREAD_PX, m
|
|
|
return group.spreadPx > minSpreadPx && worldSpanMeters(group.boundsWorld) > minSpanMeters
|
|
|
}
|
|
|
|
|
|
-function sortRows(rows, sort) {
|
|
|
+function sortRows(rows, sort, priorityOf = statusPriority) {
|
|
|
const list = rows.slice()
|
|
|
if (sort === 'name' || sort === 'code') {
|
|
|
const field = sort
|
|
|
@@ -379,7 +454,7 @@ function sortRows(rows, sort) {
|
|
|
return list
|
|
|
}
|
|
|
// 默认:风险优先(报警→预警→工单→…),再按名称/编码稳定排序。
|
|
|
- list.sort((a, b) => statusPriority(a.status) - statusPriority(b.status)
|
|
|
+ list.sort((a, b) => priorityOf(a.status) - priorityOf(b.status)
|
|
|
|| String(a.name || '').localeCompare(String(b.name || ''))
|
|
|
|| String(a.code || '').localeCompare(String(b.code || '')))
|
|
|
return list
|
|
|
@@ -392,9 +467,11 @@ export function planMemberList(group, { query = '', sort = 'risk' } = {}) {
|
|
|
const filtered = q
|
|
|
? members.filter((item) => String(item.name || '').toLowerCase().includes(q) || String(item.code || '').toLowerCase().includes(q))
|
|
|
: members
|
|
|
- // 成员表要能回答「有哪些设备、什么类型、什么状态」:逐行补原生状态与类型的中文词。
|
|
|
+ // 成员表要能回答「有哪些对象、什么类型、什么状态」:逐行补**该类别原生**状态与类型中文词。
|
|
|
+ const profile = CATEGORY_PROFILE[group && group.statusProfile] || EQUIPMENT_PROFILE
|
|
|
+ const priorities = (group && group.statusPriorities) || {}
|
|
|
const rows = filtered.map((item) => {
|
|
|
- const visual = deviceVisualForStatus(item.status || '')
|
|
|
+ const visual = profile.visualOf(item.status || '')
|
|
|
return {
|
|
|
...item,
|
|
|
statusLabel: visual.label,
|
|
|
@@ -402,7 +479,7 @@ export function planMemberList(group, { query = '', sort = 'risk' } = {}) {
|
|
|
industryLabel: industryLabel(item.industry) || (item.industry || '未标注'),
|
|
|
}
|
|
|
})
|
|
|
- return sortRows(rows, sort)
|
|
|
+ return sortRows(rows, sort, (status) => (Number.isFinite(priorities[status]) ? priorities[status] : 999))
|
|
|
}
|
|
|
|
|
|
/**
|