detailAnchor.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /** 详情层级决定空间锚点;设备归属仍由 selection.pointCode 保留。 */
  2. import { MAP_OBJECT_KIND } from './mapSummary.js'
  3. import { DEVICE_LAYER_KIND } from './deviceLayer.js'
  4. import { DETAIL_LEVEL } from './detailFlow.js'
  5. import { locationVerdict } from './coordinate.js'
  6. export function resolveDetailAnchor({ selection, objects = [], devices = [] } = {}) {
  7. const current = selection || {}
  8. if (current.level === DETAIL_LEVEL.NONE) return null
  9. if (current.level === DETAIL_LEVEL.EQUIPMENT && current.deviceCode) {
  10. if (current.pointCode) {
  11. const device = devices.find((item) => item.code === current.deviceCode && item.pointCode === current.pointCode) || null
  12. return { kind: DEVICE_LAYER_KIND, code: current.deviceCode, pointCode: current.pointCode, object: device }
  13. }
  14. const device = objects.find((item) => item.kind === MAP_OBJECT_KIND.UNASSOCIATED_EQUIPMENT && item.code === current.deviceCode) || null
  15. return { kind: MAP_OBJECT_KIND.UNASSOCIATED_EQUIPMENT, code: current.deviceCode, object: device }
  16. }
  17. if (!current.pointCode) return null
  18. const point = objects.find((item) => item.kind === MAP_OBJECT_KIND.MONITORING_POINT && item.code === current.pointCode) || null
  19. return { kind: MAP_OBJECT_KIND.MONITORING_POINT, code: current.pointCode, object: point }
  20. }
  21. /** Facility placement is its own evidence; no fabricated device coordinateValidation. */
  22. export function resolveFacilityDetailAnchor(point) {
  23. return point ? { kind: 'facility-point', code: point.code, key: point.key, category: point.detailCategory, id: point.id, object: point } : null
  24. }
  25. export function detailAnchorLocation(target) {
  26. if (target?.kind === 'facility-point') {
  27. const point = target.object
  28. return !point || point.placement === 'pending'
  29. ? { present: false, renderable: false, reasonText: '' }
  30. : { present: true, renderable: point.placement === 'drawn', reasonText: point.reasonText || '' }
  31. }
  32. if (!target || (target.object && target.object.placement === 'pending')) {
  33. return { present: false, renderable: false, reasonText: '' }
  34. }
  35. return locationVerdict(target.object ? [target.object] : [], target.code)
  36. }