t32-color-layer.mjs 1.8 KB

12345678910111213141516171819202122232425
  1. import assert from 'node:assert/strict'
  2. import { JulianDate } from 'cesium'
  3. import { syncPipeLayer, clearPipeLayer } from '../../../src/modules/cockpit/services/cesiumPipeLayer.js'
  4. const sources=[]
  5. const viewer={dataSources:{getByName:name=>sources.filter(s=>s.name===name),add:async s=>{sources.push(s);return s}}}
  6. const pipe=(code,industry,networkLevel=0)=>({code,industry,networkLevel,diameter:400,positions:[[110.39,28.44],[110.3901,28.44]]})
  7. const network={pipes:[pipe('gas','GAS',1),pipe('water','WATER_SUPPLY',1),pipe('sewage','DRAINAGE',0),pipe('rain','DRAINAGE',1)],components:[{code:'well',industry:'MANHOLE',kind:'other',position:[110.39,28.44],label:''}]}
  8. await syncPipeLayer(viewer,network)
  9. const t=JulianDate.now(),entities=sources[0].entities
  10. const color=id=>entities.getById(id).polyline.material.color.getValue(t)
  11. assert.ok(color('pipe:gas').red>color('pipe:gas').green*2,'gas visible guide must be red')
  12. assert.ok(color('pipe:water').blue>color('pipe:water').red*2)
  13. assert.ok(color('pipe:sewage').green>color('pipe:sewage').blue*1.5)
  14. assert.ok(color('pipe:rain').blue>.8&&color('pipe:rain').green>.8)
  15. const well=entities.getById('component:well')
  16. const wellColor=well.point.color.getValue(t)
  17. assert.ok(wellColor.blue>.8&&wellColor.red>.5&&wellColor.green<.6,'manhole is independent purple')
  18. assert.equal(well.label.text.getValue(t),'窨井')
  19. const rainBefore=entities.getById('pipe:rain').polyline
  20. network.pipes[3]={...network.pipes[3],networkLevel:0}
  21. await syncPipeLayer(viewer,network)
  22. assert.notStrictEqual(entities.getById('pipe:rain').polyline,rainBefore,'network-level-only update must recolor')
  23. assert.ok(color('pipe:rain').green>color('pipe:rain').blue*1.5)
  24. await clearPipeLayer(viewer)
  25. console.log('PASS real Cesium source guide colors, special manhole symbol, and network-level-only recolor')