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