CursorDeal.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import Common from './Common.js'
  2. //处理cursor优先级
  3. var CursorDeal = {
  4. priorityEvent : [//在前面的优先级高
  5. { pen_delPoint: `url({Potree.resourcePath}/images/polygon_mark/pic_pen_sub.png),auto`},
  6. { pen_addPoint: `url({Potree.resourcePath}/images/polygon_mark/pic_pen_add.png),auto`},
  7. { pen: `url({Potree.resourcePath}/images/polygon_mark/pic_pen.png),auto`},
  8. {'grabbing':'grabbing'},//通用
  9. {'hoverGrab':'grab'},//通用
  10. {'pointer':'pointer'},//通用
  11. {'hoverMonitor':'pointer'},
  12. {'zoomInCloud':'zoom-in'},
  13. {'hoverPano':'pointer'},
  14. {"notAllowed-default":'not-allowed'},
  15. {'connectPano':`url({Potree.resourcePath}/images/connect.png),auto`},
  16. {'disconnectPano':`url({Potree.resourcePath}/images/connect-dis.png),auto`},
  17. {'hoverLine':'pointer'},
  18. {'hoverTranHandle':'grab'},
  19. {"movePointcloud":'move'},
  20. {"polygon_isIntersectSelf":'not-allowed'},
  21. {"polygon_AtWrongPlace":'not-allowed'},
  22. {'delPoint':'url("https://4dkk.4dage.com/v4-test/www/sdk/images/polygon_mark/pic_pen_sub.png"), auto'},
  23. {"markerMove":'grab'},
  24. {'addPoint':'url("https://4dkk.4dage.com/v4-test/www/sdk/images/polygon_mark/pic_pen_add.png"), auto'},
  25. {'mapClipMove':'move'},
  26. {'mapClipRotate':`url({Potree.resourcePath}/images/rotate-cursor.png),auto`},
  27. {'rotatePointcloud':`url({Potree.resourcePath}/images/rotate-cursor.png),auto`},
  28. {'siteModelFloorDrag':'row-resize'},
  29. {'addSth':'cell'},//or crosshair
  30. ],
  31. list:[], //当前存在的cursor状态
  32. currentCursorIndex:null,
  33. init : function(viewer, viewers){
  34. this.priorityEvent.forEach(e=>{//刚开始Potree.resourcePath没值,现在换
  35. for(let i in e){
  36. e[i] = Common.replaceAll(e[i],'{Potree.resourcePath}',Potree.resourcePath)
  37. }
  38. })
  39. this.domElements = viewers.map(e=>e.renderArea)
  40. viewer.addEventListener("CursorChange",(e)=>{
  41. if(e.action == 'add'){
  42. this.add(e.name)
  43. }else{
  44. this.remove(e.name)
  45. }
  46. })
  47. },
  48. add : function(name){
  49. var priorityItem = this.priorityEvent.find(e=>e[name])
  50. if(!priorityItem){
  51. console.error('CursorDeal 未定义优先级 name:'+ name);
  52. return
  53. }
  54. if(!this.list.includes(name)){
  55. this.judge({addItem: priorityItem, name})
  56. this.list.push(name)
  57. }
  58. },
  59. remove : function(name){
  60. var index = this.list.indexOf(name);
  61. if(index > -1){
  62. this.list.splice(index, 1)
  63. this.judge()
  64. }
  65. },
  66. judge:function(o={}){
  67. //console.log(o,this.list)
  68. if(o.addItem){
  69. var addIndex = this.priorityEvent.indexOf(o.addItem)
  70. if(addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0){
  71. this.domElements.forEach(e=>e.style.cursor = o.addItem[o.name] )
  72. this.currentCursorIndex = addIndex
  73. }
  74. }else{
  75. var levelMax = {index:Infinity, cursor:null }
  76. this.list.forEach(name=>{
  77. var priorityItem = this.priorityEvent.find(e=>e[name])
  78. var index = this.priorityEvent.indexOf(priorityItem)
  79. if(index < levelMax.index){
  80. levelMax.index = index;
  81. levelMax.cursor = priorityItem[name]
  82. }
  83. })
  84. this.currentCursorIndex = levelMax.index
  85. this.domElements.forEach(e=>e.style.cursor = levelMax.cursor || '')
  86. }
  87. }
  88. }
  89. export default CursorDeal;