pipePhysical.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /** Source material semantics shared by map and detail renderers; unknown codes are never guessed. */
  2. const SURFACES = Object.freeze({
  3. steel: { kind: 'steel', label: '钢管', metalness: 0.82, roughness: 0.32 },
  4. iron: { kind: 'iron', label: '铸铁', metalness: 0.65, roughness: 0.7 },
  5. pe: { kind: 'pe', label: 'PE塑料', metalness: 0, roughness: 0.5 },
  6. pvc: { kind: 'pvc', label: 'PVC塑料', metalness: 0, roughness: 0.28 },
  7. frp: { kind: 'frp', label: '玻璃钢复合材料', metalness: 0, roughness: 0.4 },
  8. concrete: { kind: 'concrete', label: '混凝土', metalness: 0, roughness: 0.96 },
  9. copper: { kind: 'copper', label: '铜管', metalness: 0.92, roughness: 0.26 },
  10. unknown: { kind: 'unknown', label: '材质未识别', metalness: 0, roughness: 0.8 },
  11. })
  12. export function pipeSurface(material) {
  13. const text = typeof material === 'string' ? material.trim().toUpperCase() : ''
  14. let kind = 'unknown'
  15. if (/玻璃钢|^(FRP|GRP|GFRP)$/.test(text)) kind = 'frp'
  16. else if (/不锈钢|钢管|碳钢|镀锌|无缝钢|^(钢|STEEL|STAINLESS STEEL|SS|Q235|Q345)$/.test(text)) kind = 'steel'
  17. else if (/铸铁|球墨|^(DI|CI|DUCTILE IRON|CAST IRON)$/.test(text)) kind = 'iron'
  18. else if (/聚乙烯|^(HDPE|MDPE|PE)([-\s]?\d+)?$/.test(text)) kind = 'pe'
  19. else if (/聚氯乙烯|^(U?PVC|PVC[- ]?U)$/.test(text)) kind = 'pvc'
  20. else if (/混凝土|水泥|^(CONCRETE|RCP|RC)$/.test(text)) kind = 'concrete'
  21. else if (/铜管|^(COPPER|CU)$/.test(text)) kind = 'copper'
  22. return { ...SURFACES[kind], source: typeof material === 'string' ? material : '' }
  23. }
  24. export function sourceDiameterM(value) {
  25. return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value / 1000 : null
  26. }
  27. /** Same local tangent-plane metric as the detail projection. Source paths are never stretched. */
  28. export function geographicPipeLength(path) {
  29. if (!Array.isArray(path) || path.length < 2) return 0
  30. const cosLat = Math.cos(path[0][1] * Math.PI / 180)
  31. let length = 0
  32. for (let i = 1; i < path.length; i += 1) {
  33. length += Math.hypot((path[i][0] - path[i - 1][0]) * 111320 * cosLat, (path[i][1] - path[i - 1][1]) * 111320)
  34. }
  35. return length
  36. }